Dave Chinner | b0d40c9 | 2011-07-08 14:14:42 +1000 | [diff] [blame] | 1 | #ifndef _LINUX_SHRINKER_H |
| 2 | #define _LINUX_SHRINKER_H |
| 3 | |
| 4 | /* |
| 5 | * This struct is used to pass information from page reclaim to the shrinkers. |
| 6 | * We consolidate the values for easier extention later. |
Dave Chinner | 24f7c6b | 2013-08-28 10:17:56 +1000 | [diff] [blame] | 7 | * |
| 8 | * The 'gfpmask' refers to the allocation we are currently trying to |
| 9 | * fulfil. |
| 10 | * |
| 11 | * Note that 'shrink' will be passed nr_to_scan == 0 when the VM is |
| 12 | * querying the cache size, so a fastpath for that case is appropriate. |
Dave Chinner | b0d40c9 | 2011-07-08 14:14:42 +1000 | [diff] [blame] | 13 | */ |
| 14 | struct shrink_control { |
| 15 | gfp_t gfp_mask; |
| 16 | |
| 17 | /* How many slab objects shrinker() should scan and try to reclaim */ |
| 18 | unsigned long nr_to_scan; |
Dave Chinner | 0ce3d74 | 2013-08-28 10:18:03 +1000 | [diff] [blame^] | 19 | |
| 20 | /* shrink from these nodes */ |
| 21 | nodemask_t nodes_to_scan; |
Dave Chinner | b0d40c9 | 2011-07-08 14:14:42 +1000 | [diff] [blame] | 22 | }; |
| 23 | |
Dave Chinner | 24f7c6b | 2013-08-28 10:17:56 +1000 | [diff] [blame] | 24 | #define SHRINK_STOP (~0UL) |
Dave Chinner | b0d40c9 | 2011-07-08 14:14:42 +1000 | [diff] [blame] | 25 | /* |
| 26 | * A callback you can register to apply pressure to ageable caches. |
| 27 | * |
Dave Chinner | 24f7c6b | 2013-08-28 10:17:56 +1000 | [diff] [blame] | 28 | * @shrink() should look through the least-recently-used 'nr_to_scan' entries |
| 29 | * and attempt to free them up. It should return the number of objects which |
| 30 | * remain in the cache. If it returns -1, it means it cannot do any scanning at |
| 31 | * this time (eg. there is a risk of deadlock). |
Dave Chinner | b0d40c9 | 2011-07-08 14:14:42 +1000 | [diff] [blame] | 32 | * |
Dave Chinner | 24f7c6b | 2013-08-28 10:17:56 +1000 | [diff] [blame] | 33 | * @count_objects should return the number of freeable items in the cache. If |
| 34 | * there are no objects to free or the number of freeable items cannot be |
| 35 | * determined, it should return 0. No deadlock checks should be done during the |
| 36 | * count callback - the shrinker relies on aggregating scan counts that couldn't |
| 37 | * be executed due to potential deadlocks to be run at a later call when the |
| 38 | * deadlock condition is no longer pending. |
Dave Chinner | b0d40c9 | 2011-07-08 14:14:42 +1000 | [diff] [blame] | 39 | * |
Dave Chinner | 24f7c6b | 2013-08-28 10:17:56 +1000 | [diff] [blame] | 40 | * @scan_objects will only be called if @count_objects returned a non-zero |
| 41 | * value for the number of freeable objects. The callout should scan the cache |
| 42 | * and attempt to free items from the cache. It should then return the number |
| 43 | * of objects freed during the scan, or SHRINK_STOP if progress cannot be made |
| 44 | * due to potential deadlocks. If SHRINK_STOP is returned, then no further |
| 45 | * attempts to call the @scan_objects will be made from the current reclaim |
| 46 | * context. |
Dave Chinner | b0d40c9 | 2011-07-08 14:14:42 +1000 | [diff] [blame] | 47 | */ |
| 48 | struct shrinker { |
| 49 | int (*shrink)(struct shrinker *, struct shrink_control *sc); |
Dave Chinner | 24f7c6b | 2013-08-28 10:17:56 +1000 | [diff] [blame] | 50 | unsigned long (*count_objects)(struct shrinker *, |
| 51 | struct shrink_control *sc); |
| 52 | unsigned long (*scan_objects)(struct shrinker *, |
| 53 | struct shrink_control *sc); |
| 54 | |
Dave Chinner | b0d40c9 | 2011-07-08 14:14:42 +1000 | [diff] [blame] | 55 | int seeks; /* seeks to recreate an obj */ |
| 56 | long batch; /* reclaim batch size, 0 = default */ |
| 57 | |
| 58 | /* These are for internal use */ |
| 59 | struct list_head list; |
Konstantin Khlebnikov | 83aeead | 2011-12-08 14:33:54 -0800 | [diff] [blame] | 60 | atomic_long_t nr_in_batch; /* objs pending delete */ |
Dave Chinner | b0d40c9 | 2011-07-08 14:14:42 +1000 | [diff] [blame] | 61 | }; |
| 62 | #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */ |
| 63 | extern void register_shrinker(struct shrinker *); |
| 64 | extern void unregister_shrinker(struct shrinker *); |
| 65 | #endif |