I recently started going through memcached source code and i came across this structure. Based on my understanding, there are approximately 64 slabs and and each slab represents a unique chunk size. If we took the first slab class ( size 80 , say ) then the pages which are belongs to this slab will have it's memory broken into 80 bytes.
typedef struct {
unsigned int size; // sizes of items
unsigned int perslab; // how many items per slab
void *slots; // list of item ptrs
unsigned int sl_curr; // total free items in list
unsigned int slabs; // how many slabs were allocated for this class
void **slab_list; // array of slab pointers
unsigned int list_size; // size of prev array
size_t requested; // The number of requested bytes
} slabclass_t;
I do not understand this line,
unsigned int slabs; // how many slabs were allocated for this class
What does he mean by how many slabs were allocated for a slab class? Every slab class must be unique right? why will there be multiple slabs within one slab class? Am i missing something?
An allocated slab of class
slabclass_t
is basically a chunk of memory that hostsperslab
number of items of sizesize
. If all the items in that slab are used, Memcached allocates another chunk of memory and adds it to theslab_list
. These chunks of memory are also referred to aspages
orslab_pages
.So if you start a new Memcached server and store one item for a slab class (say size=80), then for this slab class
slabs=1
. Once you storeperslab+1
items in that class you will haveslabs=2
and theslab_list
will contain 2 items.Basically, you have a
slab_list
andslabs
its length whereaslist_size
is its capacity.I derived most of this from slabs.c so correct me if I got something wrong.