Page 1

SLAB&SLUB 丰茂

fengmao.pj@taobao.com 2012.07.24 杭州


Contents -SLAB -SLUB -Interactive Video


SLAB -The Slab is a allocator which caches objects( the size is smaller than a page). -The Slab allocator is first introduced by Jeff Bonwick for SunOS. - Slab allocator groups allocations by sizes to reduce internal memory fragmentation(avoid external fragmentation by Buddy system). - Kernel manages the physical memory by buddy system, and allocates small objects by SLAB.


SLAB - Movitation: 1) 2)

3) 4) 5) 6) 7)

Frequently used object should be cached. A finite set of the objects were needed by kernel, required time to initialize and free them. Reduce memory fragmentation. Optimizing for cache performance, reducing cache miss rate. Reduce the burden of buddy system. Reduce the need of locks(Support the per-cpu caches). NUMA-aware.


SLAB -Structures of the SLAB

The kmem_cache consists 3 lists of slab, slab holds physically contiguous pages, and each pages contains a set of object with the same type, cached for improving the system performance. A slab is hold by a single cache, never shared between the caches.


SLAB -struct slab_t • • • • • • • • • • • • • • • • •

struct slab { union { struct { struct list_head list; unsigned long colouroff; void *s_mem; /* including colour offset */ unsigned int inuse; /* num of objs active in slab */ kmem_bufctl_t free; unsigned short nodeid; };

};

};

struct slab_rcu __slab_cover_slab_rcu;


SLAB - Type of the Slab General cache/ Special cache - Type of Slab descriptor Slab with internal descriptor Slab with external descriptor


SLAB -Type of Slab descriptor


SLAB -Get next free object, based on the slab descriptor. For a given object n, the index of next free object is stored in the kmem_bufctrl_t[n]; 1) the object of kmem_bufctrl_t is initialized;

2) The index of the next free object is at kmem_bufctl_t[slab_t->free]; 3) The kmem_bufctl_t list is only updated when an object is freed;


SLAB - Coloring (reducing the cache misses rate)


SLAB - Implement: 1) Cache descriptor : kmem_cache_t 2) Slab descriptor : slab_t 3) Object’s offset descriptor: kmem_bufctl_t 4) Per-CPU slab 5) Shared slab


SLAB - Advantage: 1) Avoid the memory fragmentation (need a lot of object frequently). 2) Avoid to initialize and free objects repeatedly. 3) Support hardware cache alignment by coloring.


SLAB -Disadvantage: 1) A huge amount of metadata. 2) Not achieving a good performance on NUMA. 3) Not supporting DEBUG. 4) Not reducing the cache misses rate, but needed a lot of memory by coloring.


SLUB - Motivation -the SLAB works not well 1) Huge amounts of metadata. 2) Coloring is unnecessary. 3) Supporting NUMA is not gracefulness. 4) Other disadvantage of SLAB.


SLUB -Structures of SLUB


SLUB - Struct page • • • • • • • • • • • • • • • • • • • • • • • • • • • •

struct page { ... struct { union { pgoff_t index; void *freelist; }; ... struct { unsigned inuse:16; unsigned objects:15; unsigned frozen:1; }; ... }; ... union { ... struct kmem_cache *slab; ... }; ... };

/* Our offset within mapping. */ /* slub first free object */

/* SLUB: Pointer to slab */


SLUB - Slab mergence


SLUB - Get next free object

object

Next free object


SLUB -Diff. between SLAB and SLUB 1) Supporting Debug. 2) Merges ‘same’ caches to reduce space of metadata. 3) Supporting Per-CPU caches, which means that object is allocated/freed from/to the per-cpu caches first. 4) Simplify the metadata of slab, without 3 lists.


SLUB - Diff. between SLAB and SLUB 5) Not supporting coloring. 6) Other optimization, a slab can be frozen by a cpu core.


SLMB- a mutable slab allocator - Next generation slab allocator for Linux? Proposed by Google dev. ,on LINUX PLUMBERS CONFERENCE-2010.

Fortunately, this proposal has been rejected.


Interactive Video - Interactive video usually refers to a technique used to blend interaction and linear film or video.


Interactive Video The context of system 客户端 下载外挂文件 与视频数据 视频文件

鼠标移动到目标区域

点击操作 服务器反馈

交 互 式 视 频 服 务 服 务 器

编辑 交互式视频编辑器

交互式视频外挂文件


Interactive Video - Algorithm 跟踪器 更新 输入视频帧

位置数据

轨迹模型

更新

位 置 数 据

在线学习

位置数据 检测器

位 置 数 据

位 置 评 估

目标位置


Interactive Video - Interface of System(1)


Interactive Video - Interface of system(2)


Reference [1] Je Bonwick, An Object-Caching Ke.rnel Memory Allocator, Usenix Summer Conference 1994 [2] http://en.wikipedia.org/wiki/Slab_allocation [3] http://www.ibm.com/developerworks/linux/library/l-linux-slab-allocator/ [4] http://lwn.net/Articles/229096/ [5] http://lwn.net/Articles/229984/ [6] http://www.secretmango.com/jimb/Whitepapers/slabs/slab.html [7] http://census-labs.com/news/2012/01/03/linux-kernel-heap-exploitation/ [8] http://www.linuxplumbersconf.org/2010/ocw/proposals/405 [9] http://en.wikipedia.org/wiki/Interactive_video


Thanks for Your Attention!

SLAB&SLUB  

Linux Memory allocator, Slab&Slub.

Read more
Read more
Similar to
Popular now
Just for you