Subject: Re: dyamic memory allocation in NetBSD
To: ycchang <ycchang@cirx.org>
From: Bill Studenmund <wrstuden@netbsd.org>
List: tech-kern
Date: 05/28/2003 10:14:08
On Sat, 24 May 2003, ycchang wrote:

> Hi, All
>

> Recently, I' m studying the vm of NetBSD from the source code, but I
> still can not figure out what kinds of dynamic memory allocation
> mechanism does the kernel provide. As in Linux, it's very clear that the
> dynamic memory is allocated totally from the buddy system, such as
> alloc_pages(), and the slab allocator uses it to provide cache for
> efficient kernel data structure allocation, such as kmem_alloc or
> kmalloc(), finally, if we want nonconti. memory , we can use vmalloc().

> In NetBSD, does any one can tell me roughly the guidelines of dynamic
> memory allocation? I have traced the code, but it seems that various
> purpose dynamic memory allocation functions call each other(uvm, pmap
> etc.), and I can not figure out the relationship among them.

The main allocators used by generic code are the pool allocator and
malloc(). There is also the MALLOC macro, which is useful if you have a
known-at-compile-time size to malloc. free() and FREE() are used to free
the memory, respectively. The pool allocator is similar to Solaris's slab
allocator.

If what I'm about to say is wrong, I'm sure I'll get corrected. :-) uvm_
routines are in the MI virtual memory system, and the pmap routines are
more just the physical memory mapping code. Part of the pmap code is MI,
and part of it is MD.

Take care,

Bill