Page 1 of 1
Differentiating between different memory managers
Posted: Thu Jul 12, 2012 2:42 am
by leekimpark
In spite of my very basic understanding of operating systems, recently I've been doing a lot of research into the memory managers that different Unix-like operating systems use, particularly how they allocate memory to processes. My goal has been trying to compare the differences across different operating systems I've learned things like free lists, memory pools, power of two lists, and the buddy system. I've also learned about slab allocation. The problem is that I'm not sure which category of memory manager these schemes are used for. Most of these terms I found in books for specific operating systems under the section explaining the kernel memory allocator. Is this supposed to be allocating memory for the kernel's data structures, or for allocating memory for processes or can it be used for both? I'm particularly worried about slab allocation and which one of the two categories it falls in.
Re: Differentiating between different memory managers
Posted: Thu Jul 12, 2012 4:33 am
by JamesM
The slab allocator is normally used for allocating small sizes of memory, and is used in Linux's kernel heap (malloc for the kernel).
It's used as a general purpose kmalloc and also specialised caches (in slab parlance) are created for instances that are often created and destroyed - inodes, for example.
Re: Differentiating between different memory managers
Posted: Thu Jul 12, 2012 5:41 am
by leekimpark
In that case, what about the other allocators, and for Linux, what is used to allocate memory for processes?
Re: Differentiating between different memory managers
Posted: Thu Jul 12, 2012 8:31 am
by JamesM
leekimpark wrote:In that case, what about the other allocators, and for Linux, what is used to allocate memory for processes?
As far as I'm aware, linux divvys up the virtual address space with a buddy allocator.
Re: Differentiating between different memory managers
Posted: Thu Jul 12, 2012 4:14 pm
by gerryg400
allocating memory for the kernel's data structures
Linux now uses the SLUB allocator which is an improved SLAB allocator for small pieces of memory
allocating memory for processes
Each process lives in its own address space. You need an allocator that can allocate out of that memory. Generally it's best to represent a process address space as a list (implemented as a tree usually but a linked list might do in a simple OS) of already allocated groups of pages. Think about how mmap might work. Just search the list for a space as big as the user requested, usually combine that used space to an already-in-use space and return to the user.
IMHO, even though it's a little old, the
Gorman book is a good way to learn Linux MM.
Re: Differentiating between different memory managers
Posted: Thu Jul 12, 2012 9:21 pm
by leekimpark
I'm still confused about the whole process behind allocating memory for processes. For the kernel memory allocator that allocates for kernel data structures, the kernel just requests pages from the virtual memory manager, and then may use something like SLAB or SLUB. I've also seen the term kernel memory allocator being used interchangeably with general memory allocator for example at
http://docs.freebsd.org/44doc/papers/kernmalloc.html and
http://www.ibm.com/developerworks/aix/l ... index.html. From these sources and others, I originally thought that the kernel memory allocator was used for both the kernel's own data structures as well as process creation, but it seems that this is not the case and there is a separate allocation scheme. I've seen the thread here
http://forum.osdev.org/viewtopic.php?t=12022 but it hasn't really helped. I took a look at at the gormon book and I'm still not sure how process creation works.