Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 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.

[akpm@linux-foundation.org: add comment]
Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Dave Chinner <david@fromorbit.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Vladimir Davydov and committed by
Linus Torvalds
49e7e7ff 2acb60a0

+6 -3
+6 -3
fs/super.c
··· 91 91 /* 92 92 * prune the dcache first as the icache is pinned by it, then 93 93 * prune the icache, followed by the filesystem specific caches 94 + * 95 + * Ensure that we always scan at least one object - memcg kmem 96 + * accounting uses this to fully empty the caches. 94 97 */ 95 - sc->nr_to_scan = dentries; 98 + sc->nr_to_scan = dentries + 1; 96 99 freed = prune_dcache_sb(sb, sc); 97 - sc->nr_to_scan = inodes; 100 + sc->nr_to_scan = inodes + 1; 98 101 freed += prune_icache_sb(sb, sc); 99 102 100 103 if (fs_objects) { 101 - sc->nr_to_scan = fs_objects; 104 + sc->nr_to_scan = fs_objects + 1; 102 105 freed += sb->s_op->free_cached_objects(sb, sc); 103 106 } 104 107