Data Structures

The kernel defines its own data structure to describe the characteristics of shrinker functions:

mm/vmscan.c struct shrinker {

int (*shrink)(int nr_to_scan, gfp_t gfp_mask); int seeks; /* seeks to recreate an obj */

/* These are for internal use */ struct list_head list;

long nr; /* objs pending delete */

□ shrink is 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 indicates how many objects 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 as nr_to_scan argument.

□ seeks is 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. list serves as the list element.

□ nr is 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.

Continue reading here: Registering and Removing Shrinkers

Was this article helpful?

0 0