next up previous contents index
Next: 8.4 Sizes Cache Up: 8. Slab Allocator Previous: 8.2 Slabs   Contents   Index

Subsections


8.3 Objects

This section will cover how objects are managed. At this point, most of the real hard work has been completed by either the cache or slab managers.


8.3.1 Initialising Objects in a Slab

When a slab is created, all the objects in it put in an initialized state. If a constructor is available, it is called for each object and it is expected when an object is freed, it is left in its initialized state. Conceptually this is very simple, cycle through all objects and call the constructor and initialise the kmem_bufctl for it. The function kmem_cache_init_objs() is responsible for initializing the objects.


8.3.2 Object Allocation

The function kmem_cache_alloc() is responsible for allocating one object to the caller which behaves slightly different in the UP and SMP cases. Figure 8.12 shows the basic call graph that is used to allocate an object in the SMP case.



\includegraphics[width=17cm]{graphs/kmem_cache_alloc-UP.ps}
[1]
Figure: Call Graph: kmem_cache_alloc
[2]


There is four basic steps. The first step (kmem_cache_alloc_head()) covers basic checking to make sure the allocation is allowable. The second step is to select which slabs list to allocate from. This is one of slabs_partial or slabs_free. If there is no slabs in slabs_free, the cache is grown (See Section 8.2.2) to create a new slab in slabs_free. The final step is to allocate the object from the selected slab.

The SMP case takes one further step. Before allocating one object, it will check to see if there is one available from the per-CPU cache and use it if there is. If there is not, it will allocate batchcount number of objects in bulk and place them in its per-cpu cache. See Section 8.5 for more information on the per-cpu caches.


8.3.3 Object Freeing

Freeing an object is a relatively simple task and is available via the kmem_cache_free() function. Just like kmem_cache_alloc(), it behaves difference in the UP and SMP cases. The principle difference between the two cases is that in the UP case, the object is returned directly to the slab but with the SMP case, the object is returned to the per CPU cache. In both cases, the destructor for the object will be called if one is available. The destructor is responsible for returning the object to the initialized state.


next up previous contents index
Next: 8.4 Sizes Cache Up: 8. Slab Allocator Previous: 8.2 Slabs   Contents   Index
Mel 2003-01-14