blob: 8f80f243fed9de0436aef2625fd5176e49a5b6a2 [file] [log] [blame]
Dave Chinnerb0d40c92011-07-08 14:14:42 +10001#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 Chinner24f7c6b2013-08-28 10:17:56 +10007 *
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 Chinnerb0d40c92011-07-08 14:14:42 +100013 */
14struct 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 Chinner0ce3d742013-08-28 10:18:03 +100019
20 /* shrink from these nodes */
21 nodemask_t nodes_to_scan;
Glauber Costa1d3d4432013-08-28 10:18:04 +100022 /* current node being shrunk (for NUMA aware shrinkers) */
23 int nid;
Dave Chinnerb0d40c92011-07-08 14:14:42 +100024};
25
Dave Chinner24f7c6b2013-08-28 10:17:56 +100026#define SHRINK_STOP (~0UL)
Dave Chinnerb0d40c92011-07-08 14:14:42 +100027/*
28 * A callback you can register to apply pressure to ageable caches.
29 *
Dave Chinner24f7c6b2013-08-28 10:17:56 +100030 * @shrink() should look through the least-recently-used 'nr_to_scan' entries
31 * and attempt to free them up. It should return the number of objects which
32 * remain in the cache. If it returns -1, it means it cannot do any scanning at
33 * this time (eg. there is a risk of deadlock).
Dave Chinnerb0d40c92011-07-08 14:14:42 +100034 *
Dave Chinner24f7c6b2013-08-28 10:17:56 +100035 * @count_objects should return the number of freeable items in the cache. If
36 * there are no objects to free or the number of freeable items cannot be
37 * determined, it should return 0. No deadlock checks should be done during the
38 * count callback - the shrinker relies on aggregating scan counts that couldn't
39 * be executed due to potential deadlocks to be run at a later call when the
40 * deadlock condition is no longer pending.
Dave Chinnerb0d40c92011-07-08 14:14:42 +100041 *
Dave Chinner24f7c6b2013-08-28 10:17:56 +100042 * @scan_objects will only be called if @count_objects returned a non-zero
43 * value for the number of freeable objects. The callout should scan the cache
44 * and attempt to free items from the cache. It should then return the number
45 * of objects freed during the scan, or SHRINK_STOP if progress cannot be made
46 * due to potential deadlocks. If SHRINK_STOP is returned, then no further
47 * attempts to call the @scan_objects will be made from the current reclaim
48 * context.
Glauber Costa1d3d4432013-08-28 10:18:04 +100049 *
50 * @flags determine the shrinker abilities, like numa awareness
Dave Chinnerb0d40c92011-07-08 14:14:42 +100051 */
52struct shrinker {
53 int (*shrink)(struct shrinker *, struct shrink_control *sc);
Dave Chinner24f7c6b2013-08-28 10:17:56 +100054 unsigned long (*count_objects)(struct shrinker *,
55 struct shrink_control *sc);
56 unsigned long (*scan_objects)(struct shrinker *,
57 struct shrink_control *sc);
58
Dave Chinnerb0d40c92011-07-08 14:14:42 +100059 int seeks; /* seeks to recreate an obj */
60 long batch; /* reclaim batch size, 0 = default */
Glauber Costa1d3d4432013-08-28 10:18:04 +100061 unsigned long flags;
Dave Chinnerb0d40c92011-07-08 14:14:42 +100062
63 /* These are for internal use */
64 struct list_head list;
Glauber Costa1d3d4432013-08-28 10:18:04 +100065 /* objs pending delete, per node */
66 atomic_long_t *nr_deferred;
Dave Chinnerb0d40c92011-07-08 14:14:42 +100067};
68#define DEFAULT_SEEKS 2 /* A good number if you don't know better. */
Glauber Costa1d3d4432013-08-28 10:18:04 +100069
70/* Flags */
71#define SHRINKER_NUMA_AWARE (1 << 0)
72
73extern int register_shrinker(struct shrinker *);
Dave Chinnerb0d40c92011-07-08 14:14:42 +100074extern void unregister_shrinker(struct shrinker *);
75#endif