分类: LINUX
2010-04-24 16:45:41
struct
kmem_cache_cpu {
void **freelist; /* Pointer to first free per cpu object */
struct page *page; /* The slab from which we are allocating */
int node; /*
The node of the page (or -1 for debug) */
unsigned int offset; /* Freepointer offset (in word units) */
unsigned int objsize; /* Size of an object (from kmem_cache) */
};
struct
kmem_cache_node {
spinlock_t list_lock; /* Protect partial list and nr_partial */
unsigned long nr_partial;
struct list_head partial;
};
struct
kmem_cache {
/* Used for retriving partial slabs etc
*/
unsigned long flags;
int size; /*
The size of an object including meta data */
int objsize; /* The size of an object without meta data */
int offset; /* Free pointer offset. */
struct kmem_cache_order_objects oo;
/*
*
Avoid an extra cache line for UP, SMP and for the node local to
*
struct kmem_cache.
*/
struct kmem_cache_node local_node;
/* Allocation and freeing of slabs */
struct kmem_cache_order_objects max;
struct kmem_cache_order_objects min;
gfp_t allocflags; /* gfp flags to use on each alloc */
int refcount; /* Refcount for slab cache destroy */
void (*ctor)(void *);
int inuse; /* Offset to metadata */
int align; /* Alignment */
unsigned long min_partial;
const char *name; /* Name (only for display!) */
struct list_head list; /* List of slab caches */
struct kmem_cache_cpu cpu_slab;
};
static
LIST_HEAD(slab_caches);
所有的kmem_caches都是串在slab_caches上的。
kmem_caches的成员cpu_slab指向了per-cpu结构kmem_cache_cpu
kmem_cache_cpu
成员freelist指向了当前空闲的object;
kmem_cache_cpu成员page指向当前的slab所在的page.
如果freelist为NULL,则证明当前所指向的page已经没有空闲,则:
1. 检查有没有部分空闲的page.
2. |若没有则分配全新的page.
部分空闲的page串在kmem_cache_node的成员partial上。page的成员freelist同样
用来指示是否有空闲的object可用。
注意这个部分空闲并不指代这个page一定有空闲的object,所以,取出这个page之后要
检查page->freelist参数。如果page->freelist为NULL,则会把它从cpu
cache中移除。然后重新找到一个page.当然partial是由kmem_cache_node的成员nr_partial来指示有空闲object的page个数add_partial用来增计数。