slab.ps
来自「这是一个介绍 linux 编程知识的文章。」· PS 代码 · 共 1,690 行 · 第 1/5 页
PS
1,690 行
(foo_constructor, foo_destructor\);)1 1782 1 806 1140 t
10 R f
(To allocate, use, and free a foo object:)7 1582 1 590 1344 t
9 CW f
(foo = kmem_cache_alloc\(foo_cache, KM_SLEEP\);)3 2376 1 590 1506 t
(use foo;)1 432 1 590 1626 t
(kmem_cache_free\(foo_cache, foo\);)1 1728 1 590 1746 t
10 R f
( because the)2 553(This makes foo allocation fast,)4 1357 2 840 1908 t
( do nothing more than fetch an)6 1292(allocator will usually)2 868 2 590 2028 t
( the cache.)2 711(already-constructed foo from)2 1449 2 590 2148 t
10 CW f
(foo_constructor)590 2268 w
10 R f
(and)1615 2268 w
10 CW f
(foo_destructor)1910 2268 w
10 R f
( to populate and drain the)5 1218(will be invoked only)3 942 2 590 2388 t
(cache, respectively.)1 791 1 590 2508 t
( illustrates a bene\256cial)3 1037(The example above)2 873 2 840 2670 t
( reduces the)2 612( it)1 182( caching:)1 431(side-effect of object)2 935 4 590 2790 t
(instruction-cache footprint of the code that)5 1920 1 590 2910 t
10 I f
(uses)2578 2910 w
10 R f
( by moving the rarely-executed con-)5 1554(cached objects)1 606 2 590 3030 t
(struction and destruction code out of the hot path.)8 2048 1 590 3150 t
11 B f
( Allocator Implementation)2 1261(3. Slab)1 365 2 590 3450 t
10 R f
( the)1 185(This section describes the implementation of)5 1975 2 590 3612 t
( kernel memory allocator, or ``slab allo-)6 1707(SunOS 5.4)1 453 2 590 3732 t
( name derives from one of)5 1175( \(The)1 271( detail.)1 297(cator,'' in)1 417 4 590 3852 t
(the allocator's main data structures, the)5 1684 1 590 3972 t
10 I f
(slab)2322 3972 w
10 R f
(. The)1 261 1 2489 3972 t
( more distinc-)2 579(name stuck within Sun because it was)6 1581 2 590 4092 t
( will be dis-)3 529( Slabs)1 293( or ``cache.'')2 552(tive than ``object'')2 786 4 590 4212 t
(cussed in Section 3.2.\))3 926 1 590 4332 t
(The terms)1 429 1 840 4494 t
10 I f
(object)1321 4494 w
10 R f
(,)1565 4494 w
10 I f
(buffer)1642 4494 w
10 R f
(, and)1 222 1 1881 4494 t
10 I f
(chunk)2156 4494 w
10 R f
(will be)1 303 1 2447 4494 t
( or less interchangeably, depending on)5 1711(used more)1 449 2 590 4614 t
( that piece of memory at the)6 1324(how we're viewing)2 836 2 590 4734 t
(moment.)590 4854 w
11 B f
(3.1. Caches)1 573 1 590 5154 t
10 R f
( a)1 82(Each cache has)2 632 2 590 5316 t
10 I f
(front end)1 377 1 1342 5316 t
10 R f
(and)1757 5316 w
10 I f
(back end)1 370 1 1939 5316 t
10 R f
(which are)1 403 1 2347 5316 t
(designed to be as decoupled as possible:)6 1657 1 590 5436 t
9 R f
(cache)1568 6066 w
cleartomark restore
%%BeginGlobal
%ident "@(#)lp:filter/postscript/postscript/draw.ps 1.1"
%
% Version 3.15 drawing procedures for dpost. Automatically pulled in, but only
% when needed.
%
/inpath false def
/savematrix matrix currentmatrix def
/Dl {
inpath
{pop pop neg lineto}
{newpath neg moveto neg lineto stroke}
ifelse
} bind def
/De {
/y1 exch 2 div def
/x1 exch 2 div def
neg exch x1 add exch translate
x1 y1 scale
0 0 1 0 360
inpath
{1 0 moveto arc savematrix setmatrix}
{newpath arc savematrix setmatrix stroke}
ifelse
} bind def
/Da {
/dy2 exch def
/dx2 exch def
/dy1 exch def
/dx1 exch def
dy1 add neg exch dx1 add exch
dx1 dx1 mul dy1 dy1 mul add sqrt
dy1 dx1 neg atan
dy2 neg dx2 atan
inpath
{arc}
{newpath arc stroke}
ifelse
} bind def
/DA {
/dy2 exch def
/dx2 exch def
/dy1 exch def
/dx1 exch def
dy1 add neg exch dx1 add exch
dx1 dx1 mul dy1 dy1 mul add sqrt
dy1 dx1 neg atan
dy2 neg dx2 atan
inpath
{arcn}
{newpath arcn stroke}
ifelse
} bind def
/Ds {
/y2 exch def
/x2 exch def
/y1 exch def
/x1 exch def
/y0 exch def
/x0 exch def
x0 5 x1 mul add 6 div
y0 5 y1 mul add -6 div
x2 5 x1 mul add 6 div
y2 5 y1 mul add -6 div
x1 x2 add 2 div
y1 y2 add -2 div
inpath
{curveto}
{newpath x0 x1 add 2 div y0 y1 add -2 div moveto curveto stroke}
ifelse
} bind def
%%EndGlobal
save mark
9 R f
1382 5868 1382 6228 Dl
1958 5868 1382 5868 Dl
1958 6228 1958 5868 Dl
1382 6228 1958 6228 Dl
(back end)1 330 1 821 5718 t
1166 5760 806 5760 Dl
(front end)1 335 1 2151 5718 t
2511 5760 2123 5760 Dl
(kmem)634 5934 w
9 S f
(_)859 5934 w
9 R f
(cache)904 5934 w
9 S f
(_)1109 5934 w
9 R f
(grow)1154 5934 w
950 5976 590 5976 Dl
1382 5976 950 5976 Dl
1382 5976 1310 5994 Dl
1382 5976 1310 5958 Dl
(kmem)649 6198 w
9 S f
(_)874 6198 w
9 R f
(cache)919 6198 w
9 S f
(_)1124 6198 w
9 R f
(reap)1169 6198 w
1022 6120 1382 6120 Dl
590 6120 1022 6120 Dl
590 6120 662 6102 Dl
590 6120 662 6138 Dl
(kmem)2007 5934 w
9 S f
(_)2232 5934 w
9 R f
(cache)2277 5934 w
9 S f
(_)2482 5934 w
9 R f
(alloc)2527 5934 w
2318 5976 1958 5976 Dl
2750 5976 2318 5976 Dl
2750 5976 2678 5994 Dl
2750 5976 2678 5958 Dl
(kmem)2024 6198 w
9 S f
(_)2249 6198 w
9 R f
(cache)2294 6198 w
9 S f
(_)2499 6198 w
9 R f
(free)2544 6198 w
2390 6120 2750 6120 Dl
1958 6120 2390 6120 Dl
1958 6120 2030 6102 Dl
1958 6120 2030 6138 Dl
10 R f
( is the public interface to the)6 1311(The front end)2 599 2 840 6462 t
( cache,)1 295( moves objects to and from the)6 1352(allocator. It)1 513 3 590 6582 t
( back end when it needs more)6 1468(calling into the)2 692 2 590 6702 t
(objects.)590 6822 w
( \257ow of real)3 644(The back end manages the)4 1266 2 840 6984 t
( in\257ux routine)2 663( The)1 261(memory through the cache.)3 1236 3 590 7104 t
(\()3110 696 w
10 CW f
(kmem_cache_grow\(\))3143 696 w
10 R f
(\) gets memory from the)4 1107 1 4163 696 t
( of it, and feeds those)5 894(VM system, makes objects out)4 1266 2 3110 816 t
( out\257ux routine)2 765( The)1 287( the cache.)2 571(objects into)1 537 4 3110 936 t
(\()3110 1056 w
10 CW f
(kmem_cache_reap\(\))3143 1056 w
10 R f
( by the VM)3 563(\) is invoked)2 544 2 4163 1056 t
( some of that memory back \320)6 1275(system when it wants)3 885 2 3110 1176 t
( that all back-end)3 735( Note)1 267( paging.)1 337(e.g., at the onset of)4 821 4 3110 1296 t
( memory pressure.)2 826(activity is triggered solely by)4 1334 2 3110 1416 t
(Memory \257ows in when the cache needs more)7 2160 1 3110 1536 t
( the sys-)2 355(objects and \257ows back out when the rest of)8 1805 2 3110 1656 t
( there are no arbitrary limits)5 1197(tem needs more pages;)3 963 2 3110 1776 t
( by a)2 228( control is provided)3 828( Hysteresis)1 490(or watermarks.)1 614 4 3110 1896 t
(working-set algorithm, described in Section 3.4.)5 1966 1 3110 2016 t
( not a monolithic entity,)4 1043(The slab allocator is)3 867 2 3360 2178 t
( a loose confederation of independent)5 1629(but rather is)2 531 2 3110 2298 t
( so the)2 325( caches have no shared state,)5 1301(caches. The)1 534 3 3110 2418 t
( locking instead of)3 825(allocator can employ per-cache)3 1335 2 3110 2538 t
( with one)2 428(protecting the entire arena \(kernel heap\))5 1732 2 3110 2658 t
( locking improves scalability)3 1206( Per-cache)1 466(global lock.)1 488 3 3110 2778 t
( number of distinct caches to be)6 1456(by allowing any)2 704 2 3110 2898 t
(accessed simultaneously.)1 1012 1 3110 3018 t
(Each cache maintains its own statistics \320)6 1910 1 3360 3180 t
( and free)2 456(total allocations, number of allocated)4 1704 2 3110 3300 t
( per-cache statistics provide)3 1279( These)1 352(buffers, etc.)1 529 3 3110 3420 t
( indicate)1 357( They)1 279( system behavior.)2 734(insight into overall)2 790 4 3110 3540 t
(which parts of the system consume the most)7 2160 1 3110 3660 t
( They)1 283(memory and help to identify memory leaks.)6 1877 2 3110 3780 t
( in various subsys-)3 843(also indicate the activity level)4 1317 2 3110 3900 t
( extent that allocator traf\256c is an accu-)7 1658(tems, to the)2 502 2 3110 4020 t
( is)1 111( message allocation)2 818( \(Streams)1 431(rate approximation.)1 800 4 3110 4140 t
(a direct measure of streams activity, for example.\))7 2059 1 3110 4260 t
( to)1 128(The slab allocator is operationally similar)5 1782 2 3360 4422 t
( ``QuickFit'')1 567(the ``CustoMalloc'' [Grunwald93A],)2 1593 2 3110 4542 t
( ``Zone'' [VanSciver88] alloca-)3 1348([Weinstock88], and)1 812 2 3110 4662 t
(tors, all of which maintain distinct freelists of the)8 2160 1 3110 4782 t
( The)1 289(most commonly requested buffer sizes.)4 1871 2 3110 4902 t
(Grunwald and Weinstock papers each demonstrate)5 2160 1 3110 5022 t
(that a customized segregated-storage allocator \320)5 2160 1 3110 5142 t
( has)1 178(one that)1 340 2 3110 5262 t
10 I f
(a priori)1 329 1 3673 5262 t
10 R f
(knowledge of the most com-)4 1223 1 4047 5262 t
(mon allocation sizes \320 is usually optimal in both)8 2160 1 3110 5382 t
(space)3110 5502 w
10 I f
(and)3406 5502 w
10 R f
( in this)2 371( slab allocator is)3 802(time. The)1 466 3 3631 5502 t
(category, but has the advantage that its customiza-)7 2160 1 3110 5622 t
( rather than being)3 746(tions are client-driven at run time)5 1414 2 3110 5742 t
( is also true of)4 670( \(This)1 295(hard-coded at compile time.)3 1195 3 3110 5862 t
(the Zone allocator.\))2 800 1 3110 5982 t
( non-caching allocation routines,)3 1372(The standard)1 538 2 3360 6144 t
10 CW f
(kmem_alloc\(9F\))3110 6264 w
10 R f
(and)4021 6264 w
10 CW f
(kmem_free\(9F\))4262 6264 w
10 R f
(, use)1 228 1 5042 6264 t
( startup, the system)3 904( At)1 202( internally.)1 477(object caches)1 577 4 3110 6384 t
( size)1 212(creates a set of about 30 caches ranging in)8 1948 2 3110 6504 t
( increments.)1 506(from 8 bytes to 9K in roughly 10-20%)7 1654 2 3110 6624 t
10 CW f
(kmem_alloc\(\))3110 6744 w
10 R f
(simply performs a)2 1185 1 4085 6744 t
10 CW f
(kmem_cache_alloc\(\))3110 6864 w
10 R f
(from the nearest-size)2 982 1 4288 6864 t
( are rare,)2 390( larger than 9K, which)4 979(cache. Allocations)1 791 3 3110 6984 t
(are handled directly by the back-end page supplier.)7 2095 1 3110 7104 t
cleartomark
showpage
restore
%%EndPage: 4 4
%%Page: 5 5
save
mark
5 pagesetup
11 B f
(3.2. Slabs)1 491 1 590 696 t
10 R f
(The)590 858 w
10 I f
(slab)783 858 w
10 R f
( of currency in the slab)5 987(is the primary unit)3 775 2 988 858 t
( the allocator needs to grow a)6 1445(allocator. When)1 715 2 590 978 t
( acquires an entire slab of)5 1197(cache, for example, it)3 963 2 590 1098 t
( allocator reclaims)2 803( the)1 181( Similarly,)1 490(objects at once.)2 686 4 590 1218 t
( relinquishing a)2 644(unused memory \(shrinks a cache\) by)5 1516 2 590 1338 t
(complete slab.)1 585 1 590 1458 t
( of one or more pages of virtu-)7 1292(A slab consists)2 618 2 840 1620 t
( memory carved up into equal-size)5 1518(ally contiguous)1 642 2 590 1740 t
(chunks, with a reference count indicating how many)7 2160 1 590 1860 t
( bene\256ts)1 357( The)1 234( chunks have been allocated.)4 1228(of those)1 341 4 590 1980 t
( this simple data structure to manage the)7 1808(of using)1 352 2 590 2100 t
(arena are somewhat striking:)3 1174 1 590 2220 t
10 B f
(\(1\) Reclaiming unused memory is trivial.)5 1843 1 590 2382 t
10 R f
(When)2512 2382 w
( count goes to zero the associated)6 1426(the slab reference)2 734 2 590 2502 t
( a)1 92( Thus)1 281( the VM system.)3 730(pages can be returned to)4 1057 4 590 2622 t
( the complex trees,)3 826(simple reference count replaces)3 1334 2 590 2742 t
( most)1 249(bitmaps, and coalescing algorithms found in)5 1911 2 590 2862 t
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?