Skip to content

Commit 1495f23

Browse files
yinghantorvalds
authored andcommitted
vmscan: change shrinker API by passing shrink_control struct
Change each shrinker's API by consolidating the existing parameters into shrink_control struct. This will simplify any further features added w/o touching each file of shrinker. [[email protected]: fix build] [[email protected]: fix warning] [[email protected]: fix up new shrinker API] [[email protected]: fix xfs warning] [[email protected]: update gfs2] Signed-off-by: Ying Han <[email protected]> Cc: KOSAKI Motohiro <[email protected]> Cc: Minchan Kim <[email protected]> Acked-by: Pavel Emelyanov <[email protected]> Cc: KAMEZAWA Hiroyuki <[email protected]> Cc: Mel Gorman <[email protected]> Acked-by: Rik van Riel <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Steven Whitehouse <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent a09ed5e commit 1495f23

File tree

21 files changed

+95
-61
lines changed

21 files changed

+95
-61
lines changed

arch/x86/kvm/mmu.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -3545,10 +3545,11 @@ static int kvm_mmu_remove_some_alloc_mmu_pages(struct kvm *kvm,
35453545
return kvm_mmu_prepare_zap_page(kvm, page, invalid_list);
35463546
}
35473547

3548-
static int mmu_shrink(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
3548+
static int mmu_shrink(struct shrinker *shrink, struct shrink_control *sc)
35493549
{
35503550
struct kvm *kvm;
35513551
struct kvm *kvm_freed = NULL;
3552+
int nr_to_scan = sc->nr_to_scan;
35523553

35533554
if (nr_to_scan == 0)
35543555
goto out;

drivers/gpu/drm/i915/i915_gem.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ static int i915_gem_phys_pwrite(struct drm_device *dev,
5656
static void i915_gem_free_object_tail(struct drm_i915_gem_object *obj);
5757

5858
static int i915_gem_inactive_shrink(struct shrinker *shrinker,
59-
int nr_to_scan,
60-
gfp_t gfp_mask);
61-
59+
struct shrink_control *sc);
6260

6361
/* some bookkeeping */
6462
static void i915_gem_info_add_obj(struct drm_i915_private *dev_priv,
@@ -4092,16 +4090,15 @@ i915_gpu_is_active(struct drm_device *dev)
40924090
}
40934091

40944092
static int
4095-
i915_gem_inactive_shrink(struct shrinker *shrinker,
4096-
int nr_to_scan,
4097-
gfp_t gfp_mask)
4093+
i915_gem_inactive_shrink(struct shrinker *shrinker, struct shrink_control *sc)
40984094
{
40994095
struct drm_i915_private *dev_priv =
41004096
container_of(shrinker,
41014097
struct drm_i915_private,
41024098
mm.inactive_shrinker);
41034099
struct drm_device *dev = dev_priv->dev;
41044100
struct drm_i915_gem_object *obj, *next;
4101+
int nr_to_scan = sc->nr_to_scan;
41054102
int cnt;
41064103

41074104
if (!mutex_trylock(&dev->struct_mutex))

drivers/gpu/drm/ttm/ttm_page_alloc.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,14 @@ static int ttm_pool_get_num_unused_pages(void)
395395
/**
396396
* Callback for mm to request pool to reduce number of page held.
397397
*/
398-
static int ttm_pool_mm_shrink(struct shrinker *shrink, int shrink_pages, gfp_t gfp_mask)
398+
static int ttm_pool_mm_shrink(struct shrinker *shrink,
399+
struct shrink_control *sc)
399400
{
400401
static atomic_t start_pool = ATOMIC_INIT(0);
401402
unsigned i;
402403
unsigned pool_offset = atomic_add_return(1, &start_pool);
403404
struct ttm_page_pool *pool;
405+
int shrink_pages = sc->nr_to_scan;
404406

405407
pool_offset = pool_offset % NUM_POOLS;
406408
/* select start pool in round robin fashion */

drivers/staging/zcache/zcache.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -1181,9 +1181,12 @@ static bool zcache_freeze;
11811181
/*
11821182
* zcache shrinker interface (only useful for ephemeral pages, so zbud only)
11831183
*/
1184-
static int shrink_zcache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
1184+
static int shrink_zcache_memory(struct shrinker *shrink,
1185+
struct shrink_control *sc)
11851186
{
11861187
int ret = -1;
1188+
int nr = sc->nr_to_scan;
1189+
gfp_t gfp_mask = sc->gfp_mask;
11871190

11881191
if (nr >= 0) {
11891192
if (!(gfp_mask & __GFP_FS))

fs/dcache.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ void shrink_dcache_parent(struct dentry * parent)
12201220
EXPORT_SYMBOL(shrink_dcache_parent);
12211221

12221222
/*
1223-
* Scan `nr' dentries and return the number which remain.
1223+
* Scan `sc->nr_slab_to_reclaim' dentries and return the number which remain.
12241224
*
12251225
* We need to avoid reentering the filesystem if the caller is performing a
12261226
* GFP_NOFS allocation attempt. One example deadlock is:
@@ -1231,8 +1231,12 @@ EXPORT_SYMBOL(shrink_dcache_parent);
12311231
*
12321232
* In this case we return -1 to tell the caller that we baled.
12331233
*/
1234-
static int shrink_dcache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
1234+
static int shrink_dcache_memory(struct shrinker *shrink,
1235+
struct shrink_control *sc)
12351236
{
1237+
int nr = sc->nr_to_scan;
1238+
gfp_t gfp_mask = sc->gfp_mask;
1239+
12361240
if (nr) {
12371241
if (!(gfp_mask & __GFP_FS))
12381242
return -1;

fs/drop_caches.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ static void drop_slab(void)
4242
int nr_objects;
4343
struct shrink_control shrink = {
4444
.gfp_mask = GFP_KERNEL,
45-
.nr_scanned = 1000,
4645
};
4746

4847
do {
49-
nr_objects = shrink_slab(&shrink, 1000);
48+
nr_objects = shrink_slab(&shrink, 1000, 1000);
5049
} while (nr_objects > 10);
5150
}
5251

fs/gfs2/glock.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -1346,11 +1346,14 @@ void gfs2_glock_complete(struct gfs2_glock *gl, int ret)
13461346
}
13471347

13481348

1349-
static int gfs2_shrink_glock_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
1349+
static int gfs2_shrink_glock_memory(struct shrinker *shrink,
1350+
struct shrink_control *sc)
13501351
{
13511352
struct gfs2_glock *gl;
13521353
int may_demote;
13531354
int nr_skipped = 0;
1355+
int nr = sc->nr_to_scan;
1356+
gfp_t gfp_mask = sc->gfp_mask;
13541357
LIST_HEAD(skipped);
13551358

13561359
if (nr == 0)

fs/gfs2/quota.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include <linux/sched.h>
4040
#include <linux/slab.h>
41+
#include <linux/mm.h>
4142
#include <linux/spinlock.h>
4243
#include <linux/completion.h>
4344
#include <linux/buffer_head.h>
@@ -77,19 +78,20 @@ static LIST_HEAD(qd_lru_list);
7778
static atomic_t qd_lru_count = ATOMIC_INIT(0);
7879
static DEFINE_SPINLOCK(qd_lru_lock);
7980

80-
int gfs2_shrink_qd_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
81+
int gfs2_shrink_qd_memory(struct shrinker *shrink, struct shrink_control *sc)
8182
{
8283
struct gfs2_quota_data *qd;
8384
struct gfs2_sbd *sdp;
85+
int nr_to_scan = sc->nr_to_scan;
8486

85-
if (nr == 0)
87+
if (nr_to_scan == 0)
8688
goto out;
8789

88-
if (!(gfp_mask & __GFP_FS))
90+
if (!(sc->gfp_mask & __GFP_FS))
8991
return -1;
9092

9193
spin_lock(&qd_lru_lock);
92-
while (nr && !list_empty(&qd_lru_list)) {
94+
while (nr_to_scan && !list_empty(&qd_lru_list)) {
9395
qd = list_entry(qd_lru_list.next,
9496
struct gfs2_quota_data, qd_reclaim);
9597
sdp = qd->qd_gl->gl_sbd;
@@ -110,7 +112,7 @@ int gfs2_shrink_qd_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
110112
spin_unlock(&qd_lru_lock);
111113
kmem_cache_free(gfs2_quotad_cachep, qd);
112114
spin_lock(&qd_lru_lock);
113-
nr--;
115+
nr_to_scan--;
114116
}
115117
spin_unlock(&qd_lru_lock);
116118

fs/gfs2/quota.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
struct gfs2_inode;
1414
struct gfs2_sbd;
15+
struct shrink_control;
1516

1617
#define NO_QUOTA_CHANGE ((u32)-1)
1718

@@ -51,7 +52,8 @@ static inline int gfs2_quota_lock_check(struct gfs2_inode *ip)
5152
return ret;
5253
}
5354

54-
extern int gfs2_shrink_qd_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask);
55+
extern int gfs2_shrink_qd_memory(struct shrinker *shrink,
56+
struct shrink_control *sc);
5557
extern const struct quotactl_ops gfs2_quotactl_ops;
5658

5759
#endif /* __QUOTA_DOT_H__ */

fs/inode.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,12 @@ static void prune_icache(int nr_to_scan)
751751
* This function is passed the number of inodes to scan, and it returns the
752752
* total number of remaining possibly-reclaimable inodes.
753753
*/
754-
static int shrink_icache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
754+
static int shrink_icache_memory(struct shrinker *shrink,
755+
struct shrink_control *sc)
755756
{
757+
int nr = sc->nr_to_scan;
758+
gfp_t gfp_mask = sc->gfp_mask;
759+
756760
if (nr) {
757761
/*
758762
* Nasty deadlock avoidance. We may hold various FS locks,

fs/mbcache.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ static DEFINE_SPINLOCK(mb_cache_spinlock);
9090
* What the mbcache registers as to get shrunk dynamically.
9191
*/
9292

93-
static int mb_cache_shrink_fn(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask);
93+
static int mb_cache_shrink_fn(struct shrinker *shrink,
94+
struct shrink_control *sc);
9495

9596
static struct shrinker mb_cache_shrinker = {
9697
.shrink = mb_cache_shrink_fn,
@@ -156,18 +157,19 @@ __mb_cache_entry_release_unlock(struct mb_cache_entry *ce)
156157
* gets low.
157158
*
158159
* @shrink: (ignored)
159-
* @nr_to_scan: Number of objects to scan
160-
* @gfp_mask: (ignored)
160+
* @sc: shrink_control passed from reclaim
161161
*
162162
* Returns the number of objects which are present in the cache.
163163
*/
164164
static int
165-
mb_cache_shrink_fn(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
165+
mb_cache_shrink_fn(struct shrinker *shrink, struct shrink_control *sc)
166166
{
167167
LIST_HEAD(free_list);
168168
struct mb_cache *cache;
169169
struct mb_cache_entry *entry, *tmp;
170170
int count = 0;
171+
int nr_to_scan = sc->nr_to_scan;
172+
gfp_t gfp_mask = sc->gfp_mask;
171173

172174
mb_debug("trying to free %d entries", nr_to_scan);
173175
spin_lock(&mb_cache_spinlock);

fs/nfs/dir.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -2042,11 +2042,14 @@ static void nfs_access_free_list(struct list_head *head)
20422042
}
20432043
}
20442044

2045-
int nfs_access_cache_shrinker(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
2045+
int nfs_access_cache_shrinker(struct shrinker *shrink,
2046+
struct shrink_control *sc)
20462047
{
20472048
LIST_HEAD(head);
20482049
struct nfs_inode *nfsi, *next;
20492050
struct nfs_access_entry *cache;
2051+
int nr_to_scan = sc->nr_to_scan;
2052+
gfp_t gfp_mask = sc->gfp_mask;
20502053

20512054
if ((gfp_mask & GFP_KERNEL) != GFP_KERNEL)
20522055
return (nr_to_scan == 0) ? 0 : -1;

fs/nfs/internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ extern int nfs_init_client(struct nfs_client *clp,
234234

235235
/* dir.c */
236236
extern int nfs_access_cache_shrinker(struct shrinker *shrink,
237-
int nr_to_scan, gfp_t gfp_mask);
237+
struct shrink_control *sc);
238238

239239
/* inode.c */
240240
extern struct workqueue_struct *nfsiod_workqueue;

fs/quota/dquot.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,11 @@ static void prune_dqcache(int count)
691691
* This is called from kswapd when we think we need some
692692
* more memory
693693
*/
694-
static int shrink_dqcache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
694+
static int shrink_dqcache_memory(struct shrinker *shrink,
695+
struct shrink_control *sc)
695696
{
697+
int nr = sc->nr_to_scan;
698+
696699
if (nr) {
697700
spin_lock(&dq_list_lock);
698701
prune_dqcache(nr);

fs/xfs/linux-2.6/xfs_buf.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1422,12 +1422,12 @@ xfs_wait_buftarg(
14221422
int
14231423
xfs_buftarg_shrink(
14241424
struct shrinker *shrink,
1425-
int nr_to_scan,
1426-
gfp_t mask)
1425+
struct shrink_control *sc)
14271426
{
14281427
struct xfs_buftarg *btp = container_of(shrink,
14291428
struct xfs_buftarg, bt_shrinker);
14301429
struct xfs_buf *bp;
1430+
int nr_to_scan = sc->nr_to_scan;
14311431
LIST_HEAD(dispose);
14321432

14331433
if (!nr_to_scan)

fs/xfs/linux-2.6/xfs_sync.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -1032,13 +1032,14 @@ xfs_reclaim_inodes(
10321032
static int
10331033
xfs_reclaim_inode_shrink(
10341034
struct shrinker *shrink,
1035-
int nr_to_scan,
1036-
gfp_t gfp_mask)
1035+
struct shrink_control *sc)
10371036
{
10381037
struct xfs_mount *mp;
10391038
struct xfs_perag *pag;
10401039
xfs_agnumber_t ag;
10411040
int reclaimable;
1041+
int nr_to_scan = sc->nr_to_scan;
1042+
gfp_t gfp_mask = sc->gfp_mask;
10421043

10431044
mp = container_of(shrink, struct xfs_mount, m_inode_shrink);
10441045
if (nr_to_scan) {

fs/xfs/quota/xfs_qm.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ STATIC void xfs_qm_list_destroy(xfs_dqlist_t *);
6060

6161
STATIC int xfs_qm_init_quotainos(xfs_mount_t *);
6262
STATIC int xfs_qm_init_quotainfo(xfs_mount_t *);
63-
STATIC int xfs_qm_shake(struct shrinker *, int, gfp_t);
63+
STATIC int xfs_qm_shake(struct shrinker *, struct shrink_control *);
6464

6565
static struct shrinker xfs_qm_shaker = {
6666
.shrink = xfs_qm_shake,
@@ -2009,10 +2009,10 @@ xfs_qm_shake_freelist(
20092009
STATIC int
20102010
xfs_qm_shake(
20112011
struct shrinker *shrink,
2012-
int nr_to_scan,
2013-
gfp_t gfp_mask)
2012+
struct shrink_control *sc)
20142013
{
20152014
int ndqused, nfree, n;
2015+
gfp_t gfp_mask = sc->gfp_mask;
20162016

20172017
if (!kmem_shake_allow(gfp_mask))
20182018
return 0;

include/linux/mm.h

+11-8
Original file line numberDiff line numberDiff line change
@@ -1166,18 +1166,20 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
11661166
* We consolidate the values for easier extention later.
11671167
*/
11681168
struct shrink_control {
1169-
unsigned long nr_scanned;
11701169
gfp_t gfp_mask;
1170+
1171+
/* How many slab objects shrinker() should scan and try to reclaim */
1172+
unsigned long nr_to_scan;
11711173
};
11721174

11731175
/*
11741176
* A callback you can register to apply pressure to ageable caches.
11751177
*
1176-
* 'shrink' is passed a count 'nr_to_scan' and a 'gfpmask'. It should
1177-
* look through the least-recently-used 'nr_to_scan' entries and
1178-
* attempt to free them up. It should return the number of objects
1179-
* which remain in the cache. If it returns -1, it means it cannot do
1180-
* any scanning at this time (eg. there is a risk of deadlock).
1178+
* 'sc' is passed shrink_control which includes a count 'nr_to_scan'
1179+
* and a 'gfpmask'. It should look through the least-recently-used
1180+
* 'nr_to_scan' entries and attempt to free them up. It should return
1181+
* the number of objects which remain in the cache. If it returns -1, it means
1182+
* it cannot do any scanning at this time (eg. there is a risk of deadlock).
11811183
*
11821184
* The 'gfpmask' refers to the allocation we are currently trying to
11831185
* fulfil.
@@ -1186,7 +1188,7 @@ struct shrink_control {
11861188
* querying the cache size, so a fastpath for that case is appropriate.
11871189
*/
11881190
struct shrinker {
1189-
int (*shrink)(struct shrinker *, int nr_to_scan, gfp_t gfp_mask);
1191+
int (*shrink)(struct shrinker *, struct shrink_control *sc);
11901192
int seeks; /* seeks to recreate an obj */
11911193

11921194
/* These are for internal use */
@@ -1640,7 +1642,8 @@ int in_gate_area_no_mm(unsigned long addr);
16401642
int drop_caches_sysctl_handler(struct ctl_table *, int,
16411643
void __user *, size_t *, loff_t *);
16421644
unsigned long shrink_slab(struct shrink_control *shrink,
1643-
unsigned long lru_pages);
1645+
unsigned long nr_pages_scanned,
1646+
unsigned long lru_pages);
16441647

16451648
#ifndef CONFIG_MMU
16461649
#define randomize_va_space 0

mm/memory-failure.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,9 @@ void shake_page(struct page *p, int access)
241241
do {
242242
struct shrink_control shrink = {
243243
.gfp_mask = GFP_KERNEL,
244-
.nr_scanned = 1000,
245244
};
246245

247-
nr = shrink_slab(&shrink, 1000);
246+
nr = shrink_slab(&shrink, 1000, 1000);
248247
if (page_count(p) == 1)
249248
break;
250249
} while (nr > 10);

0 commit comments

Comments
 (0)