Skip to content

Commit 1a554ec

Browse files
Qi Zhengakpm00
authored andcommitted
Revert "mm: shrinkers: make count and scan in shrinker debugfs lockless"
This reverts commit 20cd189. Kernel test robot reports -88.8% regression in stress-ng.ramfs.ops_per_sec test case [1], which is caused by commit f95bdb7 ("mm: vmscan: make global slab shrink lockless"). The root cause is that SRCU has to be careful to not frequently check for SRCU read-side critical section exits. Therefore, even if no one is currently in the SRCU read-side critical section, synchronize_srcu() cannot return quickly. That's why unregister_shrinker() has become slower. We will try to use the refcount+RCU method [2] proposed by Dave Chinner to continue to re-implement the lockless slab shrink. So revert the shrinker_srcu related changes first. [1]. https://lore.kernel.org/lkml/[email protected]/ [2]. https://lore.kernel.org/lkml/[email protected]/ Link: https://lkml.kernel.org/r/[email protected] Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-lkp/[email protected] Signed-off-by: Qi Zheng <[email protected]> Cc: Dave Chinner <[email protected]> Cc: Kirill Tkhai <[email protected]> Cc: Muchun Song <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c534f7c commit 1a554ec

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

mm/shrinker_debug.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
#include <linux/seq_file.h>
66
#include <linux/shrinker.h>
77
#include <linux/memcontrol.h>
8-
#include <linux/srcu.h>
98

109
/* defined in vmscan.c */
1110
extern struct rw_semaphore shrinker_rwsem;
1211
extern struct list_head shrinker_list;
13-
extern struct srcu_struct shrinker_srcu;
1412

1513
static DEFINE_IDA(shrinker_debugfs_ida);
1614
static struct dentry *shrinker_debugfs_root;
@@ -51,13 +49,18 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v)
5149
struct mem_cgroup *memcg;
5250
unsigned long total;
5351
bool memcg_aware;
54-
int ret = 0, nid, srcu_idx;
52+
int ret, nid;
5553

5654
count_per_node = kcalloc(nr_node_ids, sizeof(unsigned long), GFP_KERNEL);
5755
if (!count_per_node)
5856
return -ENOMEM;
5957

60-
srcu_idx = srcu_read_lock(&shrinker_srcu);
58+
ret = down_read_killable(&shrinker_rwsem);
59+
if (ret) {
60+
kfree(count_per_node);
61+
return ret;
62+
}
63+
rcu_read_lock();
6164

6265
memcg_aware = shrinker->flags & SHRINKER_MEMCG_AWARE;
6366

@@ -88,7 +91,8 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v)
8891
}
8992
} while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL);
9093

91-
srcu_read_unlock(&shrinker_srcu, srcu_idx);
94+
rcu_read_unlock();
95+
up_read(&shrinker_rwsem);
9296

9397
kfree(count_per_node);
9498
return ret;
@@ -111,8 +115,9 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file,
111115
.gfp_mask = GFP_KERNEL,
112116
};
113117
struct mem_cgroup *memcg = NULL;
114-
int nid, srcu_idx;
118+
int nid;
115119
char kbuf[72];
120+
ssize_t ret;
116121

117122
read_len = size < (sizeof(kbuf) - 1) ? size : (sizeof(kbuf) - 1);
118123
if (copy_from_user(kbuf, buf, read_len))
@@ -141,7 +146,11 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file,
141146
return -EINVAL;
142147
}
143148

144-
srcu_idx = srcu_read_lock(&shrinker_srcu);
149+
ret = down_read_killable(&shrinker_rwsem);
150+
if (ret) {
151+
mem_cgroup_put(memcg);
152+
return ret;
153+
}
145154

146155
sc.nid = nid;
147156
sc.memcg = memcg;
@@ -150,7 +159,7 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file,
150159

151160
shrinker->scan_objects(shrinker, &sc);
152161

153-
srcu_read_unlock(&shrinker_srcu, srcu_idx);
162+
up_read(&shrinker_rwsem);
154163
mem_cgroup_put(memcg);
155164

156165
return size;

0 commit comments

Comments
 (0)