HOME

TheInfoList



OR:

Slab allocation is a
memory management Memory management (also dynamic memory management, dynamic storage allocation, or dynamic memory allocation) is a form of Resource management (computing), resource management applied to computer memory. The essential requirement of memory manag ...
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 Kellanova, formerly known as the Kellogg Company and commonly known as Kellogg's, is an American Multinational corporation, multinational food manufacturing company headquartered in Chicago, Illinois, US. Kellanova produces and markets con ...
cereal commercial
catchphrase A catchphrase (alternatively spelled catch phrase) is a phrase or expression recognized by its repeated utterance. Such phrases often originate in popular culture and in the arts, and typically spread through word of mouth and a variety of mass ...
rhyme, "grab a slab". Slab allocation is now widely used by many Unix and Unix-like operating systems including
FreeBSD FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
FreeBSD Kernel Developer's Manual
/ref> and
Linux Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
,M. Tim Jones
Anatomy of the Linux slab allocator
both in the SLAB allocator and its replacement, SLUB.Vlastimil Babka
remove the SLAB allocator
/ref>


Basis

Slab allocation significantly reduces the frequency of computationally costly initialization and destruction of kernel data-objects, which can outweigh the cost of allocating memory for them. Jeff Bonwick
The Slab Allocator: An Object-Caching Kernel Memory Allocator (1994)
/ref> When the kernel creates and deletes objects often, overhead costs of initialization can result in significant performance drops. Object caching leads to less frequent invocation of functions which initialize object state: when a slab-allocated object is released after use, the slab allocation system typically keeps it cached (rather than doing the work of destroying it) ready for re-use next time an object of that type is needed (thus avoiding the work of constructing and initialising a new object). With slab allocation, a cache for a certain type or size of data object has a number of pre-allocated "slabs" of memory; within each slab there are memory chunks of fixed size suitable for the objects. Abraham Silberschatz ''et al''.: ''Operating system concepts''. Wiley: 2004. The slab allocator keeps track of these chunks, so that when it receives a request to allocate memory for a data object of a certain type, usually it can satisfy the request with a free slot (chunk) from an existing slab. When the allocator is asked to free the object's memory, it just adds the slot to the containing slab's list of free (unused) slots. The next call to create an object of the same type (or allocate memory of the same size) will return that memory slot (or some other free slot) and remove it from the list of free slots. This process eliminates the need to search for suitable memory space and greatly alleviates memory fragmentation. In this context, a slab is one or more contiguous pages in the memory containing pre-allocated memory chunks.


Implementation

The slab allocation algorithm defines the following terms: # Cache: cache represents a small amount of very fast memory. A cache is a storage for a specific type of object, such as semaphores,
process A process is a series or set of activities that interact to produce a result; it may occur once-only or be recurrent or periodic. Things called a process include: Business and management * Business process, activities that produce a specific s ...
descriptors, file objects, etc. # Slab: slab represents a contiguous piece of memory, usually made of several virtually contiguous pages. The slab is the actual container of data associated with objects of the specific kind of the containing cache. When a program sets up a cache, it allocates a number of objects to the slabs associated with that cache. This number depends on the size of the associated slabs. Slabs may exist in one of the following states: # ''empty'' – all objects on a slab marked as free # ''partial'' – slab consists of both used and free objects # ''full'' – all objects on a slab marked as used Initially, the system marks each slab as "empty". When the process calls for a new kernel object, the system tries to find a free location for that object on a partial slab in a cache for that type of object. If no such location exists, the system allocates a new slab from contiguous virtual pages and assigns it to a cache. The new object gets allocated from this slab, and its location becomes marked as "partial". The allocation takes place quickly, because the system builds the objects in advance and readily allocates them from a slab.


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.


Systems using slab allocation

*
AmigaOS AmigaOS is a family of proprietary native operating systems of the Amiga and AmigaOne personal computers. It was developed first by Commodore International and introduced with the launch of the first Amiga, the Amiga 1000, in 1985. Early versions ...
(introduced in
AmigaOS 4 AmigaOS 4 (abbreviated as OS4 or AOS4) is a line of Amiga operating systems which runs on PowerPC microprocessors. It is mainly based on AmigaOS 3.1 source code developed by Commodore International, Commodore, and partially on version 3.9 develop ...
) *
DragonFly BSD DragonFly BSD is a free and open-source Unix-like operating system forked from FreeBSD 4.8. Matthew Dillon, an Amiga developer in the late 1980s and early 1990s and FreeBSD developer between 1994 and 2003, began working on DragonFly BSD in ...
(introduced in release 1.0) *
FreeBSD FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
(introduced in 5.0) * GNU Mach *
Haiku is a type of short form poetry that originated in Japan. Traditional Japanese haiku consist of three phrases composed of 17 Mora (linguistics), morae (called ''On (Japanese prosody), on'' in Japanese) in a 5, 7, 5 pattern; that include a ''kire ...
(introduced in alpha 2) * Horizon (
Nintendo Switch The is a video game console developed by Nintendo and released worldwide in most regions on March 3, 2017. Released in the middle of the Eighth generation of video game consoles, eighth generation of home consoles, the Switch succeeded the ...
microkernel) * HP-UX (introduced in 11i)Chris Cooper and Chris Moore, ''HP-UX 11i Internals'', Upper Saddle River, New Jersey: Prentice Hall PTR, 2004,
p. 334
*
Linux Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
(introduced in 2.1.23) *
NetBSD NetBSD is a free and open-source Unix-like operating system based on the Berkeley Software Distribution (BSD). It was the first open-source BSD descendant officially released after 386BSD was fork (software development), forked. It continues to ...
(introduced in 4.0) * Solaris (introduced in 2.4) * The Perl 5 compiler uses a slab allocator for internal memory management * Memcached uses slab allocation for memory management *
illumos Illumos (stylized as "illumos") is a partly free and open-source Unix operating system. It has been developed since 2010 and is based on OpenSolaris, after the discontinuation of that product by Oracle. It comprises a kernel, device driver ...


See also

* Fixed-size blocks allocation * Memory pool


Notes

{{Reflist


External links


FreeBSD uma(9) manual page

The SLUB allocator
comment about management of slabs in
Linux Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
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. Memory management algorithms