Skip to contentSkip to conversation

fs/superblock: Unregister sb shrinker before ->kill_sb()

PATCH New Tim Chen 1 participant 1 message Sep 6, 2013 VFS

lore
Share & tools
lore

Tim Chen

author
#0 lore raw

PATCH 1/2 fs/superblock: Unregister sb shrinker before ->kill_sb()

Dave,

I've created the two patches we've discussed on the mail thread regarding avoiding grab_super_passive during memory reclaim.

Tim

From: Dave Chinner <[email protected]>
We will like to unregister the sb shrinker before ->kill_sb(). This will allow cached objects to be counted without call to grab_super_passive() to update ref count on sb. We want to avoid locking during memory reclamation especially when we are skipping the memory reclaim when we are out of cached objects.

This is safe because grab_super_passive does a try-lock on the sb->s_umount now, and so if we are in the unmount process, it won't ever block. That means what used to be a deadlock and races we were avoiding by using grab_super_passive() is now:

        shrinker                        umount

        down_read(shrinker_rwsem)
                                        down_write(sb->s_umount)
                                        shrinker_unregister
                                          down_write(shrinker_rwsem)
                                            <blocks>
        grab_super_passive(sb)
          down_read_trylock(sb->s_umount)
            <fails>
        <shrinker aborts>
        ....
        <shrinkers finish running>
        up_read(shrinker_rwsem)
                                          <unblocks>
                                          <removes shrinker>
                                          up_write(shrinker_rwsem)
                                        ->kill_sb()
                                        ....

So it is safe to deregister the shrinker before ->kill_sb().

---
 fs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/super.c +1 -1
index 73d0952..b724f35 100644
@@ -324,10 +324,10 @@ void deactivate_locked_super(struct super_block *s)
 	struct file_system_type *fs = s->s_type;
 	if (atomic_dec_and_test(&s->s_active)) {
 		cleancache_invalidate_fs(s);
+		unregister_shrinker(&s->s_shrink);
 		fs->kill_sb(s);
 
 		/* caches are now gone, we can safely kill the shrinker now */
-		unregister_shrinker(&s->s_shrink);
 		list_lru_destroy(&s->s_dentry_lru);
 		list_lru_destroy(&s->s_inode_lru);
 
Signature · 1 line
1.7.11.7