Skip to content

RFC dcache: increase poison resistance

Konstantin Khlebnikov linux-fsdevel linux-mm lkml 1 version In review

Get series with b4
b4 am 158893941613.200862.4094521350329937435.stgit@buzz

Versions newest first

  1. v1 RFC Latest8 patches 18 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8dcache: show count of hash buckets in sysctl fs.dentry-stateDocumentation/admin-guide/sysctl/fs.rst fs/dcache.c include/linux/dcache.h+17 -96 replies
2/8selftests: add stress testing tool for dcachetools/testing/selftests/filesystems/Makefile tools/testing/selftests/filesystems/dcache_stress.c+211 -01 reply
3/8dcache: sweep cached negative dentries to the end of list of siblingsfs/dcache.c include/linux/dcache.h+66 -31 reply
4/8fsnotify: stop walking child dentries if remaining tail is negativefs/notify/fsnotify.c+5 -10 replies
5/8dcache: add action D_WALK_SKIP_SIBLINGS to d_walk()fs/dcache.c+7 -00 replies
6/8dcache: stop walking siblings if remaining dentries all negativefs/dcache.c fs/libfs.c+19 -10 replies
7/8dcache: push releasing dentry lock into sweep_negativefs/dcache.c+9 -30 replies
8/8dcache: prevent flooding with negative dentriesfs/dcache.c+54 -03 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH RFC 0/8] dcache: increase poison resistance

For most filesystems result of every negative lookup is cached, content of directories is usually cached too. Production of negative dentries isn't limited with disk speed. It's really easy to generate millions of them if system has enough memory.

Getting this memory back ins't that easy because slab frees pages only when all related objects are gone. While dcache shrinker works in LRU order.

Typical scenario is an idle system where some process periodically creates temporary files and removes them. After some time, memory will be filled with negative dentries for these random file names.

Simple lookup of random names also generates negative dentries very fast. Constant flow of such negative denries drains all other inactive caches.

Negative dentries are linked into siblings list along with normal positive dentries. Some operations walks dcache tree but looks only for positive
dentries: most important is fsnotify/inotify. Hordes of negative dentries slow down these operations significantly.

Time of dentry lookup is usually unaffected because hash table grows along with size of memory. Unless somebody especially crafts hash collisions.

This patch set solves all of these problems:

Move negative denries to the end of sliblings list, thus walkers could skip them at first sight (patches 3-6).

Keep in dcache at most three unreferenced negative denties in row in each hash bucket (patches 7-8).

---

Konstantin Khlebnikov (8):
dcache: show count of hash buckets in sysctl fs.dentry-state
selftests: add stress testing tool for dcache
dcache: sweep cached negative dentries to the end of list of siblings
fsnotify: stop walking child dentries if remaining tail is negative
dcache: add action D_WALK_SKIP_SIBLINGS to d_walk()
dcache: stop walking siblings if remaining dentries all negative
dcache: push releasing dentry lock into sweep_negative
dcache: prevent flooding with negative dentries

 fs/dcache.c                                   | 144 +++++++++++-
 fs/libfs.c                                    |  10 +-
 fs/notify/fsnotify.c                          |   6 +-
 include/linux/dcache.h                        |   6 +
 tools/testing/selftests/filesystems/Makefile  |   1 +
 .../selftests/filesystems/dcache_stress.c     | 210 ++++++++++++++++++
 6 files changed, 370 insertions(+), 7 deletions(-)
 create mode 100644 tools/testing/selftests/filesystems/dcache_stress.c

--
Signature