blob: 68c097077ef04af4533dd3ccc0272db8564bf269 [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.
Dave Chinnerb0d40c92011-07-08 14:14:42 +100010 */
11struct shrink_control {
12 gfp_t gfp_mask;
13
Dave Chinnera0b02132013-08-28 10:18:16 +100014 /*
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 */
Dave Chinnerb0d40c92011-07-08 14:14:42 +100019 unsigned long nr_to_scan;
Dave Chinner0ce3d742013-08-28 10:18:03 +100020
21 /* shrink from these nodes */
22 nodemask_t nodes_to_scan;
Glauber Costa1d3d4432013-08-28 10:18:04 +100023 /* current node being shrunk (for NUMA aware shrinkers) */
24 int nid;
Dave Chinnerb0d40c92011-07-08 14:14:42 +100025};
26
Dave Chinner24f7c6b2013-08-28 10:17:56 +100027#define SHRINK_STOP (~0UL)
Dave Chinnerb0d40c92011-07-08 14:14:42 +100028/*
29 * A callback you can register to apply pressure to ageable caches.
30 *
Dave Chinner24f7c6b2013-08-28 10:17:56 +100031 * @count_objects should return the number of freeable items in the cache. If
32 * there are no objects to free or the number of freeable items cannot be
33 * determined, it should return 0. No deadlock checks should be done during the
34 * count callback - the shrinker relies on aggregating scan counts that couldn't
35 * be executed due to potential deadlocks to be run at a later call when the
36 * deadlock condition is no longer pending.
Dave Chinnerb0d40c92011-07-08 14:14:42 +100037 *
Dave Chinner24f7c6b2013-08-28 10:17:56 +100038 * @scan_objects will only be called if @count_objects returned a non-zero
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.
Glauber Costa1d3d4432013-08-28 10:18:04 +100045 *
46 * @flags determine the shrinker abilities, like numa awareness
Dave Chinnerb0d40c92011-07-08 14:14:42 +100047 */
48struct shrinker {
Dave Chinner24f7c6b2013-08-28 10:17:56 +100049 unsigned long (*count_objects)(struct shrinker *,
50 struct shrink_control *sc);
51 unsigned long (*scan_objects)(struct shrinker *,
52 struct shrink_control *sc);
53
Dave Chinnerb0d40c92011-07-08 14:14:42 +100054 int seeks; /* seeks to recreate an obj */
55 long batch; /* reclaim batch size, 0 = default */
Glauber Costa1d3d4432013-08-28 10:18:04 +100056 unsigned long flags;
Dave Chinnerb0d40c92011-07-08 14:14:42 +100057
58 /* These are for internal use */
59 struct list_head list;
Glauber Costa1d3d4432013-08-28 10:18:04 +100060 /* objs pending delete, per node */
61 atomic_long_t *nr_deferred;
Dave Chinnerb0d40c92011-07-08 14:14:42 +100062};
63#define DEFAULT_SEEKS 2 /* A good number if you don't know better. */
Glauber Costa1d3d4432013-08-28 10:18:04 +100064
65/* Flags */
66#define SHRINKER_NUMA_AWARE (1 << 0)
67
68extern int register_shrinker(struct shrinker *);
Dave Chinnerb0d40c92011-07-08 14:14:42 +100069extern void unregister_shrinker(struct shrinker *);
70#endif