Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


Data Structures


Each cache is represented by an instance of thekmem_cachestructure defined inmm/slab.c. The structure
is not normally visible at other points of the kernel because it is defined in a C header and not in a
header file. This is because users of the cache need not know in detail how the cache is implemented. It is
sufficient to regard slab caches as mechanisms for the efficient creation and release of objects of a specific
type by means of a set of standard functions.

The contents of the structure are as follows:

mm/slab.c
struct kmem_cache {
/* 1) per-cpu data, touched during every alloc/free */
struct array_cache *array[NR_CPUS];
/* 2) Cache tunables. Protected by cache_chain_mutex */
unsigned int batchcount;
unsigned int limit;
unsigned int shared;

unsigned int buffer_size;
u32 reciprocal_buffer_size;
/* 3) touched by every alloc & free from the backend */

unsigned int flags; /* constant flags */
unsigned int num; /* # of objs per slab */

/* 4) cache_grow/shrink */
/* order of pgs per slab (2^n) */
unsigned int gfporder;

/* force GFP flags, e.g. GFP_DMA */
gfp_t gfpflags;

size_t colour; /* cache colouring range */
unsigned int colour_off; /* colour offset */
struct kmem_cache *slabp_cache;
unsigned int slab_size;
unsigned int dflags; /* dynamic flags */

/* constructor func */
void (*ctor)(struct kmem_cache *, void *);

/* 5) cache creation/removal */
const char *name;
struct list_head next;

/* 6) statistics */
...

struct kmem_list3 *nodelists[MAX_NUMNODES];
};
Free download pdf