Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Jan 1999 09:11:38 +1100
From:      Bruce Evans <bde@zeta.org.au>
To:        dillon@apollo.backplane.com, green@unixhelp.org
Cc:        current@FreeBSD.ORG, julian@whistle.com, mike@smith.net.au
Subject:   Re: kernel malloc and M_CANWAIT
Message-ID:  <199901182211.JAA17726@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>    It looks like malloc() can return NULL if the kmem_malloc() fails.

Not for the M_WAITOK case.

>    kmem_malloc() can only fail in the M_WAITOK case if the KVM map is full.

kmem_malloc() panics in this case (except for map == mb_map; the mbuf
allocator has special handling for this problem).

>    If the system is simply low on memory, kmem_malloc() will block.
>
>    So malloc() will generally not return NULL even in low memory situations
>    unless the KVM map fills up, which isn't supposed to happen but can in
>    certain severe circumstances.  Callers should therefore check for NULL.

Callers that check for NULL are bogus.  Callers that can actually handle
low memory conditions should use M_NOWAIT.  There should probably be
a flag that says to wait for everything except the map to unfill, and
this flag should have been used instead of the `map == mb_map' hack,
but no callers actually handle filling of their map (the mbuf allocator
doesn't -- it tends to panic a little later because m_retry[hdr]()
is not prepared to pass failures back to callers in the can-wait case).

Bruce

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?199901182211.JAA17726>