Selecting a Cached Object

_cache_alloc can check relatively easily if an object is in the per-CPU cache, as the following code excerpt shows:

mm/slab.c static inline void *_cache_alloc(kmem_cache_t *cachep, gfp_t flags)

ac = ac_data(cachep); if (likely(ac->avail)) { ac->touched = 1; objp = ac->entry[--ac->avail];

objp = cache_alloc_refill(cachep, flags);

return objp;

cachep is a pointer to the kmem_cache_t instance of the cache used. The ac_data macro yields the associated array_cache instance for the currently active CPU by returning cachep->array[smp_processor_ id()].

As the objects in memory immediately follow the array_cache instance, the kernel can access them easily with the help of the dummy array at the end of the structure without the explicit need for pointer arithmetic. The object is removed from the cache by decrementing ac->avail.

Continue reading here: Refilling the PerCPU Cache

Was this article helpful?

0 0