Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SLAB memory management

Tags:

linux-kernel

I'm confused as to the structuring of the SLAB memory management mechanism.

I get that there are multiple 'caches' that are specific to commonly used data objects, but why does each cache contain multiple 'slabs'?

What differentiates each slab within a cache? Why not simply have the cache filled with the data objects themselves? Why does there need to be this extra layer?

like image 725
Darcys22 Avatar asked Jan 22 '13 01:01

Darcys22


1 Answers

I may be too late to answer this, but this may help others as well. As I see from Understanding Linux Virtual Memory Manager, having slabs has three major benefits.

  1. Reducing internal fragmentation caused by buddy system. Because we have caches that best suits smaller objects.
  2. Better hardware cache usage - by aligining objects to start at different offsets in different slabs so that interference between cache lines can be reduced. This is based on assumption that we have physically indexed cache.
  3. A slab is primary unit in cache, which is acquired/relinquished at once. This causes reduction in external fragmentation as well.

See section 3.2 from The Slab Allocator: An Object Caching Kernel memory Allocator (1994).

like image 185
ultimate cause Avatar answered Oct 23 '22 10:10

ultimate cause