Figure 73 The slab allocator components

Object

Object

The slab allocator never releases the page frames of an empty slab on its own. It would not know when free memory is needed, and there is no benefit to releasing objects when there is still plenty of free memory for new objects. Therefore, releases occur only when the kernel is looking for additional free page frames (see Section 7.2.13 later in this chapter and Section 16.7).

7.2.2 Cache Descriptor

Each cache is described by a table of type struct kmem_cache_s (which is equivalent to the type kmem_cache_t). The most significant fields of this table are:

name

Character array storing the name of the cache.

slabs full

i\*b

Slab

Doubly linked circular list of slab descriptors with no free objects.

slabs_partial

Doubly linked circular list of slab descriptors with both free and nonfree objects.

slabs_free

Doubly linked circular list of slab descriptors with free objects only.

spinlock

Spin lock protecting the cache from concurrent accesses in multiprocessor systems.

Number of objects packed into a single slab. (All slabs of the cache have the same size.)

objsize

Size of the objects included in the cache. (This size may be rounded up by the slab allocator if the initial addresses of the objects must be memory-aligned.)

gfporder

Logarithm of the number of contiguous page frames included in a single slab.

ctor, dtor

Point, respectively, to the constructor and destructor methods associated with the cache objects. They are currently set to null, as stated earlier.

next

Pointers for the doubly linked list of cache descriptors.

flags

A set of flags that describes permanent properties of the cache. There is, for instance, a flag that specifies which of two possible alternatives (see the following section) has been chosen to store the object descriptors in memory.

dflags

A set of flags that describe dynamic properties of the cache. There is, for instance, a flag that indicates whether the kernel is allocating new slabs to the cache. In multiprocessor systems, they must be accessed by acquiring the cache spin lock.

gfpflags

A set of flags passed to the buddy system function when allocating page frames. The field is typically used to specify the _ _gfp_dma and _ _gfp_highmem zone modifiers. For instance, if _ _GFP_DMA is set in gfpflags, all objects of the cache can be used for ISA DMA. 7.2.3 Slab Descriptor

Each slab of a cache has its own descriptor of type struct slab_s (equivalent to the type slab_t). Slab descriptors can be stored in two possible places:

External slab descriptor

Stored outside the slab, in one of the general caches not suitable for ISA DMA pointed to by cache_sizes.

Internal slab descriptor

Stored inside the slab, at the beginning of the first page frame assigned to the slab.

The slab allocator chooses the second solution when the size of the objects is smaller than 512 or when internal fragmentation leaves enough space for the slab—and object descriptors (as described later)—inside the slab.

The most significant fields of a slab descriptor are:

inuse

Number of objects in the slab that are currently allocated.

s_mem

Points to the first object (either allocated or free) inside the slab.

free

Points to the first free object (if any) in the slab.

list

Pointers for one of the three doubly linked lists of slab descriptors (either the slabs_full, slabs_partial, or slabs_free list in the cache descriptor).

Figure 7-4 illustrates the major relationships between cache and slab descriptors. Full slabs, partially full slabs, and free slabs are linked in different lists.

Continue reading here: Figure 74 Relationship between cache and slab descriptors

Was this article helpful?

0 0