On Wed, Jul 03, 2024 at 08:13:01AM -0400, Brian Foster wrote: > The nr_dentry_negative counter is intended to only account negative > dentries that are present on the superblock LRU. Therefore, the LRU > add, remove and isolate helpers modify the counter based on whether > the dentry is negative, but the shrinker list related helpers do not > modify the counter, and the paths that change a dentry between > positive and negative only do so if DCACHE_LRU_LIST is set. > > The problem with this is that a dentry on a shrinker list still has > DCACHE_LRU_LIST set to indicate ->d_lru is in use. The additional > DCACHE_SHRINK_LIST flag denotes whether the dentry is on LRU or a > shrink related list. Therefore if a relevant operation (i.e. unlink) > occurs while a dentry is present on a shrinker list, and the > associated codepath only checks for DCACHE_LRU_LIST, then it is > technically possible to modify the negative dentry count for a > dentry that is off the LRU. Since the shrinker list related helpers > do not modify the negative dentry count (because non-LRU dentries > should not be included in the count) when the dentry is ultimately > removed from the shrinker list, this can cause the negative dentry > count to become permanently inaccurate. > > This problem can be reproduced via a heavy file create/unlink vs. > drop_caches workload. On an 80xcpu system, I start 80 tasks each > running a 1k file create/delete loop, and one task spinning on > drop_caches. After 10 minutes or so of runtime, the idle/clean cache > negative dentry count increases from somewhere in the range of 5-10 > entries to several hundred (and increasingly grows beyond > nr_dentry_unused). > > Tweak the logic in the paths that turn a dentry negative or positive > to filter out the case where the dentry is present on a shrink > related list. This allows the above workload to maintain an accurate > negative dentry count. > > Fixes: af0c9af1b3f6 ("fs/dcache: Track & report number of negative dentries") > Signed-off-by: Brian Foster <bfoster@xxxxxxxxxx> > Acked-by: Ian Kent <ikent@xxxxxxxxxx> > --- > > Hi Christian, > > I see you already picked up v1. Josef had asked for some comment updates > so I'm posting v2 with that, but TBH I'm not sure how useful this all is > once one groks the flags. I have no strong opinion on it. I also added a > Fixes: tag for the patch that added the counter. > > In short, feel free to grab this one, ignore this and stick with v1, or > maybe just pull in the Fixes: tag if you agree with it. Thanks. > > Brian > > v2: > - Update comments (Josef). > - Add Fixes: tag, cc Waiman. > v1: https://lore.kernel.org/linux-fsdevel/20240702170757.232130-1-bfoster@xxxxxxxxxx/ Reviewed-by: Josef Bacik <josef@xxxxxxxxxxxxxx> Thanks! Josef