Skip to content

Commit bf2b356

Browse files
author
Kent Overstreet
committed
bcachefs: Leave a buffer in the btree key cache to avoid lock thrashing
Signed-off-by: Kent Overstreet <[email protected]>
1 parent 2760bfe commit bf2b356

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

fs/bcachefs/btree_key_cache.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,14 @@ static unsigned long bch2_btree_key_cache_count(struct shrinker *shrink,
915915
long nr = atomic_long_read(&bc->nr_keys) -
916916
atomic_long_read(&bc->nr_dirty);
917917

918+
/*
919+
* Avoid hammering our shrinker too much if it's nearly empty - the
920+
* shrinker code doesn't take into account how big our cache is, if it's
921+
* mostly empty but the system is under memory pressure it causes nasty
922+
* lock contention:
923+
*/
924+
nr -= 128;
925+
918926
return max(0L, nr);
919927
}
920928

0 commit comments

Comments
 (0)