Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Dec 2004 04:39:27 +0300
From:      Kenny Chamber <kenny@gem-hs.org>
To:        freebsd-hackers@freebsd.org
Subject:   kernel malloc usage
Message-ID:  <41C0E74F.1070404@gem-hs.org>

next in thread | raw e-mail | index | archive | help
I have a question concerning the use of malloc to allocate small amounts
of memory for packet wrappers for certain packets.
Basically, I'm using malloc in much the same way as one would use it in
a standard userland program: allocating small chunks and freeing them
again a short(ish) time later.
A colleague said this was a bad idea, since malloc should only really be
used to allocate larger chunks (PAGE_SIZE and over) at driver
initialisation. Management and partition of the allocated space should
be done by the driver. His reason was that over time, the kernel heap
memory gets progressively more fragmented until it becomes difficult to
get larger blocks.
Is this true? I seem to remember that FreeBSD has a slab allocator,
which IIRC is particularly good at allocating small chunks.

Is it a better idea to write my own allocators which use a larger block
of memory allocated by malloc at driver start-time, or can I use malloc
as in userland?




-----------------------
Kenny Chamber
http://gem-hs.org/contact.html



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?41C0E74F.1070404>