diff options
Diffstat (limited to 'include/linux/shrinker.h')
-rw-r--r-- | include/linux/shrinker.h | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index ac6b8ee07825..68c097077ef0 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h | |||
@@ -4,39 +4,67 @@ | |||
4 | /* | 4 | /* |
5 | * This struct is used to pass information from page reclaim to the shrinkers. | 5 | * This struct is used to pass information from page reclaim to the shrinkers. |
6 | * We consolidate the values for easier extention later. | 6 | * We consolidate the values for easier extention later. |
7 | * | ||
8 | * The 'gfpmask' refers to the allocation we are currently trying to | ||
9 | * fulfil. | ||
7 | */ | 10 | */ |
8 | struct shrink_control { | 11 | struct shrink_control { |
9 | gfp_t gfp_mask; | 12 | gfp_t gfp_mask; |
10 | 13 | ||
11 | /* How many slab objects shrinker() should scan and try to reclaim */ | 14 | /* |
15 | * How many objects scan_objects should scan and try to reclaim. | ||
16 | * This is reset before every call, so it is safe for callees | ||
17 | * to modify. | ||
18 | */ | ||
12 | unsigned long nr_to_scan; | 19 | unsigned long nr_to_scan; |
20 | |||
21 | /* shrink from these nodes */ | ||
22 | nodemask_t nodes_to_scan; | ||
23 | /* current node being shrunk (for NUMA aware shrinkers) */ | ||
24 | int nid; | ||
13 | }; | 25 | }; |
14 | 26 | ||
27 | #define SHRINK_STOP (~0UL) | ||
15 | /* | 28 | /* |
16 | * A callback you can register to apply pressure to ageable caches. | 29 | * A callback you can register to apply pressure to ageable caches. |
17 | * | 30 | * |
18 | * 'sc' is passed shrink_control which includes a count 'nr_to_scan' | 31 | * @count_objects should return the number of freeable items in the cache. If |
19 | * and a 'gfpmask'. It should look through the least-recently-used | 32 | * there are no objects to free or the number of freeable items cannot be |
20 | * 'nr_to_scan' entries and attempt to free them up. It should return | 33 | * determined, it should return 0. No deadlock checks should be done during the |
21 | * the number of objects which remain in the cache. If it returns -1, it means | 34 | * count callback - the shrinker relies on aggregating scan counts that couldn't |
22 | * it cannot do any scanning at this time (eg. there is a risk of deadlock). | 35 | * be executed due to potential deadlocks to be run at a later call when the |
36 | * deadlock condition is no longer pending. | ||
23 | * | 37 | * |
24 | * The 'gfpmask' refers to the allocation we are currently trying to | 38 | * @scan_objects will only be called if @count_objects returned a non-zero |
25 | * fulfil. | 39 | * value for the number of freeable objects. The callout should scan the cache |
40 | * and attempt to free items from the cache. It should then return the number | ||
41 | * of objects freed during the scan, or SHRINK_STOP if progress cannot be made | ||
42 | * due to potential deadlocks. If SHRINK_STOP is returned, then no further | ||
43 | * attempts to call the @scan_objects will be made from the current reclaim | ||
44 | * context. | ||
26 | * | 45 | * |
27 | * Note that 'shrink' will be passed nr_to_scan == 0 when the VM is | 46 | * @flags determine the shrinker abilities, like numa awareness |
28 | * querying the cache size, so a fastpath for that case is appropriate. | ||
29 | */ | 47 | */ |
30 | struct shrinker { | 48 | struct shrinker { |
31 | int (*shrink)(struct shrinker *, struct shrink_control *sc); | 49 | unsigned long (*count_objects)(struct shrinker *, |
50 | struct shrink_control *sc); | ||
51 | unsigned long (*scan_objects)(struct shrinker *, | ||
52 | struct shrink_control *sc); | ||
53 | |||
32 | int seeks; /* seeks to recreate an obj */ | 54 | int seeks; /* seeks to recreate an obj */ |
33 | long batch; /* reclaim batch size, 0 = default */ | 55 | long batch; /* reclaim batch size, 0 = default */ |
56 | unsigned long flags; | ||
34 | 57 | ||
35 | /* These are for internal use */ | 58 | /* These are for internal use */ |
36 | struct list_head list; | 59 | struct list_head list; |
37 | atomic_long_t nr_in_batch; /* objs pending delete */ | 60 | /* objs pending delete, per node */ |
61 | atomic_long_t *nr_deferred; | ||
38 | }; | 62 | }; |
39 | #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */ | 63 | #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */ |
40 | extern void register_shrinker(struct shrinker *); | 64 | |
65 | /* Flags */ | ||
66 | #define SHRINKER_NUMA_AWARE (1 << 0) | ||
67 | |||
68 | extern int register_shrinker(struct shrinker *); | ||
41 | extern void unregister_shrinker(struct shrinker *); | 69 | extern void unregister_shrinker(struct shrinker *); |
42 | #endif | 70 | #endif |