]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/linux/shrinker.h
mm: new shrinker API
[karo-tx-linux.git] / include / linux / shrinker.h
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.
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.
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;
19 };
20
21 #define SHRINK_STOP (~0UL)
22 /*
23  * A callback you can register to apply pressure to ageable caches.
24  *
25  * @shrink() should look through the least-recently-used 'nr_to_scan' entries
26  * and attempt to free them up.  It should return the number of objects which
27  * remain in the cache.  If it returns -1, it means it cannot do any scanning at
28  * this time (eg. there is a risk of deadlock).
29  *
30  * @count_objects should return the number of freeable items in the cache. If
31  * there are no objects to free or the number of freeable items cannot be
32  * determined, it should return 0. No deadlock checks should be done during the
33  * count callback - the shrinker relies on aggregating scan counts that couldn't
34  * be executed due to potential deadlocks to be run at a later call when the
35  * deadlock condition is no longer pending.
36  *
37  * @scan_objects will only be called if @count_objects returned a non-zero
38  * value for the number of freeable objects. The callout should scan the cache
39  * and attempt to free items from the cache. It should then return the number
40  * of objects freed during the scan, or SHRINK_STOP if progress cannot be made
41  * due to potential deadlocks. If SHRINK_STOP is returned, then no further
42  * attempts to call the @scan_objects will be made from the current reclaim
43  * context.
44  */
45 struct shrinker {
46         int (*shrink)(struct shrinker *, struct shrink_control *sc);
47         unsigned long (*count_objects)(struct shrinker *,
48                                        struct shrink_control *sc);
49         unsigned long (*scan_objects)(struct shrinker *,
50                                       struct shrink_control *sc);
51
52         int seeks;      /* seeks to recreate an obj */
53         long batch;     /* reclaim batch size, 0 = default */
54
55         /* These are for internal use */
56         struct list_head list;
57         atomic_long_t nr_in_batch; /* objs pending delete */
58 };
59 #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */
60 extern void register_shrinker(struct shrinker *);
61 extern void unregister_shrinker(struct shrinker *);
62 #endif