[PATCH v2 3/3] fs: Use delayed shrinker unregistration

From: Kirill Tkhai
Date: Mon Jun 05 2023 - 15:03:57 EST


Kernel test robot reports -88.8% regression in stress-ng.ramfs.ops_per_sec
test case caused by commit: f95bdb700bc6 ("mm: vmscan: make global slab
shrink lockless"). Qi Zheng investigated that the reason is in long SRCU's
synchronize_srcu() occuring in unregister_shrinker().

This patch fixes the problem by using new unregistration interfaces,
which split unregister_shrinker() in two parts. First part actually only
notifies shrinker subsystem about the fact of unregistration and it prevents
future shrinker methods calls. The second part completes the unregistration
and it insures, that struct shrinker is not used during shrinker chain
iteration anymore, so shrinker memory may be freed. Since the long second
part is called from delayed work asynchronously, it hides synchronize_srcu()
delay from a user.

Signed-off-by: Kirill Tkhai <tkhai@xxxxx>
---
fs/super.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/super.c b/fs/super.c
index 8d8d68799b34..f3e4f205ec79 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -159,6 +159,7 @@ static void destroy_super_work(struct work_struct *work)
destroy_work);
int i;

+ unregister_shrinker_delayed_finalize(&s->s_shrink);
for (i = 0; i < SB_FREEZE_LEVELS; i++)
percpu_free_rwsem(&s->s_writers.rw_sem[i]);
kfree(s);
@@ -327,7 +328,7 @@ void deactivate_locked_super(struct super_block *s)
{
struct file_system_type *fs = s->s_type;
if (atomic_dec_and_test(&s->s_active)) {
- unregister_shrinker(&s->s_shrink);
+ unregister_shrinker_delayed_initiate(&s->s_shrink);
fs->kill_sb(s);

/*