kernel malloc usage

Gerald Heinig gheinig at syskonnect.de
Mon Nov 3 02:08:35 PST 2003


Hi all,

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?

Cheers,

Gerald
-- 
S y s K o n n e c t   G m b H
A Marvell Company
Siemensstr. 23
D-76275 Ettlingen, Germany
---------------------------------
Gerald Heinig
Software Engineer
-------------------------------------
phone:  + 49 (0) 7243 502 354
fax:        +49 (0) 7243 502 364
email: gheinig at syskonnect.de
http://www.syskonnect.com


More information about the freebsd-hackers mailing list