Slab allocation
≈ 4 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
Slab allocation is a memory management mechanism intended for the efficient memory allocation of objects. In comparison with earlier mechanisms, it reduces fragmentation caused by allocations and deallocations. This technique is used for retaining allocated memory containing a data object of a certain type for reuse upon subsequent allocations of objects of the same type. It is analogous to an object pool, but only applies to memory, not other resources. Slab allocation was first introduced in the Solaris 2.4 kernel by Jeff Bonwick. Bonwick claims the name "Slab" comes from a Kellogg's cereal commercial catchphrase rhyme, "grab a slab". Slab allocation is now widely used by many Unix and Unix-like operating systems including FreeBSD and Linux, both in the SLAB allocator and its replacement, SLUB.
Slab allocation is a memory management mechanism intended for the efficient memory allocation of objects. In comparison with earlier mechanisms, it reduces fragmentation caused by allocations and deallocations. This technique is used for retaining allocated memory containing a data object of a certain type for reuse upon subsequent allocations of objects of the same type. It is analogous to an object pool, but only applies to memory, not other resources. Slab allocation was first introduced in the Solaris 2.4 kernel by Jeff Bonwick. Bonwick claims the name "Slab" comes from a Kellogg's cereal commercial catchphrase rhyme, "grab a slab". Slab allocation is now widely used by many Unix and Unix-like operating systems including FreeBSD and Linux, both in the SLAB allocator and its replacement, SLUB.
Implementation techniques
Free lists
A slab represents one memory allocation to the cache from the machine, and whose size is customarily a multiple of the page size. The slab will be divided into a number of entries, which will then be requested by the cache as the client code requests memory for new objects. It is necessary then to keep track of which parts of the slab are free to use and which ones were already occupied. This is generally done using "free lists": lists of free entries in the slab ready to store new objects. The free list may be a separate data structure, such as an array of indices indicating which entries of the slab are free, or it may be embedded within the slab. The Linux SLUB allocator keeps the free list as a linked list of pointers, each of which is stored directly in the free memory area of the slab they represent.
Slab sizes
Operating systems may use different slab sizes and internal layouts depending on the size of the objects to be stored. The reason for the large slabs having a different layout from the small slabs is that it allows large slabs to pack better into page-size units, which helps with fragmentation. For example, objects that are at least 1/8 of the page size for a given machine may benefit from a "large slab" size, with explicit free lists, while smaller objects may use a "small slab" setup, embed the free list tracking. Bonwick's original presentation of the slab allocator already made the distinction of layouts for large and small slabs.
See also
Fixed-size blocks allocation Memory pool
Notes
External links
FreeBSD uma(9) manual page The SLUB allocator comment about management of slabs in Linux by two different allocators: SLUB allocator and SLAB allocator Memory Compaction v7 (a Linux patch set from Mel Gorman dealing with SLAB fragmentation and compaction issues, 2 April 2010) Detecting kernel memory leaks Jonathan Corbet, Linux Weekly News, 2006; includes user comments on garbage collection Linux performance: is Linux becoming just too slow and bloated? On SLAB and SLUB. Free software magazine 2010.
Text derived from https://en.wikipedia.org/w/index.php?oldid=1359110247 under CC BY-SA 4.0; modifications have been made.