gpt4 book ai didi

memory-management - Linux 内核中的 Slab 和 Slub 分配器如何选择?

转载 作者:行者123 更新时间:2023-12-03 07:34:09 31 4
gpt4 key购买 nike

哪些因素有助于决定 Linux 内核中内存分配器的选择?

在当前的 Linux 内核中,我们可以选择 SLAB、SLUB 或 SLOB。我读过 SLOB 用于较小占用空间的内核。但我想知道有助于在 Slab Allocator 和 Slub Allocator 之间做出决定的因素。

最佳答案

为了寻找答案,我在 Quora 上发布了同样的问题,Robert Love 回答了它:

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.

请引用此link获取原始回复。

关于memory-management - Linux 内核中的 Slab 和 Slub 分配器如何选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15470560/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com