Re: [PATCH 1/4] fs/dcache: Limit numbers of negative dentries

From: Matthew Wilcox
Date: Mon Jul 17 2017 - 13:49:49 EST


On Mon, Jul 17, 2017 at 09:39:30AM -0400, Waiman Long wrote:
> The number of positive dentries is limited by the number of files
> in the filesystems. The number of negative dentries, however,
> has no limit other than the total amount of memory available in
> the system. So a rogue application that generates a lot of negative
> dentries can potentially exhaust most of the memory available in the
> system impacting performance on other running applications.
>
> To prevent this from happening, the dcache code is now updated to limit
> the amount of the negative dentries in the LRU lists that can be kept
> as a percentage of total available system memory. The default is 5%
> and can be changed by specifying the "neg_dentry_pc=" kernel command
> line option.

I see the problem, but rather than restricting the number of negative
dentries to be a fraction of the total amount of memory in the machine,
wouldn't it make more sense to limit the number of negative dentries to be
some multiple of the number of positive dentries currently in the system?

Or make negative dentries more easily prunable. For example, we could
allocate them from a separate slab and use the existing reclaim mechanism
to just throw them away. Since they can't be pinned by an inode, they're
much easier to get rid of than positive dentries. Might make changing
a dentry from positive to negative or vice versa a bit more expensive ...