slab
何时分配新的slab? 1 bigger item; 2 no free chunk;
If the new item is bigger than the size of any existing blocks, then a new slab is created, divided up into blocks of a suitable size. If an existing slab with the right block sizealready exists, but there are no free blocks, a new slab is created.
内存页一旦被分配给slab,在memcache生命周期内不再更改,在内存总量确定的情形下,其它slab可能出现饿死现象;
为此1.4.11引入slab automove
Thealgorithm is slow and conservative. If a slab class is seen as having the highest eviction count 3 times 10 seconds apart, it will take a pagefrom a slab class which has had zero evictions in the last 30 seconds and move the memory.
typedef struct {
unsigned int size; /* 每个item大小, sizes of items */
unsigned int perslab; /* 每个page中包含多少个item , how many items per slab */
void **slots; /* 空闲的item指针, list of item ptrs */
unsigned int sl_total; /* 以分配空闲的item 个数, size of previous array */
unsigned int sl_curr; /* 当前空闲的item位置(也就是实际空闲item个数),从后往前的, first free slot */
void *end_page_ptr; /* 指向最后一个页面中空闲的item开始位置, pointer to next free item at end of page, or 0 */
unsigned int end_page_free; /* 最后一个页面,item个数, number of items remaining at end of last alloced page */
unsigned int slabs; /* 实际使用slab(page)个数 how many slabs were allocated for this class */
void **slab_list; /* 所有page的指针, array of slab pointers */
unsigned int list_size; /* 已经分配page指针个数,size of prev array */
unsigned int killing; /* index+1 of dying slab, or zero if none */
size_t requested; /* 所有被使用了的内存的大小, The number of requested bytes */
} slabclass_t;