diff options
author | Dave Chinner <dchinner@redhat.com> | 2013-08-27 20:17:56 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2013-09-10 18:56:30 -0400 |
commit | 24f7c6b981fb70084757382da464ea85d72af300 (patch) | |
tree | 641ec828955f54b13641fadcee35b530989349a6 /include/linux/shrinker.h | |
parent | dd1f6b2e43a53ee58eb87d5e623cf44e277d005d (diff) |
mm: new shrinker API
The current shrinker callout API uses an a single shrinker call for
multiple functions. To determine the function, a special magical value is
passed in a parameter to change the behaviour. This complicates the
implementation and return value specification for the different
behaviours.
Separate the two different behaviours into separate operations, one to
return a count of freeable objects in the cache, and another to scan a
certain number of objects in the cache for freeing. In defining these new
operations, ensure the return values and resultant behaviours are clearly
defined and documented.
Modify shrink_slab() to use the new API and implement the callouts for all
the existing shrinkers.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Glauber Costa <glommer@parallels.com>
Acked-by: Mel Gorman <mgorman@suse.de>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Cc: Arve Hjønnevåg <arve@android.com>
Cc: Carlos Maiolino <cmaiolino@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Chuck Lever <chuck.lever@oracle.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: David Rientjes <rientjes@google.com>
Cc: Gleb Natapov <gleb@redhat.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: J. Bruce Fields <bfields@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'include/linux/shrinker.h')
-rw-r--r-- | include/linux/shrinker.h | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index ac6b8ee07825..884e76222e1b 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h | |||
@@ -4,6 +4,12 @@ | |||
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. | ||
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. | ||
7 | */ | 13 | */ |
8 | struct shrink_control { | 14 | struct shrink_control { |
9 | gfp_t gfp_mask; | 15 | gfp_t gfp_mask; |
@@ -12,23 +18,37 @@ struct shrink_control { | |||
12 | unsigned long nr_to_scan; | 18 | unsigned long nr_to_scan; |
13 | }; | 19 | }; |
14 | 20 | ||
21 | #define SHRINK_STOP (~0UL) | ||
15 | /* | 22 | /* |
16 | * A callback you can register to apply pressure to ageable caches. | 23 | * A callback you can register to apply pressure to ageable caches. |
17 | * | 24 | * |
18 | * 'sc' is passed shrink_control which includes a count 'nr_to_scan' | 25 | * @shrink() should look through the least-recently-used 'nr_to_scan' entries |
19 | * and a 'gfpmask'. It should look through the least-recently-used | 26 | * and attempt to free them up. It should return the number of objects which |
20 | * 'nr_to_scan' entries and attempt to free them up. It should return | 27 | * remain in the cache. If it returns -1, it means it cannot do any scanning at |
21 | * the number of objects which remain in the cache. If it returns -1, it means | 28 | * this time (eg. there is a risk of deadlock). |
22 | * it cannot do any scanning at this time (eg. there is a risk of deadlock). | ||
23 | * | 29 | * |
24 | * The 'gfpmask' refers to the allocation we are currently trying to | 30 | * @count_objects should return the number of freeable items in the cache. If |
25 | * fulfil. | 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. | ||
26 | * | 36 | * |
27 | * Note that 'shrink' will be passed nr_to_scan == 0 when the VM is | 37 | * @scan_objects will only be called if @count_objects returned a non-zero |
28 | * querying the cache size, so a fastpath for that case is appropriate. | 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. | ||
29 | */ | 44 | */ |
30 | struct shrinker { | 45 | struct shrinker { |
31 | int (*shrink)(struct shrinker *, struct shrink_control *sc); | 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 | |||
32 | int seeks; /* seeks to recreate an obj */ | 52 | int seeks; /* seeks to recreate an obj */ |
33 | long batch; /* reclaim batch size, 0 = default */ | 53 | long batch; /* reclaim batch size, 0 = default */ |
34 | 54 | ||