Re: [REPOST PATCH v4 2/5] kernfs: use VFS negative dentry caching
From: Miklos Szeredi
Date: Thu Jun 03 2021 - 14:07:51 EST
On Thu, 3 Jun 2021 at 19:26, Eric W. Biederman <ebiederm@xxxxxxxxxxxx> wrote:
>
> Ian Kent <raven@xxxxxxxxxx> writes:
>
> > If there are many lookups for non-existent paths these negative lookups
> > can lead to a lot of overhead during path walks.
> >
> > The VFS allows dentries to be created as negative and hashed, and caches
> > them so they can be used to reduce the fairly high overhead alloc/free
> > cycle that occurs during these lookups.
> >
> > Signed-off-by: Ian Kent <raven@xxxxxxxxxx>
> > ---
> > fs/kernfs/dir.c | 55 +++++++++++++++++++++++++++++++++----------------------
> > 1 file changed, 33 insertions(+), 22 deletions(-)
> >
> > diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
> > index 4c69e2af82dac..5151c712f06f5 100644
> > --- a/fs/kernfs/dir.c
> > +++ b/fs/kernfs/dir.c
> > @@ -1037,12 +1037,33 @@ static int kernfs_dop_revalidate(struct dentry *dentry, unsigned int flags)
> > if (flags & LOOKUP_RCU)
> > return -ECHILD;
> >
> > - /* Always perform fresh lookup for negatives */
> > - if (d_really_is_negative(dentry))
> > - goto out_bad_unlocked;
> > + mutex_lock(&kernfs_mutex);
> >
> > kn = kernfs_dentry_node(dentry);
> > - mutex_lock(&kernfs_mutex);
>
> Why bring kernfs_dentry_node inside the mutex?
>
> The inode lock of the parent should protect negative to positive
> transitions not the kernfs_mutex. So moving the code inside
> the mutex looks unnecessary and confusing.
Except that d_revalidate() may or may not be called with parent lock held.
Thanks,
Miklos