diff options
author | Dave Chinner <dchinner@redhat.com> | 2010-07-19 00:56:17 -0400 |
---|---|---|
committer | Dave Chinner <david@fromorbit.com> | 2010-07-19 00:56:17 -0400 |
commit | 7f8275d0d660c146de6ee3017e1e2e594c49e820 (patch) | |
tree | 884db927118b44102750b5168ee36ef4b8b5cb4e | |
parent | d0c6f6258478e1dba532bf7c28e2cd6e1047d3a4 (diff) |
mm: add context argument to shrinker callback
The current shrinker implementation requires the registered callback
to have global state to work from. This makes it difficult to shrink
caches that are not global (e.g. per-filesystem caches). Pass the shrinker
structure to the callback so that users can embed the shrinker structure
in the context the shrinker needs to operate on and get back to it in the
callback via container_of().
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
-rw-r--r-- | arch/x86/kvm/mmu.c | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/i915/i915_gem.c | 2 | ||||
-rw-r--r-- | fs/dcache.c | 2 | ||||
-rw-r--r-- | fs/gfs2/glock.c | 2 | ||||
-rw-r--r-- | fs/gfs2/quota.c | 2 | ||||
-rw-r--r-- | fs/gfs2/quota.h | 2 | ||||
-rw-r--r-- | fs/inode.c | 2 | ||||
-rw-r--r-- | fs/mbcache.c | 5 | ||||
-rw-r--r-- | fs/nfs/dir.c | 2 | ||||
-rw-r--r-- | fs/nfs/internal.h | 3 | ||||
-rw-r--r-- | fs/quota/dquot.c | 2 | ||||
-rw-r--r-- | fs/ubifs/shrinker.c | 2 | ||||
-rw-r--r-- | fs/ubifs/ubifs.h | 2 | ||||
-rw-r--r-- | fs/xfs/linux-2.6/xfs_buf.c | 5 | ||||
-rw-r--r-- | fs/xfs/linux-2.6/xfs_sync.c | 1 | ||||
-rw-r--r-- | fs/xfs/quota/xfs_qm.c | 7 | ||||
-rw-r--r-- | include/linux/mm.h | 2 | ||||
-rw-r--r-- | mm/vmscan.c | 8 |
18 files changed, 31 insertions, 22 deletions
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 3699613e8830..b1ed0a1a5913 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c | |||
@@ -2926,7 +2926,7 @@ static int kvm_mmu_remove_some_alloc_mmu_pages(struct kvm *kvm) | |||
2926 | return kvm_mmu_zap_page(kvm, page) + 1; | 2926 | return kvm_mmu_zap_page(kvm, page) + 1; |
2927 | } | 2927 | } |
2928 | 2928 | ||
2929 | static int mmu_shrink(int nr_to_scan, gfp_t gfp_mask) | 2929 | static int mmu_shrink(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask) |
2930 | { | 2930 | { |
2931 | struct kvm *kvm; | 2931 | struct kvm *kvm; |
2932 | struct kvm *kvm_freed = NULL; | 2932 | struct kvm *kvm_freed = NULL; |
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 8757ecf6e96b..e7018708cc31 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c | |||
@@ -4978,7 +4978,7 @@ i915_gpu_is_active(struct drm_device *dev) | |||
4978 | } | 4978 | } |
4979 | 4979 | ||
4980 | static int | 4980 | static int |
4981 | i915_gem_shrink(int nr_to_scan, gfp_t gfp_mask) | 4981 | i915_gem_shrink(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask) |
4982 | { | 4982 | { |
4983 | drm_i915_private_t *dev_priv, *next_dev; | 4983 | drm_i915_private_t *dev_priv, *next_dev; |
4984 | struct drm_i915_gem_object *obj_priv, *next_obj; | 4984 | struct drm_i915_gem_object *obj_priv, *next_obj; |
diff --git a/fs/dcache.c b/fs/dcache.c index c8c78ba07827..86d4db15473e 100644 --- a/fs/dcache.c +++ b/fs/dcache.c | |||
@@ -896,7 +896,7 @@ EXPORT_SYMBOL(shrink_dcache_parent); | |||
896 | * | 896 | * |
897 | * In this case we return -1 to tell the caller that we baled. | 897 | * In this case we return -1 to tell the caller that we baled. |
898 | */ | 898 | */ |
899 | static int shrink_dcache_memory(int nr, gfp_t gfp_mask) | 899 | static int shrink_dcache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask) |
900 | { | 900 | { |
901 | if (nr) { | 901 | if (nr) { |
902 | if (!(gfp_mask & __GFP_FS)) | 902 | if (!(gfp_mask & __GFP_FS)) |
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index dbab3fdc2582..0898f3ec8212 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c | |||
@@ -1358,7 +1358,7 @@ void gfs2_glock_complete(struct gfs2_glock *gl, int ret) | |||
1358 | } | 1358 | } |
1359 | 1359 | ||
1360 | 1360 | ||
1361 | static int gfs2_shrink_glock_memory(int nr, gfp_t gfp_mask) | 1361 | static int gfs2_shrink_glock_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask) |
1362 | { | 1362 | { |
1363 | struct gfs2_glock *gl; | 1363 | struct gfs2_glock *gl; |
1364 | int may_demote; | 1364 | int may_demote; |
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index b256d6f24288..8f02d3db8f42 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c | |||
@@ -77,7 +77,7 @@ static LIST_HEAD(qd_lru_list); | |||
77 | static atomic_t qd_lru_count = ATOMIC_INIT(0); | 77 | static atomic_t qd_lru_count = ATOMIC_INIT(0); |
78 | static DEFINE_SPINLOCK(qd_lru_lock); | 78 | static DEFINE_SPINLOCK(qd_lru_lock); |
79 | 79 | ||
80 | int gfs2_shrink_qd_memory(int nr, gfp_t gfp_mask) | 80 | int gfs2_shrink_qd_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask) |
81 | { | 81 | { |
82 | struct gfs2_quota_data *qd; | 82 | struct gfs2_quota_data *qd; |
83 | struct gfs2_sbd *sdp; | 83 | struct gfs2_sbd *sdp; |
diff --git a/fs/gfs2/quota.h b/fs/gfs2/quota.h index 195f60c8bd14..e7d236ca48bd 100644 --- a/fs/gfs2/quota.h +++ b/fs/gfs2/quota.h | |||
@@ -51,7 +51,7 @@ static inline int gfs2_quota_lock_check(struct gfs2_inode *ip) | |||
51 | return ret; | 51 | return ret; |
52 | } | 52 | } |
53 | 53 | ||
54 | extern int gfs2_shrink_qd_memory(int nr, gfp_t gfp_mask); | 54 | extern int gfs2_shrink_qd_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask); |
55 | extern const struct quotactl_ops gfs2_quotactl_ops; | 55 | extern const struct quotactl_ops gfs2_quotactl_ops; |
56 | 56 | ||
57 | #endif /* __QUOTA_DOT_H__ */ | 57 | #endif /* __QUOTA_DOT_H__ */ |
diff --git a/fs/inode.c b/fs/inode.c index 2bee20ae3d65..722860b323a9 100644 --- a/fs/inode.c +++ b/fs/inode.c | |||
@@ -512,7 +512,7 @@ static void prune_icache(int nr_to_scan) | |||
512 | * This function is passed the number of inodes to scan, and it returns the | 512 | * This function is passed the number of inodes to scan, and it returns the |
513 | * total number of remaining possibly-reclaimable inodes. | 513 | * total number of remaining possibly-reclaimable inodes. |
514 | */ | 514 | */ |
515 | static int shrink_icache_memory(int nr, gfp_t gfp_mask) | 515 | static int shrink_icache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask) |
516 | { | 516 | { |
517 | if (nr) { | 517 | if (nr) { |
518 | /* | 518 | /* |
diff --git a/fs/mbcache.c b/fs/mbcache.c index ec88ff3d04a9..e28f21b95344 100644 --- a/fs/mbcache.c +++ b/fs/mbcache.c | |||
@@ -115,7 +115,7 @@ mb_cache_indexes(struct mb_cache *cache) | |||
115 | * What the mbcache registers as to get shrunk dynamically. | 115 | * What the mbcache registers as to get shrunk dynamically. |
116 | */ | 116 | */ |
117 | 117 | ||
118 | static int mb_cache_shrink_fn(int nr_to_scan, gfp_t gfp_mask); | 118 | static int mb_cache_shrink_fn(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask); |
119 | 119 | ||
120 | static struct shrinker mb_cache_shrinker = { | 120 | static struct shrinker mb_cache_shrinker = { |
121 | .shrink = mb_cache_shrink_fn, | 121 | .shrink = mb_cache_shrink_fn, |
@@ -191,13 +191,14 @@ forget: | |||
191 | * This function is called by the kernel memory management when memory | 191 | * This function is called by the kernel memory management when memory |
192 | * gets low. | 192 | * gets low. |
193 | * | 193 | * |
194 | * @shrink: (ignored) | ||
194 | * @nr_to_scan: Number of objects to scan | 195 | * @nr_to_scan: Number of objects to scan |
195 | * @gfp_mask: (ignored) | 196 | * @gfp_mask: (ignored) |
196 | * | 197 | * |
197 | * Returns the number of objects which are present in the cache. | 198 | * Returns the number of objects which are present in the cache. |
198 | */ | 199 | */ |
199 | static int | 200 | static int |
200 | mb_cache_shrink_fn(int nr_to_scan, gfp_t gfp_mask) | 201 | mb_cache_shrink_fn(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask) |
201 | { | 202 | { |
202 | LIST_HEAD(free_list); | 203 | LIST_HEAD(free_list); |
203 | struct list_head *l, *ltmp; | 204 | struct list_head *l, *ltmp; |
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 782b431ef91c..e60416d3f818 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c | |||
@@ -1710,7 +1710,7 @@ static void nfs_access_free_list(struct list_head *head) | |||
1710 | } | 1710 | } |
1711 | } | 1711 | } |
1712 | 1712 | ||
1713 | int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask) | 1713 | int nfs_access_cache_shrinker(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask) |
1714 | { | 1714 | { |
1715 | LIST_HEAD(head); | 1715 | LIST_HEAD(head); |
1716 | struct nfs_inode *nfsi; | 1716 | struct nfs_inode *nfsi; |
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index d8bd619e386c..e70f44b9b3f4 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h | |||
@@ -205,7 +205,8 @@ extern struct rpc_procinfo nfs4_procedures[]; | |||
205 | void nfs_close_context(struct nfs_open_context *ctx, int is_sync); | 205 | void nfs_close_context(struct nfs_open_context *ctx, int is_sync); |
206 | 206 | ||
207 | /* dir.c */ | 207 | /* dir.c */ |
208 | extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask); | 208 | extern int nfs_access_cache_shrinker(struct shrinker *shrink, |
209 | int nr_to_scan, gfp_t gfp_mask); | ||
209 | 210 | ||
210 | /* inode.c */ | 211 | /* inode.c */ |
211 | extern struct workqueue_struct *nfsiod_workqueue; | 212 | extern struct workqueue_struct *nfsiod_workqueue; |
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index 12c233da1b6b..437d2ca2de97 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c | |||
@@ -676,7 +676,7 @@ static void prune_dqcache(int count) | |||
676 | * This is called from kswapd when we think we need some | 676 | * This is called from kswapd when we think we need some |
677 | * more memory | 677 | * more memory |
678 | */ | 678 | */ |
679 | static int shrink_dqcache_memory(int nr, gfp_t gfp_mask) | 679 | static int shrink_dqcache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask) |
680 | { | 680 | { |
681 | if (nr) { | 681 | if (nr) { |
682 | spin_lock(&dq_list_lock); | 682 | spin_lock(&dq_list_lock); |
diff --git a/fs/ubifs/shrinker.c b/fs/ubifs/shrinker.c index 02feb59cefca..0b201114a5ad 100644 --- a/fs/ubifs/shrinker.c +++ b/fs/ubifs/shrinker.c | |||
@@ -277,7 +277,7 @@ static int kick_a_thread(void) | |||
277 | return 0; | 277 | return 0; |
278 | } | 278 | } |
279 | 279 | ||
280 | int ubifs_shrinker(int nr, gfp_t gfp_mask) | 280 | int ubifs_shrinker(struct shrinker *shrink, int nr, gfp_t gfp_mask) |
281 | { | 281 | { |
282 | int freed, contention = 0; | 282 | int freed, contention = 0; |
283 | long clean_zn_cnt = atomic_long_read(&ubifs_clean_zn_cnt); | 283 | long clean_zn_cnt = atomic_long_read(&ubifs_clean_zn_cnt); |
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index 2eef553d50c8..04310878f449 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h | |||
@@ -1575,7 +1575,7 @@ int ubifs_tnc_start_commit(struct ubifs_info *c, struct ubifs_zbranch *zroot); | |||
1575 | int ubifs_tnc_end_commit(struct ubifs_info *c); | 1575 | int ubifs_tnc_end_commit(struct ubifs_info *c); |
1576 | 1576 | ||
1577 | /* shrinker.c */ | 1577 | /* shrinker.c */ |
1578 | int ubifs_shrinker(int nr_to_scan, gfp_t gfp_mask); | 1578 | int ubifs_shrinker(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask); |
1579 | 1579 | ||
1580 | /* commit.c */ | 1580 | /* commit.c */ |
1581 | int ubifs_bg_thread(void *info); | 1581 | int ubifs_bg_thread(void *info); |
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c index 649ade8ef598..2ee3f7a60163 100644 --- a/fs/xfs/linux-2.6/xfs_buf.c +++ b/fs/xfs/linux-2.6/xfs_buf.c | |||
@@ -45,7 +45,7 @@ | |||
45 | 45 | ||
46 | static kmem_zone_t *xfs_buf_zone; | 46 | static kmem_zone_t *xfs_buf_zone; |
47 | STATIC int xfsbufd(void *); | 47 | STATIC int xfsbufd(void *); |
48 | STATIC int xfsbufd_wakeup(int, gfp_t); | 48 | STATIC int xfsbufd_wakeup(struct shrinker *, int, gfp_t); |
49 | STATIC void xfs_buf_delwri_queue(xfs_buf_t *, int); | 49 | STATIC void xfs_buf_delwri_queue(xfs_buf_t *, int); |
50 | static struct shrinker xfs_buf_shake = { | 50 | static struct shrinker xfs_buf_shake = { |
51 | .shrink = xfsbufd_wakeup, | 51 | .shrink = xfsbufd_wakeup, |
@@ -340,7 +340,7 @@ _xfs_buf_lookup_pages( | |||
340 | __func__, gfp_mask); | 340 | __func__, gfp_mask); |
341 | 341 | ||
342 | XFS_STATS_INC(xb_page_retries); | 342 | XFS_STATS_INC(xb_page_retries); |
343 | xfsbufd_wakeup(0, gfp_mask); | 343 | xfsbufd_wakeup(NULL, 0, gfp_mask); |
344 | congestion_wait(BLK_RW_ASYNC, HZ/50); | 344 | congestion_wait(BLK_RW_ASYNC, HZ/50); |
345 | goto retry; | 345 | goto retry; |
346 | } | 346 | } |
@@ -1762,6 +1762,7 @@ xfs_buf_runall_queues( | |||
1762 | 1762 | ||
1763 | STATIC int | 1763 | STATIC int |
1764 | xfsbufd_wakeup( | 1764 | xfsbufd_wakeup( |
1765 | struct shrinker *shrink, | ||
1765 | int priority, | 1766 | int priority, |
1766 | gfp_t mask) | 1767 | gfp_t mask) |
1767 | { | 1768 | { |
diff --git a/fs/xfs/linux-2.6/xfs_sync.c b/fs/xfs/linux-2.6/xfs_sync.c index ef7f0218bccb..be375827af98 100644 --- a/fs/xfs/linux-2.6/xfs_sync.c +++ b/fs/xfs/linux-2.6/xfs_sync.c | |||
@@ -838,6 +838,7 @@ static struct rw_semaphore xfs_mount_list_lock; | |||
838 | 838 | ||
839 | static int | 839 | static int |
840 | xfs_reclaim_inode_shrink( | 840 | xfs_reclaim_inode_shrink( |
841 | struct shrinker *shrink, | ||
841 | int nr_to_scan, | 842 | int nr_to_scan, |
842 | gfp_t gfp_mask) | 843 | gfp_t gfp_mask) |
843 | { | 844 | { |
diff --git a/fs/xfs/quota/xfs_qm.c b/fs/xfs/quota/xfs_qm.c index 8c117ff2e3ab..67c018392d62 100644 --- a/fs/xfs/quota/xfs_qm.c +++ b/fs/xfs/quota/xfs_qm.c | |||
@@ -69,7 +69,7 @@ STATIC void xfs_qm_list_destroy(xfs_dqlist_t *); | |||
69 | 69 | ||
70 | STATIC int xfs_qm_init_quotainos(xfs_mount_t *); | 70 | STATIC int xfs_qm_init_quotainos(xfs_mount_t *); |
71 | STATIC int xfs_qm_init_quotainfo(xfs_mount_t *); | 71 | STATIC int xfs_qm_init_quotainfo(xfs_mount_t *); |
72 | STATIC int xfs_qm_shake(int, gfp_t); | 72 | STATIC int xfs_qm_shake(struct shrinker *, int, gfp_t); |
73 | 73 | ||
74 | static struct shrinker xfs_qm_shaker = { | 74 | static struct shrinker xfs_qm_shaker = { |
75 | .shrink = xfs_qm_shake, | 75 | .shrink = xfs_qm_shake, |
@@ -2117,7 +2117,10 @@ xfs_qm_shake_freelist( | |||
2117 | */ | 2117 | */ |
2118 | /* ARGSUSED */ | 2118 | /* ARGSUSED */ |
2119 | STATIC int | 2119 | STATIC int |
2120 | xfs_qm_shake(int nr_to_scan, gfp_t gfp_mask) | 2120 | xfs_qm_shake( |
2121 | struct shrinker *shrink, | ||
2122 | int nr_to_scan, | ||
2123 | gfp_t gfp_mask) | ||
2121 | { | 2124 | { |
2122 | int ndqused, nfree, n; | 2125 | int ndqused, nfree, n; |
2123 | 2126 | ||
diff --git a/include/linux/mm.h b/include/linux/mm.h index b969efb03787..a2b48041b910 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h | |||
@@ -999,7 +999,7 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm) | |||
999 | * querying the cache size, so a fastpath for that case is appropriate. | 999 | * querying the cache size, so a fastpath for that case is appropriate. |
1000 | */ | 1000 | */ |
1001 | struct shrinker { | 1001 | struct shrinker { |
1002 | int (*shrink)(int nr_to_scan, gfp_t gfp_mask); | 1002 | int (*shrink)(struct shrinker *, int nr_to_scan, gfp_t gfp_mask); |
1003 | int seeks; /* seeks to recreate an obj */ | 1003 | int seeks; /* seeks to recreate an obj */ |
1004 | 1004 | ||
1005 | /* These are for internal use */ | 1005 | /* These are for internal use */ |
diff --git a/mm/vmscan.c b/mm/vmscan.c index 9c7e57cc63a3..199fa436c0dd 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c | |||
@@ -213,8 +213,9 @@ unsigned long shrink_slab(unsigned long scanned, gfp_t gfp_mask, | |||
213 | list_for_each_entry(shrinker, &shrinker_list, list) { | 213 | list_for_each_entry(shrinker, &shrinker_list, list) { |
214 | unsigned long long delta; | 214 | unsigned long long delta; |
215 | unsigned long total_scan; | 215 | unsigned long total_scan; |
216 | unsigned long max_pass = (*shrinker->shrink)(0, gfp_mask); | 216 | unsigned long max_pass; |
217 | 217 | ||
218 | max_pass = (*shrinker->shrink)(shrinker, 0, gfp_mask); | ||
218 | delta = (4 * scanned) / shrinker->seeks; | 219 | delta = (4 * scanned) / shrinker->seeks; |
219 | delta *= max_pass; | 220 | delta *= max_pass; |
220 | do_div(delta, lru_pages + 1); | 221 | do_div(delta, lru_pages + 1); |
@@ -242,8 +243,9 @@ unsigned long shrink_slab(unsigned long scanned, gfp_t gfp_mask, | |||
242 | int shrink_ret; | 243 | int shrink_ret; |
243 | int nr_before; | 244 | int nr_before; |
244 | 245 | ||
245 | nr_before = (*shrinker->shrink)(0, gfp_mask); | 246 | nr_before = (*shrinker->shrink)(shrinker, 0, gfp_mask); |
246 | shrink_ret = (*shrinker->shrink)(this_scan, gfp_mask); | 247 | shrink_ret = (*shrinker->shrink)(shrinker, this_scan, |
248 | gfp_mask); | ||
247 | if (shrink_ret == -1) | 249 | if (shrink_ret == -1) |
248 | break; | 250 | break; |
249 | if (shrink_ret < nr_before) | 251 | if (shrink_ret < nr_before) |