[PATCH 2/2] fs/superblock: Avoid locking counting inodes anddentries before reclaiming them

From: Tim Chen
Date: Fri Sep 06 2013 - 14:24:36 EST


We remove the call to grab_super_passive in call to super_cache_count.
This becomes a scalability bottleneck as multiple threads are trying
to do memory reclamation, e.g. when we are doing large amount of
file read and page cache is under pressure. The cached objects
quickly got reclaimed down to 0 and we are aborting the cache_scan()
reclaim. But counting creates a log jam acquiring the sb_lock.

We are holding the shrinker_rwsem which ensures the safety of
call to list_lru_count_node() and s_op->nr_cached_objects. The
shrinker is unregistered now before ->kill_sb() so the operation is
safe when we are doing unmount.

Signed-off-by: Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>
---
fs/super.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/super.c b/fs/super.c
index b724f35..b5c9fdf 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -112,9 +112,14 @@ static unsigned long super_cache_count(struct shrinker *shrink,

sb = container_of(shrink, struct super_block, s_shrink);

- if (!grab_super_passive(sb))
- return 0;
-
+ /*
+ * Don't call grab_super_passive as it is a potential
+ * scalability bottleneck. The counts could get updated
+ * between super_cache_count and super_cache_scan anyway.
+ * Call to super_cache_count with shrinker_rwsem held
+ * ensures the safety of call to list_lru_count_node() and
+ * s_op->nr_cached_objects().
+ */
if (sb->s_op && sb->s_op->nr_cached_objects)
total_objects = sb->s_op->nr_cached_objects(sb,
sc->nid);
@@ -125,7 +130,6 @@ static unsigned long super_cache_count(struct shrinker *shrink,
sc->nid);

total_objects = vfs_pressure_ratio(total_objects);
- drop_super(sb);
return total_objects;
}

--
1.7.11.7


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/