Наши партнеры








Книги по Linux (с отзывами читателей)

Библиотека сайта rus-linux.net

After this documentation was released in July 2003, I was approached by Prentice Hall and asked to write a book on the Linux VM under the Bruce Peren's Open Book Series.

The book is available and called simply "Understanding The Linux Virtual Memory Manager". There is a lot of additional material in the book that is not available here, including details on later 2.4 kernels, introductions to 2.6, a whole new chapter on the shared memory filesystem, coverage of TLB management, a lot more code commentary, countless other additions and clarifications and a CD with lots of cool stuff on it. This material (although now dated and lacking in comparison to the book) will remain available although I obviously encourge you to buy the book from your favourite book store :-) . As the book is under the Bruce Perens Open Book Series, it will be available 90 days after appearing on the book shelves which means it is not available right now. When it is available, it will be downloadable from http://www.phptr.com/perens so check there for more information.

To be fully clear, this webpage is not the actual book.
next up previous contents index
Next: 9.5 Per-CPU Object Cache Up: 9. Slab Allocator Previous: 9.3 Objects   Contents   Index

Subsections


9.4 Sizes Cache

Linux keeps two sets of caches for small memory allocations for 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 are size-N cache and size-N(DMA) cache which are viewable from /proc/slabinfo. 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;

The fields in this struct are described as follows:

cs_size The size of the memory block;

cs_cachep The cache of blocks for normal memory use;

cs_dmacachep The cache of blocks for use with DMA.

As there are a limited number of these caches that exist, a static array called cache_sizes is initialised 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 initialised with caches at system startup.


9.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 9.14 is therefore very simple as all the hard work is in cache allocation.

Figure 9.14: Call Graph: kmalloc()
\includegraphics[width=5cm]{graphs/kmalloc.ps}

9.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 9.3.3) so the call graph in Figure 9.15 is very simple.

Figure 9.15: Call Graph: kfree()
\includegraphics[width=5cm]{graphs/kfree.ps}


next up previous contents index
Next: 9.5 Per-CPU Object Cache Up: 9. Slab Allocator Previous: 9.3 Objects   Contents   Index
Mel 2004-02-15