Linux Kernel Memory Management (2)

来源:互联网 发布:淘宝店铺怎么关闭啊 编辑:程序博客网 时间:2024/05/16 10:57

Author: Harold Wang

http://blog.csdn.net/hero7935

1.Slab Allocator

Three Layer architecture:
--Cache
--Slab
--Object
image

1.1 Caches
General cache
--kmem_cache_init() and kmem_cache_sizes_init() to establish general cache when system initializing.
--kmalloc() function to allocate object
image
Specific cache
--caches that are frequently used.
--kmem_cache_create() function to create specific cache

Author: Harold Wang

http://blog.csdn.net/hero7935

/proc/slabinfo to illustrate the general cache and specific cache in the system.

Linux 2.6 involves per-CPU data structure(struct array_cache which is slab local cache) to reduce spin lock contention among processors and to make better use of the hardware caches, Most allocations and releases of slab objects affects the local cache only!

Cache Descriptor
struct kmem_cache
{
struct kmem_list3* nodelists[MAX_NUMNODES];
/*constructor func*/
/*de-constructor func*/
struct list_head next;
}

struct kmem_list3
{
struct list_head slabs_partial; /* list of slab descriptors with both free and non-free objects */
struct list_head slabs_full; /* list of slab descriptors with non-free objects */
struct list_head slabs_free; /* list of slab descriptors with free objects only */
unsigned long free_objects;/*number of objects available in kmem_list3*/
unsigned int free_limit;/*maxmimum of objects in kmem_list3*/
/*other functions*/
}

struct slab
{
struct list_head list;
unsigned long colouroff;/*offset(in bytes) of the first object in a Slab*/
void* s_mem;/*Address of first object in the slab*/
unsigned int inuse;
kmem_bufctl_t free;/*Index of next free object in the slab, or BUFCTL_END if there are no free objects left*/
}
image

All caches are orgnised by double-linked chain and pointed by cache_chain.

Author: Harold Wang

http://blog.csdn.net/hero7935


image

1.2 Slabs and objects


image

Slub allocation:

image

 

Noncontiguous memory area management(updating)
image

Process address space

Process-Related Memory Structures
image

Process Memory Layout

image 

Linux Process Page Table
image

Author: Harold Wang

http://blog.csdn.net/hero7935

updating…….