Slub and slab Overview

Source: Internet
Author: User

Slub replaces slab and becomes the default memory distributor. Kernel developers call it more smp-friendly slub allocator. Obviously, the multi-core processor on the desktop platform can also benefit from this.


Slab is an old memory distributor on Linux. Because of its complex structure, almost no one dared to modify it. Like my idol Anders hejlsberg used the fully compiled Delphi compiler, he had been away from Borland for a long time, do not dare to maintain these Compilers Code .


Before studying slub, let's talk about slab. As we all know, the operating system allocates memory in pages, which can also be called memory blocks or heap. However, the kernel objects are much smaller than the page size, and these objects are frequently applied for and released during the lifecycle of the operating system, the initialization time of these objects exceeds the total time of memory allocation and memory release. Therefore, a more fine-grained allocation of kernel objects is required. Algorithm So slab was born:


Slab caches released kernel objects so that you do not need to initialize and allocate space for the next application, similar to the object pool concept. The general memory allocation algorithm is not modified to ensure the performance of large memory block allocation.


The top layer of slab is a cache chain composed of multiple kmem_caches.


Each kmem_cache consists of three Queues: slabs_full, slabs_partial, and slabs_empty, respectively marking all the allocated pages of slab, some allocated pages, and the pages for slab allocation. Obviously, when a new slab application arrives, the slab_partial page will be considered; when a memory block is released, slab_empty will be given priority.


Because slab groups objects by size, no fragments in heap allocation mode will be generated during allocation, and no space waste in the buddy allocation algorithm will be generated, it also supports hardware cache matching to Improve the Performance of TLB, Which is perfect.


However, there is no perfect algorithm in this world. An algorithm either takes up more space to reduce the computing time, or uses more computing time to reduce the space occupation. An excellent algorithm is to find a balance between the two based on actual application conditions. Although slab can allocate kernel objects more quickly, complex hierarchies such as cache queues occupy a large amount of memory.


Slub was born as a result:


Slub does not contain the complex structure of slab. Slab not only has queues, but also stores the metadata of the slab object at the beginning of each slab. Slub only places objects of similar sizes on the page and saves the linked list of unallocated slab objects. It is easy to locate the objects quickly during access, eliminating the need for queue traversal and header metadata offset calculation. Although the linked list is maintained independently on each CPU node like slab, an independent thread is used to maintain the global slab object, an object not used by the CPU will be placed in the global partial queue for other CPUs to use. It balances the slab objects of nodes. When the page is recycled, the slab object of slub is global and does not cause object sharing problems. In addition, slub adopts the method of merging similar slab objects,
Further reduce memory usage.


According to kernel developers, slub improves performance by 5%-10% compared with Slab and reduces memory usage by 50% (it is occupied by Kernel Object cache, not global, otherwise, you can modify the main version number of Linux kernel ). Therefore, slub is a time and space improvement algorithm, and slub is fully compatible with slab interfaces. Therefore, other kernel modules can benefit from slub's high performance without modification. In kernel 2.6.22, slub naturally replaces slab.


A few days ago, we saw that the 2.6.23 feature has been frozen, and the revolutionary scheduler "CFS" will appear. The full name of CFS is a completely fair scheduler and there is no concept of queue or time slice, Program Nor can an infinite loop stop the system. The operating system book is outdated. However, I suspect that the scheduler in kernel 2.6.22 has been modified and carefully observes the system monitor of ubuntu7.10. Generally, the usage of the two CPUs is no longer the opposite, that is to say, the operating system is no longer moving the same process between different CPU nodes, which improves the performance of the amd K8 non-shared second-level cache CPU. 2.6.20 Linux and Windows
Windows Server 2003 is installed on a single-core opteron server, which cannot predict the optimization conditions in multiple cores.


2.6.23 another improvement is the reiser4, the fastest File System on the earth. I have never cared about this file system because I have been using XFS. However, such a title may be as revolutionary as CFS.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.