next up previous contents index
Next: 8.5 Per-CPU Object Cache Up: 8. Slab Allocator Previous: 8.3 Objects   Contents   Index

Subsections


8.4 Sizes Cache

Linux keeps two sets of caches for small memory allocations which the physical page allocator is unsuitable. One cache is for use with DMA and the other suitable for normal use. The human readable names for these caches size-X cache and size-X(DMA) cache viewable from /proc/cpuinfo. Information for each sized cache is stored in a cache_sizes_t struct defined in mm/slab.c

331 typedef struct cache_sizes {
332         size_t           cs_size;
333         kmem_cache_t    *cs_cachep;
334         kmem_cache_t    *cs_dmacachep;
335 } cache_sizes_t;

332 The size of the memory block

333 The cache of blocks for normal memory use

334 The cache of blocks for use with DMA

As there is a limited number of these caches that exist, a static array called cache_sizes is initialized at compile time beginning with 32 bytes on a 4KiB machine and 64 for greater page sizes.

337 static cache_sizes_t cache_sizes[] = {
338 #if PAGE_SIZE == 4096
339         {    32,        NULL, NULL},
340 #endif
341         {    64,        NULL, NULL},
342         {   128,        NULL, NULL},
343         {   256,        NULL, NULL},
344         {   512,        NULL, NULL},
345         {  1024,        NULL, NULL},
346         {  2048,        NULL, NULL},
347         {  4096,        NULL, NULL},
348         {  8192,        NULL, NULL},
349         { 16384,        NULL, NULL},
350         { 32768,        NULL, NULL},
351         { 65536,        NULL, NULL},
352         {131072,        NULL, NULL},
353         {     0,        NULL, NULL}

As is obvious, this is a static array that is zero terminated consisting of buffers of succeeding powers of 2 from 2$^5$ to 2$^{17}$ . An array now exists that describes each sized cache which must be initialized with caches at system startup.


8.4.1 kmalloc

With the existence of the sizes cache, the slab allocator is able to offer a new allocator function, kmalloc() for use when small memory buffers are required. When a request is received, the appropriate sizes cache is selected and an object assigned from it. The call graph on Figure 8.13 is therefore very simple as all the hard work is in cache allocation.



\includegraphics[]{graphs/kmalloc.ps}
[1]
Figure: Call Graph: kmalloc
[2]


8.4.2 kfree

Just as there is a kmalloc() function to allocate small memory objects for use, there is a kfree() for freeing it. As with kmalloc(), the real work takes place during object freeing (See Section 8.3.3) so the call graph in Figure 8.14 is very simple.



\includegraphics[]{graphs/kfree.ps}
[1]
Figure: Call Graph: kfree
[2]



next up previous contents index
Next: 8.5 Per-CPU Object Cache Up: 8. Slab Allocator Previous: 8.3 Objects   Contents   Index
Mel 2003-01-14