Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to choose between Slab and Slub Allocator in Linux Kernel?

What are the factors which help to decide the choice of memory allocators in Linux Kernel?

In the present Linux Kernel we have the option of choosing SLAB,SLUB or SLOB. I have read that SLOB is used for Kernel of smaller footprints. But I want to know the factors which help to decide between Slab Allocator and Slub Allocator.

like image 276
Siddharth Avatar asked Mar 18 '13 05:03

Siddharth


People also ask

What are the differences between slab allocator and slub allocator?

Slub is simpler than Slab. SLOB (Simple List Of Blocks) is a memory allocator optimized for embedded systems with very little memory—on the order of megabytes. It applies a very simple first-fit algorithm on a list of blocks, not unlike the old K&R-style heap allocator.

What is slub allocator?

SLUB (the unqueued slab allocator) is a memory management mechanism intended for the efficient memory allocation of kernel objects which displays the desirable property of eliminating fragmentation caused by allocations and deallocations.

What is slab allocator in Linux?

Slab allocation is a form of memory management, within the Linux kernel, used with the intention of making memory allocation of objects efficient. This type of memory management reduces fragmentation caused by allocations and deallocations.

What is true for slab in terms of allocating kernel memory?

A second strategy for allocating kernel memory is known as slab allocation. It eliminates fragmentation caused by allocations and deallocations. This method is used to retain allocated memory that contains a data object of a certain type for reuse upon subsequent allocations of objects of the same type.


1 Answers

In the search of answer, I posted the same question on Quora and Robert Love answered it:

I'm assuming you are asking this from the point-of-view of the user of a system, or perhaps someone building a kernel for a particular product. As a kernel developer, you don't care what "slab" allocator is in use; the API is the same.

First, "slab" has become a generic name referring to a memory allocation strategy employing an object cache, enabling efficient allocation and deallocation of kernel objects. It was first documented by Sun engineer Jeff Bonwick1 and implemented in the Solaris 2.4 kernel.

Linux currently offers three choices for its "slab" allocator:

Slab is the original, based on Bonwick's seminal paper and available since Linux kernel version 2.2. It is a faithful implementation of Bonwick's proposal, augmented by the multiprocessor changes described in Bonwick's follow-up paper2.

Slub is the next-generation replacement memory allocator, which has been the default in the Linux kernel since 2.6.23. It continues to employ the basic "slab" model, but fixes several deficiencies in Slab's design, particularly around systems with large numbers of processors. Slub is simpler than Slab.

SLOB (Simple List Of Blocks) is a memory allocator optimized for embedded systems with very little memory—on the order of megabytes. It applies a very simple first-fit algorithm on a list of blocks, not unlike the old K&R-style heap allocator. In eliminating nearly all of the overhad from the memory allocator, SLOB is a good fit for systems under extreme memory constraints, but it offers none of the benefits described in 1 and can suffer from pathological fragmentation.

What should you use? Slub, unless you are building a kernel for an embedded device with limited in memory. In that case, I would benchmark Slub versus SLOB and see what works best for your workload. There is no reason to use Slab; it will likely be removed from future Linux kernel releases.

Please refer to this link for an original response.

like image 59
Siddharth Avatar answered Oct 17 '22 15:10

Siddharth