Skip to contentSkip to conversation

fs: shrinker: always scan at least one object of each type

PATCH In review Vladimir Davydov 2 participants 3 messages Jan 12, 2015 – Jan 14, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: shrinker: always scan at least one object of each type

In super_cache_scan() we divide the number of objects of particular type by the total number of objects in order to distribute pressure among different types of fs objects (inodes, dentries, fs-private objects). As a result, in some corner cases we can get nr_to_scan=0 even if there are some objects to reclaim, e.g. dentries=1, inodes=1, fs_objects=1, nr_to_scan=1/3=0.

This is unacceptable for per memcg kmem accounting, because this means that some objects may never get reclaimed after memcg death, preventing it from being freed.

This patch therefore assures that super_cache_scan() will scan at least one object of each type if any.

---
 fs/super.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/super.c +3 -3
index 482b4071f4de..63136156867e 100644
@@ -92,13 +92,13 @@ static unsigned long super_cache_scan(struct shrinker *shrink,
 	 * prune the dcache first as the icache is pinned by it, then
 	 * prune the icache, followed by the filesystem specific caches
 	 */
-	sc->nr_to_scan = dentries;
+	sc->nr_to_scan = dentries + 1;
 	freed = prune_dcache_sb(sb, sc);
-	sc->nr_to_scan = inodes;
+	sc->nr_to_scan = inodes + 1;
 	freed += prune_icache_sb(sb, sc);
 
 	if (fs_objects) {
-		sc->nr_to_scan = fs_objects;
+		sc->nr_to_scan = fs_objects + 1;
 		freed += sb->s_op->free_cached_objects(sb, sc);
 	}
 
Signature · 7 lines
1.7.10.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#1 lore raw
Quoted 22 lines · On Mon, 12 Jan 2015 13:20:46 +0300 Vladimir Davydov <[email protected]>…

In super_cache_scan() we divide the number of objects of particular type by the total number of objects in order to distribute pressure among different types of fs objects (inodes, dentries, fs-private objects). As a result, in some corner cases we can get nr_to_scan=0 even if there are some objects to reclaim, e.g. dentries=1, inodes=1, fs_objects=1, nr_to_scan=1/3=0.

This is unacceptable for per memcg kmem accounting, because this means that some objects may never get reclaimed after memcg death, preventing it from being freed.

This patch therefore assures that super_cache_scan() will scan at least one object of each type if any.

fs/super.c +1 -1
@@ -92,13 +92,13 @@ static unsigned long super_cache_scan(struct shrinker *shrink,
 	 * prune the dcache first as the icache is pinned by it, then
 	 * prune the icache, followed by the filesystem specific caches
 	 */
-	sc->nr_to_scan = dentries;
+	sc->nr_to_scan = dentries + 1;

fs/super.c static unsigned long super_cache_scan(struct shrinker *shrink, · line 103

Quoted 10 lines
fs/super.c +2 -2
 	freed = prune_dcache_sb(sb, sc);
-	sc->nr_to_scan = inodes;
+	sc->nr_to_scan = inodes + 1;
 	freed += prune_icache_sb(sb, sc);
 
 	if (fs_objects) {
-		sc->nr_to_scan = fs_objects;
+		sc->nr_to_scan = fs_objects + 1;
 		freed += sb->s_op->free_cached_objects(sb, sc);
 	}

A reader of this code will wonder "why is it adding 1 everywhere". Let's tell them?

fs/super.c renamed from fs/super.c~fs-shrinker-always-scan-at-least-one-object-of-each-type-fix +3 -0
@@ -91,6 +91,9 @@ static unsigned long super_cache_scan(st
 	/*
 	 * prune the dcache first as the icache is pinned by it, then
 	 * prune the icache, followed by the filesystem specific caches
+	 *
+	 * Ensure that we always scan at least one object - memcg kmem
+	 * accounting uses this to fully empty the caches.
 	 */
 	sc->nr_to_scan = dentries + 1;
 	freed = prune_dcache_sb(sb, sc);

_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 29 lines · Andrew Morton
Quoted 27 lines · On Mon, 12 Jan 2015 13:20:46 +0300 Vladimir Davydov <[email protected]>…

In super_cache_scan() we divide the number of objects of particular type by the total number of objects in order to distribute pressure among different types of fs objects (inodes, dentries, fs-private objects). As a result, in some corner cases we can get nr_to_scan=0 even if there are some objects to reclaim, e.g. dentries=1, inodes=1, fs_objects=1, nr_to_scan=1/3=0.

This is unacceptable for per memcg kmem accounting, because this means that some objects may never get reclaimed after memcg death, preventing it from being freed.

This patch therefore assures that super_cache_scan() will scan at least one object of each type if any.

fs/super.c +2 -2
@@ -92,13 +92,13 @@ static unsigned long super_cache_scan(struct shrinker *shrink,
 	 * prune the dcache first as the icache is pinned by it, then
 	 * prune the icache, followed by the filesystem specific caches
 	 */
-	sc->nr_to_scan = dentries;
+	sc->nr_to_scan = dentries + 1;
 	freed = prune_dcache_sb(sb, sc);
-	sc->nr_to_scan = inodes;
+	sc->nr_to_scan = inodes + 1;
 	freed += prune_icache_sb(sb, sc);
 
Quoted 8 lines

fs/super.c static unsigned long super_cache_scan(struct shrinker *shrink, · line 103

Quoted 5 lines
fs/super.c +1 -1
 	if (fs_objects) {
-		sc->nr_to_scan = fs_objects;
+		sc->nr_to_scan = fs_objects + 1;
 		freed += sb->s_op->free_cached_objects(sb, sc);
 	}

A reader of this code will wonder "why is it adding 1 everywhere". Let's tell them?

Yeah, sounds reasonable. Thank you!

Quoted 13 lines
fs/super.c renamed from fs/super.c~fs-shrinker-always-scan-at-least-one-object-of-each-type-fix +3 -0
@@ -91,6 +91,9 @@ static unsigned long super_cache_scan(st
 	/*
 	 * prune the dcache first as the icache is pinned by it, then
 	 * prune the icache, followed by the filesystem specific caches
+	 *
+	 * Ensure that we always scan at least one object - memcg kmem
+	 * accounting uses this to fully empty the caches.
 	 */
 	sc->nr_to_scan = dentries + 1;
 	freed = prune_dcache_sb(sb, sc);
Quoted 2 lines

_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>