diff options
author | Dave Chinner <dchinner@redhat.com> | 2011-07-08 00:14:42 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2011-07-20 20:47:10 -0400 |
commit | b0d40c92adafde7c2d81203ce7c1c69275f41140 (patch) | |
tree | f75a19dcd1a37aff23dc43323b58f014b1297c6b /include | |
parent | 12ad3ab66103e6582ca69c0c9de18b13487eaaef (diff) |
superblock: introduce per-sb cache shrinker infrastructure
With context based shrinkers, we can implement a per-superblock
shrinker that shrinks the caches attached to the superblock. We
currently have global shrinkers for the inode and dentry caches that
split up into per-superblock operations via a coarse proportioning
method that does not batch very well. The global shrinkers also
have a dependency - dentries pin inodes - so we have to be very
careful about how we register the global shrinkers so that the
implicit call order is always correct.
With a per-sb shrinker callout, we can encode this dependency
directly into the per-sb shrinker, hence avoiding the need for
strictly ordering shrinker registrations. We also have no need for
any proportioning code for the shrinker subsystem already provides
this functionality across all shrinkers. Allowing the shrinker to
operate on a single superblock at a time means that we do less
superblock list traversals and locking and reclaim should batch more
effectively. This should result in less CPU overhead for reclaim and
potentially faster reclaim of items from each filesystem.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/fs.h | 7 | ||||
-rw-r--r-- | include/linux/mm.h | 40 | ||||
-rw-r--r-- | include/linux/shrinker.h | 42 |
3 files changed, 50 insertions, 39 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h index 460d2cc21ec6..d7f35e90b84a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -393,6 +393,7 @@ struct inodes_stat_t { | |||
393 | #include <linux/semaphore.h> | 393 | #include <linux/semaphore.h> |
394 | #include <linux/fiemap.h> | 394 | #include <linux/fiemap.h> |
395 | #include <linux/rculist_bl.h> | 395 | #include <linux/rculist_bl.h> |
396 | #include <linux/shrinker.h> | ||
396 | #include <linux/atomic.h> | 397 | #include <linux/atomic.h> |
397 | 398 | ||
398 | #include <asm/byteorder.h> | 399 | #include <asm/byteorder.h> |
@@ -1444,8 +1445,14 @@ struct super_block { | |||
1444 | * Saved pool identifier for cleancache (-1 means none) | 1445 | * Saved pool identifier for cleancache (-1 means none) |
1445 | */ | 1446 | */ |
1446 | int cleancache_poolid; | 1447 | int cleancache_poolid; |
1448 | |||
1449 | struct shrinker s_shrink; /* per-sb shrinker handle */ | ||
1447 | }; | 1450 | }; |
1448 | 1451 | ||
1452 | /* superblock cache pruning functions */ | ||
1453 | extern void prune_icache_sb(struct super_block *sb, int nr_to_scan); | ||
1454 | extern void prune_dcache_sb(struct super_block *sb, int nr_to_scan); | ||
1455 | |||
1449 | extern struct timespec current_fs_time(struct super_block *sb); | 1456 | extern struct timespec current_fs_time(struct super_block *sb); |
1450 | 1457 | ||
1451 | /* | 1458 | /* |
diff --git a/include/linux/mm.h b/include/linux/mm.h index 9b9777ac726d..e3a1a9eec0b1 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/range.h> | 15 | #include <linux/range.h> |
16 | #include <linux/pfn.h> | 16 | #include <linux/pfn.h> |
17 | #include <linux/bit_spinlock.h> | 17 | #include <linux/bit_spinlock.h> |
18 | #include <linux/shrinker.h> | ||
18 | 19 | ||
19 | struct mempolicy; | 20 | struct mempolicy; |
20 | struct anon_vma; | 21 | struct anon_vma; |
@@ -1121,45 +1122,6 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm) | |||
1121 | } | 1122 | } |
1122 | #endif | 1123 | #endif |
1123 | 1124 | ||
1124 | /* | ||
1125 | * This struct is used to pass information from page reclaim to the shrinkers. | ||
1126 | * We consolidate the values for easier extention later. | ||
1127 | */ | ||
1128 | struct shrink_control { | ||
1129 | gfp_t gfp_mask; | ||
1130 | |||
1131 | /* How many slab objects shrinker() should scan and try to reclaim */ | ||
1132 | unsigned long nr_to_scan; | ||
1133 | }; | ||
1134 | |||
1135 | /* | ||
1136 | * A callback you can register to apply pressure to ageable caches. | ||
1137 | * | ||
1138 | * 'sc' is passed shrink_control which includes a count 'nr_to_scan' | ||
1139 | * and a 'gfpmask'. It should look through the least-recently-used | ||
1140 | * 'nr_to_scan' entries and attempt to free them up. It should return | ||
1141 | * the number of objects which remain in the cache. If it returns -1, it means | ||
1142 | * it cannot do any scanning at this time (eg. there is a risk of deadlock). | ||
1143 | * | ||
1144 | * The 'gfpmask' refers to the allocation we are currently trying to | ||
1145 | * fulfil. | ||
1146 | * | ||
1147 | * Note that 'shrink' will be passed nr_to_scan == 0 when the VM is | ||
1148 | * querying the cache size, so a fastpath for that case is appropriate. | ||
1149 | */ | ||
1150 | struct shrinker { | ||
1151 | int (*shrink)(struct shrinker *, struct shrink_control *sc); | ||
1152 | int seeks; /* seeks to recreate an obj */ | ||
1153 | long batch; /* reclaim batch size, 0 = default */ | ||
1154 | |||
1155 | /* These are for internal use */ | ||
1156 | struct list_head list; | ||
1157 | long nr; /* objs pending delete */ | ||
1158 | }; | ||
1159 | #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */ | ||
1160 | extern void register_shrinker(struct shrinker *); | ||
1161 | extern void unregister_shrinker(struct shrinker *); | ||
1162 | |||
1163 | int vma_wants_writenotify(struct vm_area_struct *vma); | 1125 | int vma_wants_writenotify(struct vm_area_struct *vma); |
1164 | 1126 | ||
1165 | extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr, | 1127 | extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr, |
diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h new file mode 100644 index 000000000000..790651b4e5ba --- /dev/null +++ b/include/linux/shrinker.h | |||
@@ -0,0 +1,42 @@ | |||
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 | struct shrink_control { | ||
9 | gfp_t gfp_mask; | ||
10 | |||
11 | /* How many slab objects shrinker() should scan and try to reclaim */ | ||
12 | unsigned long nr_to_scan; | ||
13 | }; | ||
14 | |||
15 | /* | ||
16 | * A callback you can register to apply pressure to ageable caches. | ||
17 | * | ||
18 | * 'sc' is passed shrink_control which includes a count 'nr_to_scan' | ||
19 | * and a 'gfpmask'. It should look through the least-recently-used | ||
20 | * 'nr_to_scan' entries and attempt to free them up. It should return | ||
21 | * the number of objects which remain in the cache. If it returns -1, it means | ||
22 | * it cannot do any scanning at this time (eg. there is a risk of deadlock). | ||
23 | * | ||
24 | * The 'gfpmask' refers to the allocation we are currently trying to | ||
25 | * fulfil. | ||
26 | * | ||
27 | * Note that 'shrink' will be passed nr_to_scan == 0 when the VM is | ||
28 | * querying the cache size, so a fastpath for that case is appropriate. | ||
29 | */ | ||
30 | struct shrinker { | ||
31 | int (*shrink)(struct shrinker *, struct shrink_control *sc); | ||
32 | int seeks; /* seeks to recreate an obj */ | ||
33 | long batch; /* reclaim batch size, 0 = default */ | ||
34 | |||
35 | /* These are for internal use */ | ||
36 | struct list_head list; | ||
37 | long nr; /* objs pending delete */ | ||
38 | }; | ||
39 | #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */ | ||
40 | extern void register_shrinker(struct shrinker *); | ||
41 | extern void unregister_shrinker(struct shrinker *); | ||
42 | #endif | ||