Re: [PATCH v2 1/3] 9p: Cache negative dentries for lookup performance
From: Christian Schoenebeck
Date: Wed Feb 18 2026 - 07:46:53 EST
On Thursday, 12 February 2026 10:16:12 CET Remi Pommarel wrote:
> On Wed, Feb 11, 2026 at 04:49:19PM +0100, Christian Schoenebeck wrote:
> > On Wednesday, 21 January 2026 20:56:08 CET Remi Pommarel wrote:
[...]
> > > diff --git a/fs/9p/vfs_dentry.c b/fs/9p/vfs_dentry.c
> > > index c5bf74d547e8..90291cf0a34b 100644
> > > --- a/fs/9p/vfs_dentry.c
> > > +++ b/fs/9p/vfs_dentry.c
> > > @@ -23,6 +23,46 @@
> > >
> > > #include "v9fs_vfs.h"
> > > #include "fid.h"
> > >
> > > +/**
> > > + * v9fs_dentry_is_expired - Check if dentry lookup has expired
> > > + *
> > > + * This should be called to know if a negative dentry should be removed
> > > from + * cache.
> > > + *
> > > + * @dentry: dentry in question
> > > + *
> > > + */
> > > +static bool v9fs_dentry_is_expired(struct dentry const *dentry)
> > > +{
> > > + struct v9fs_session_info *v9ses = v9fs_dentry2v9ses(dentry);
> > > + struct v9fs_dentry *v9fs_dentry = to_v9fs_dentry(dentry);
> > > +
> > > + if (v9ses->ndentry_timeout == -1)
> > > + return false;
> > > +
> > > + return time_before_eq64(v9fs_dentry->expire_time, get_jiffies_64());
> > > +}
> >
> > v9fs_negative_dentry_is_expired() ?
> >
> > Or is there a plan to use this for regular dentries, say with cache=loose
> > in future?
>
> Yes I wanted to let the possibility for dentry cache expiration open,
> maybe this could be a nice thing to have ?
Fine either way, I leave it up to you.
> > > +
> > > +/**
> > > + * v9fs_dentry_refresh - Refresh dentry lookup cache timeout
> > > + *
> > > + * This should be called when a look up yields a negative entry.
> > > + *
> > > + * @dentry: dentry in question
> > > + *
> > > + */
> > > +void v9fs_dentry_refresh(struct dentry *dentry)
> > > +{
> > > + struct v9fs_session_info *v9ses = v9fs_dentry2v9ses(dentry);
> > > + struct v9fs_dentry *v9fs_dentry = to_v9fs_dentry(dentry);
> > > +
> > > + if (v9ses->ndentry_timeout == -1)
> > > + return;
> > > +
> > > + v9fs_dentry->expire_time = get_jiffies_64() +
> > > + msecs_to_jiffies(v9ses->ndentry_timeout);
> > > +}
> >
> > v9fs_negative_dentry_refresh_timeout() ?
Nevertheless I would rename this function to something that at least contains
"timeout" in its name, as v9fs_dentry_refresh() is somewhat too generic IMO.
> >
> > > +
> > >
> > > /**
> > >
> > > * v9fs_cached_dentry_delete - called when dentry refcount equals 0
> > > * @dentry: dentry in question
> > >
> > > @@ -33,20 +73,15 @@ static int v9fs_cached_dentry_delete(const struct
> > > dentry *dentry) p9_debug(P9_DEBUG_VFS, " dentry: %pd (%p)\n",
> > >
> > > dentry, dentry);
> > >
> > > - /* Don't cache negative dentries */
> > > - if (d_really_is_negative(dentry))
> > > - return 1;
> > > - return 0;
> > > -}
> > > + if (!d_really_is_negative(dentry))
> > > + return 0;
> >
> > Is it worth a check for v9ses->ndentry_timeout != 0 here?
>
> The check will be done in v9fs_dentry_is_expired() not sure this is
> worth the optimization here ?
Right, that's OK.
Overall I think it makes sense to bring this series forward. The improvement
is really impressive.
Thanks!
/Christian