Skip to content

Commit e566d48

Browse files
Andreas GruenbacherAl Viro
authored andcommitted
mbcache: fix shrinker function return value
The shrinker function is supposed to return the number of cache entries after shrinking, not before shrinking. Fix that. Based on a patch from Wang Sheng-Hui <crosslonelyover@gmail.com>. Signed-off-by: Andreas Gruenbacher <agruen@suse.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 2aec7c5 commit e566d48

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

‎fs/mbcache.c‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,35 +176,28 @@ static int
176176
mb_cache_shrink_fn(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
177177
{
178178
LIST_HEAD(free_list);
179-
struct list_head *l, *ltmp;
179+
struct mb_cache *cache;
180+
struct mb_cache_entry *entry, *tmp;
180181
int count = 0;
181182

182-
spin_lock(&mb_cache_spinlock);
183-
list_for_each(l, &mb_cache_list) {
184-
struct mb_cache *cache =
185-
list_entry(l, struct mb_cache, c_cache_list);
186-
mb_debug("cache %s (%d)", cache->c_name,
187-
atomic_read(&cache->c_entry_count));
188-
count += atomic_read(&cache->c_entry_count);
189-
}
190183
mb_debug("trying to free %d entries", nr_to_scan);
191-
if (nr_to_scan == 0) {
192-
spin_unlock(&mb_cache_spinlock);
193-
goto out;
194-
}
184+
spin_lock(&mb_cache_spinlock);
195185
while (nr_to_scan-- && !list_empty(&mb_cache_lru_list)) {
196186
struct mb_cache_entry *ce =
197187
list_entry(mb_cache_lru_list.next,
198188
struct mb_cache_entry, e_lru_list);
199189
list_move_tail(&ce->e_lru_list, &free_list);
200190
__mb_cache_entry_unhash(ce);
201191
}
192+
list_for_each_entry(cache, &mb_cache_list, c_cache_list) {
193+
mb_debug("cache %s (%d)", cache->c_name,
194+
atomic_read(&cache->c_entry_count));
195+
count += atomic_read(&cache->c_entry_count);
196+
}
202197
spin_unlock(&mb_cache_spinlock);
203-
list_for_each_safe(l, ltmp, &free_list) {
204-
__mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
205-
e_lru_list), gfp_mask);
198+
list_for_each_entry_safe(entry, tmp, &free_list, e_lru_list) {
199+
__mb_cache_entry_forget(entry, gfp_mask);
206200
}
207-
out:
208201
return (count / 100) * sysctl_vfs_cache_pressure;
209202
}
210203

0 commit comments

Comments
 (0)