Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 18: Page Reclaim and Swapping


❑ shrinkis a pointer to the function invoked to shrink a cache. Every shrinker function must
accept two parameters — the number of memory pages to be examined and the memory
type — and return an integer number that indicateshow manyobjects are still in the cache.

This differs from the kernel’s normal practice of returning the number of released
objects/pages.

If−1 is returned, the function could not perform any shrinking.
When the kernel wants to query the size of the cache, it passes 0 asnr_to_scanargument.
❑ seeksis a factor to adjust the cache weight in relation to the page cache. I examine this in more
detail when I discuss how caches are shrunk.
❑ All registered shrinkers are kept in a doubly linked standard list.listserves as the list element.
❑ nris the number of elements to be freed by the shrinker function. The kernel uses this value to
enable the batch processing of objects for performance reasons.

18.10.2 Registering and Removing Shrinkers


register_shrinkeris used to register a new shrinker:

mm/vmscan.c
void register_shrinker(struct shrinker *shrinker)

The function expects ashrinkerinstance whereseekandshrinkare set appropriately. Besides, the
function only ensures thatshrinkeris added to the global listshrinker_list.

At present, only a small number of shrinkers are present in the kernel. This includes the following:

❑ shrink_icache_memoryshrinks the inode cache discussed in Chapter 8 and also manages
struct Inodeobjects.
❑ shrink_dcache_memoryis responsible for thedentrycache also discussed in Chapter 8.
❑ mb_cache_shrink_fnshrinks a general cache for filesystem metadata (currently used to imple-
ment enhanced attributes in the Ext2 and Ext3 filesystems).

Theremove_shrinkerfunction removes shrinkers from the global list by reference to theirshrinker
instance:

mm/vmscan.c
void remove_shrinker(struct shrinker *shrinker)

18.10.3 Shrinking Caches


shrink_slabis invoked to shrink all caches registered asshrinkable. The allocation mask that specifies the
required memory type and the number of pages scanned during page reclaim are passed to the function.
Essentially, it iterates over all shrinkers inshrinker_list:

mm/vmscan.c
static int shrink_slab(long scanned, unsigned int gfp_mask)
{
Free download pdf