Re: [PATCH v3 1/4] 9p: Cache negative dentries for lookup performance

From: Christian Schoenebeck

Date: Wed Mar 04 2026 - 07:50:57 EST


On Friday, 27 February 2026 08:56:52 CET Remi Pommarel wrote:
> Not caching negative dentries can result in poor performance for
> workloads that repeatedly look up non-existent paths. Each such
> lookup triggers a full 9P transaction with the server, adding
> unnecessary overhead.
>
> A typical example is source compilation, where multiple cc1 processes
> are spawned and repeatedly search for the same missing header files
> over and over again.
>
> This change enables caching of negative dentries, so that lookups for
> known non-existent paths do not require a full 9P transaction. The
> cached negative dentries are retained for a configurable duration
> (expressed in milliseconds), as specified by the ndentry_timeout
> field in struct v9fs_session_info. If set to -1, negative dentries
> are cached indefinitely.
>
> This optimization reduces lookup overhead and improves performance for
> workloads involving frequent access to non-existent paths.
>
> Signed-off-by: Remi Pommarel <repk@xxxxxxxxxxxx>
> ---
> fs/9p/fid.c | 11 +++--
> fs/9p/v9fs.c | 1 +
> fs/9p/v9fs.h | 5 ++
> fs/9p/v9fs_vfs.h | 15 ++++++
> fs/9p/vfs_dentry.c | 105 ++++++++++++++++++++++++++++++++++------
> fs/9p/vfs_inode.c | 12 +++--
> fs/9p/vfs_super.c | 1 +
> include/net/9p/client.h | 2 +
> 8 files changed, 128 insertions(+), 24 deletions(-)
[...]
> diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h
> index 6a12445d3858..8410f7883109 100644
> --- a/fs/9p/v9fs.h
> +++ b/fs/9p/v9fs.h
> @@ -91,6 +91,7 @@ enum p9_cache_bits {
> * @debug: debug level
> * @afid: authentication handle
> * @cache: cache mode of type &p9_cache_bits
> + * @ndentry_timeout: Negative dentry lookup cache retention time in ms
> * @cachetag: the tag of the cache associated with this session
> * @fscache: session cookie associated with FS-Cache
> * @uname: string user name to mount hierarchy as
> @@ -101,6 +102,7 @@ enum p9_cache_bits {
> * @uid: if %V9FS_ACCESS_SINGLE, the numeric uid which mounted the
> hierarchy * @clnt: reference to 9P network client instantiated for this
> session * @slist: reference to list of registered 9p sessions
> + * @ndentry_timeout_ms: Negative dentry caching retention time
> *
> * This structure holds state for each session instance established during
> * a sys_mount() .
> @@ -116,6 +118,7 @@ struct v9fs_session_info {
> unsigned short debug;
> unsigned int afid;
> unsigned int cache;
> + unsigned int ndentry_timeout_ms;
> #ifdef CONFIG_9P_FSCACHE
> char *cachetag;
> struct fscache_volume *fscache;
> @@ -133,6 +136,8 @@ struct v9fs_session_info {
> long session_lock_timeout; /* retry interval for blocking locks */
> };
[...]
> diff --git a/include/net/9p/client.h b/include/net/9p/client.h
> index 838a94218b59..55c6cb54bd25 100644
> --- a/include/net/9p/client.h
> +++ b/include/net/9p/client.h
> @@ -192,6 +192,7 @@ struct p9_rdma_opts {
> * @dfltgid: default numeric groupid to mount hierarchy as
> * @uid: if %V9FS_ACCESS_SINGLE, the numeric uid which mounted the
> hierarchy * @session_lock_timeout: retry interval for blocking locks
> + * @ndentry_timeout_ms: Negative dentry lookup cache retention time in ms
> *
> * This strucure holds options which are parsed and will be transferred
> * to the v9fs_session_info structure when mounted, and therefore largely
> @@ -203,6 +204,7 @@ struct p9_session_opts {
> unsigned short debug;
> unsigned int afid;
> unsigned int cache;
> + unsigned int ndentry_timeout_ms;
> #ifdef CONFIG_9P_FSCACHE
> char *cachetag;
> #endif

Depending on what turns out to be chosen for the mount option eventually,
these types could be increased in size. But in general, LGTM:

Reviewed-by: Christian Schoenebeck <linux_oss@xxxxxxxxxxxxx>