Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Oct 2002 16:36:59 -0400 (EDT)
From:      Jeff Roberson <jroberson@chesapeake.net>
To:        Terry Lambert <tlambert2@mindspring.com>
Cc:        Ben Stuyts <ben@stuyts.nl>, Robert Watson <rwatson@freebsd.org>, <current@freebsd.org>, <jeff@freebsd.org>
Subject:   Re: [Ugly PATCH] Re: Again: panic kmem_malloc()
Message-ID:  <20021011162439.P46092-100000@mail.chesapeake.net>
In-Reply-To: <3DA72490.32A10E8@mindspring.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 11 Oct 2002, Terry Lambert wrote:

> Ben Stuyts wrote:
> > Is there a way to check the free list of the kernel? Maybe I can find out
> > what action triggers eating al its memory.

Maybe you should just increase the size of your kmem_map?  I'll look into
a better fix but that should do it short term.

>
> ] panic: kmem_malloc(4096): kmem_map too small: 28246016 total allocated.
>
> That's easy: you're calling kmem_malloc() without M_NOWAIT.
>
> That function only operates on the maps kmem_map or mb_map.
>
> It calls vm_map_findspace(), which fails to find space in the
> map.
>
> vm_map_findspace() fails to add space to the map, because it
> only adds space tot he map if the map is kernel_map; all other
> maps fail catastrophically.

Well, for the old allocator this was a panicing situation.  It never
returned memory and kva back to kmem_map.  So you were pretty much done.
>
> The map you are calling it with is kmem_map (if it were mb_map,
> you would get an "Out of mbuf clusters" message on your console,
> and the allocation would fail, regardless of the value of the
> M_NOWAIT flags bit (mbuf allocations do not properly honor the
> lack of an M_NOWAIT flags bit).

It is documented that they do not.  Notice we only have M_TRYWAIT now for
mbufs.
>
> The panic message occurs becuause you asked it to wait for memory
> to be available.
>
> But the code is stupid, and refuses to wait for memory to be
> available, in the case that space can not be found in the map,
> because it does not properly realize that the freeing of memory
> elsewhere can result in freed space in the map.  So it calls
> "panic" instead of waiting.
It will wait for pages to be available.  It just wont wait for KVA to be
available.  This was a somewhat less bogus with the old allocator.
>
> Therefore, it's technically illegal to call kmem_malloc() with
> a third argument that does not include the M_NOWAIT bit, even
> though the function is documented, and obviously intended, to
> permit the use of this flags bit.
No, that's not true.  It will wait if you're low on pages.  It will not
wait if you've run out of kva.  There's a big difference.  Also, WAITOK
more appropriately means "Never return NULL even if you have to panic."
You just assumed it would mean "Never return NULL even if you have to wait".
;-)  I agree that it should mean the latter though.

>
>
> In -current, there is exactly one place where kmem_malloc() is
> called with the kmem_map as its first argument: in the function
> page_alloc() in vm/uma_core.c.
>
>
> So, you have two bogus things happening:
>
> 1)	page_alloc() in uma is using kmem_malloc() without the
> 	M_NOWAIT flag
Why is this bogus?
>
> 2)	kmem_malloc() without the M_NOWAIT flag panics, INSTEAD
> 	OF FRICKING WAITING, LIKE YOU ARE TELLING IT TO DO.
> 	:-0_ <- Dr. Evil
Yes, I agree, it should wait.  It might be interesting to see what the
effects of allocating straight out of the kernel_map would be.  Or perhaps
positioning the kmem_map in such a way that it might be able to expand.  I
don't like the hard limit here anymore than anyone else does.  On
reasonable architectures your only worry is wasting pages and not kva.
Now with UMA the VM can tell it that it's using too many pages and so the
system is self tuning.  We'll have to do something to help kva crippled
architectures (x86) in the near term.
>
> Probably, page_alloc should be rewritten to not use kmem_malloc(),
> and to use the kmem_alloc_wait() instead.
>
> Please find a (relatively bogus) patch attached, which could cause
> things to block for a long time, but will avoid the panic.
>
> Jeffrey Roberson is going to need to fix UMA allocations, per the
> comment in this patch, for a more permanent fix.  I've specifically
> Cc:'ed him on this message.

Thanks for looking into this terry.  Please, call me Jeff though.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021011162439.P46092-100000>