Skip to contentSkip to conversation

9p: Performance improvements for build workloads

PATCH Superseded Remi Pommarel 3 participants 14 messages Feb 27 – Mar 4

Subsystems (3)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover 9p: Performance improvements for build workloads

This patchset introduces several performance optimizations for the 9p filesystem when used with cache=loose option (exclusive or read only mounts). These improvements particularly target workloads with frequent lookups of non-existent paths and repeated symlink resolutions.

The very state of the art benchmark consisting of cloning a fresh hostap repository and building hostapd and wpa_supplicant for hwsim tests (cd tests/hwsim; time ./build.sh) in a VM running on a 9pfs rootfs (with trans=virtio,cache=loose options) has been used to test those optimizations impact.

For reference, the build takes 0m56.492s on my laptop natively while it completes in 2m18.702sec on the VM. This represents a significant performance penalty considering running the same build on a VM using a virtiofs rootfs (with "--cache always" virtiofsd option) takes around 1m32.141s. This patchset aims to bring the 9pfs build time close to that of virtiofs, rather than the native host time, as a realistic expectation.

This first three patches in this series focus on keeping negative dentries in the cache, ensuring that subsequent lookups for paths known to not exist do not require redundant 9P RPC calls. This optimization reduces the time needed for the compiler to search for header files across known locations. The two first patches introduce a new mount option, ndentrycache, which specifies the number of ms to keep the dentry in the cache. Using ndentrycache without value (i.e. keeping the negative dentry indifinetly) shrunk build time to 1m46.198s. The third patch enable the negative dentry caching for 24 hours by default on cache=loose.

The fourth patch extends page cache usage to symlinks by allowing p9_client_readlink() results to be cached. Resolving symlink is apparently something done quite frequently during the build process and avoiding the cost of a 9P RPC call round trip for already known symlinks helps reduce the build time to 1m26.602s, outperforming the virtiofs setup.

Here is summary of the different hostapd/wpa_supplicant build times:

- Baseline (no patch): 2m18.702s
- negative dentry caching (patches 1-3): 1m46.198s (23% improvement)
- Above + symlink caching (patches 1-4): 1m26.302s (an additional 18% improvement, 37% in total)

With this ~37% performance gain, 9pfs with cache=loose can compete with virtiofs for (at least) this specific scenario. Although this benchmark is not the most typical, I do think that these caching optimizations could benefit a wide range of other workflows as well.

Changes since v2:
- Rename v9fs_dentry_is_{expired,refresh} to ndentry
- Some grammatical fixes in couple of comments
- Rename the negative cache mount option to ndentrycache. Using ndentrycache without value enable infinite caching while ndentrycache=<time> enable caching for <time> milliseconds. This allows the option to be unsigned.
- Make it more obvious v9fs_issue_read() is only called on dotl symlinks

Changes since v1:
- Rebase on 9p-next (with new mount API conversion)
- Integrated symlink caching with the network filesystem helper library for robustness (a lot of code expects a valid netfs context)
- Instantiate symlink dentry at creation to avoid keeping a negative dentry in cache
- Moved IO waiting time accounting to a separate patch series

Thanks.

Remi Pommarel (4):
9p: Cache negative dentries for lookup performance 9p: Add mount option for negative dentry cache retention 9p: Set default negative dentry retention time for cache=loose 9p: Enable symlink caching in page cache

 fs/9p/fid.c             |  11 +++--
 fs/9p/v9fs.c            |  84 +++++++++++++++++++++-----------
 fs/9p/v9fs.h            |  28 +++++++----
 fs/9p/v9fs_vfs.h        |  15 ++++++
 fs/9p/vfs_addr.c        |  29 +++++++++--
 fs/9p/vfs_dentry.c      | 105 ++++++++++++++++++++++++++++++++++------
 fs/9p/vfs_inode.c       |  18 ++++---
 fs/9p/vfs_inode_dotl.c  |  72 ++++++++++++++++++++++++---
 fs/9p/vfs_super.c       |   1 +
 include/net/9p/client.h |   2 +
 10 files changed, 290 insertions(+), 75 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

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

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.

---
 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(-)
fs/9p/fid.c +6 -5
index f84412290a30..76242d450aa7 100644
@@ -20,7 +20,9 @@
 
 static inline void __add_fid(struct dentry *dentry, struct p9_fid *fid)
 {
-	hlist_add_head(&fid->dlist, (struct hlist_head *)&dentry->d_fsdata);
+	struct v9fs_dentry *v9fs_dentry = to_v9fs_dentry(dentry);
+
+	hlist_add_head(&fid->dlist, &v9fs_dentry->head);
 }
 
 
@@ -112,6 +114,7 @@ void v9fs_open_fid_add(struct inode *inode, struct p9_fid **pfid)
 
 static struct p9_fid *v9fs_fid_find(struct dentry *dentry, kuid_t uid, int any)
 {
+	struct v9fs_dentry *v9fs_dentry = to_v9fs_dentry(dentry);
 	struct p9_fid *fid, *ret;
 
 	p9_debug(P9_DEBUG_VFS, " dentry: %pd (%p) uid %d any %d\n",
@@ -119,11 +122,9 @@ static struct p9_fid *v9fs_fid_find(struct dentry *dentry, kuid_t uid, int any)
 		 any);
 	ret = NULL;
 	/* we'll recheck under lock if there's anything to look in */
-	if (dentry->d_fsdata) {
-		struct hlist_head *h = (struct hlist_head *)&dentry->d_fsdata;
-
+	if (!hlist_empty(&v9fs_dentry->head)) {
 		spin_lock(&dentry->d_lock);
-		hlist_for_each_entry(fid, h, dlist) {
+		hlist_for_each_entry(fid, &v9fs_dentry->head, dlist) {
 			if (any || uid_eq(fid->uid, uid)) {
 				ret = fid;
 				p9_fid_get(ret);
fs/9p/v9fs.c +1 -0
index 057487efaaeb..c5dca81a553e 100644
@@ -422,6 +422,7 @@ static void v9fs_apply_options(struct v9fs_session_info *v9ses,
 	v9ses->cache = ctx->session_opts.cache;
 	v9ses->uid = ctx->session_opts.uid;
 	v9ses->session_lock_timeout = ctx->session_opts.session_lock_timeout;
+	v9ses->ndentry_timeout_ms = ctx->session_opts.ndentry_timeout_ms;
 }
 
 /**
fs/9p/v9fs.h +5 -0
index 6a12445d3858..8410f7883109 100644
@@ -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 */
 };
 
+#define NDENTRY_TMOUT_NEVER (-1U)
+
 /* cache_validity flags */
 #define V9FS_INO_INVALID_ATTR 0x01
 
fs/9p/v9fs_vfs.h +15 -0
index d3aefbec4de6..83c2335f438d 100644
@@ -28,6 +28,19 @@
 /* flags for v9fs_stat2inode() & v9fs_stat2inode_dotl() */
 #define V9FS_STAT2INODE_KEEP_ISIZE 1
 
+/**
+ * struct v9fs_dentry - v9fs specific dentry data
+ * @head: List of fid associated with this dentry
+ * @expire_time: Lookup cache expiration time for negative dentries
+ * @rcu: used by kfree_rcu to schedule clean up job
+ */
+struct v9fs_dentry {
+	struct hlist_head head;
+	u64 expire_time;
+	struct rcu_head rcu;
+};
+#define to_v9fs_dentry(d) ((struct v9fs_dentry *)((d)->d_fsdata))
+
 extern struct file_system_type v9fs_fs_type;
 extern const struct address_space_operations v9fs_addr_operations;
 extern const struct file_operations v9fs_file_operations;
@@ -35,6 +48,8 @@ extern const struct file_operations v9fs_file_operations_dotl;
 extern const struct file_operations v9fs_dir_operations;
 extern const struct file_operations v9fs_dir_operations_dotl;
 extern const struct dentry_operations v9fs_dentry_operations;
+extern void v9fs_ndentry_refresh_timeout(struct dentry *dentry);
+extern void v9fs_dentry_fid_remove(struct dentry *dentry);
 extern const struct dentry_operations v9fs_cached_dentry_operations;
 extern struct kmem_cache *v9fs_inode_cache;
 
fs/9p/vfs_dentry.c +91 -14

156 lines not on this page · raw message

fs/9p/vfs_inode.c +7 -5
index 97abe65bf7c1..c82db6fe0c39 100644
@@ -549,7 +549,7 @@ static int v9fs_remove(struct inode *dir, struct dentry *dentry, int flags)
 
 		/* invalidate all fids associated with dentry */
 		/* NOTE: This will not include open fids */
-		dentry->d_op->d_release(dentry);
+		v9fs_dentry_fid_remove(dentry);
 	}
 	return retval;
 }
@@ -732,14 +732,16 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
 	name = dentry->d_name.name;
 	fid = p9_client_walk(dfid, 1, &name, 1);
 	p9_fid_put(dfid);
-	if (fid == ERR_PTR(-ENOENT))
+	if (fid == ERR_PTR(-ENOENT)) {
 		inode = NULL;
-	else if (IS_ERR(fid))
+		v9fs_ndentry_refresh_timeout(dentry);
+	} else if (IS_ERR(fid)) {
 		inode = ERR_CAST(fid);
-	else if (v9ses->cache & (CACHE_META|CACHE_LOOSE))
+	} else if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) {
 		inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
-	else
+	} else {
 		inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
+	}
 	/*
 	 * If we had a rename on the server and a parallel lookup
 	 * for the new name, then make sure we instantiate with
fs/9p/vfs_super.c +1 -0
index 0a1c4f7cb001..3b2a906528cd 100644
@@ -327,6 +327,7 @@ static int v9fs_init_fs_context(struct fs_context *fc)
 	ctx->session_opts.uid = INVALID_UID;
 	ctx->session_opts.dfltuid = V9FS_DEFUID;
 	ctx->session_opts.dfltgid = V9FS_DEFGID;
+	ctx->session_opts.ndentry_timeout_ms = 0;
 
 	/* initialize client options */
 	ctx->client_opts.proto_version = p9_proto_2000L;
include/net/9p/client.h +2 -0
index 838a94218b59..55c6cb54bd25 100644
@@ -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
Signature · 1 line
2.52.0
#10 lore raw

PATCH v3 3/4 9p: Set default negative dentry retention time for cache=loose

In reply to Remi Pommarel

For cache=loose mounts, set the default negative dentry cache retention time to 24 hours.

---
 fs/9p/v9fs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
fs/9p/v9fs.c +10 -0
index a26bd9070786..d14f6eda94d6 100644
@@ -24,6 +24,9 @@
 #include "v9fs_vfs.h"
 #include "cache.h"
 
+/* cache=loose default negative dentry retention time is 24hours */
+#define CACHE_LOOSE_NDENTRY_TMOUT_DEFAULT (24 * 60 * 60 * 1000)
+
 static DEFINE_SPINLOCK(v9fs_sessionlist_lock);
 static LIST_HEAD(v9fs_sessionlist);
 struct kmem_cache *v9fs_inode_cache;
@@ -440,6 +443,13 @@ static void v9fs_apply_options(struct v9fs_session_info *v9ses,
 	v9ses->uid = ctx->session_opts.uid;
 	v9ses->session_lock_timeout = ctx->session_opts.session_lock_timeout;
 	v9ses->ndentry_timeout_ms = ctx->session_opts.ndentry_timeout_ms;
+
+	/* If negative dentry timeout has not been overriden set default for
+	 * cache=loose
+	 */
+	if (!(v9ses->flags & V9FS_NDENTRY_TMOUT_SET) &&
+	    (v9ses->cache & CACHE_LOOSE))
+		v9ses->ndentry_timeout_ms = CACHE_LOOSE_NDENTRY_TMOUT_DEFAULT;
 }
 
 /**
Signature · 1 line
2.52.0
#12 lore raw

PATCH v3 4/4 9p: Enable symlink caching in page cache

In reply to Remi Pommarel

Currently, when cache=loose is enabled, file reads are cached in the page cache, but symlink reads are not. This patch allows the results of p9_client_readlink() to be stored in the page cache, eliminating the need for repeated 9P transactions on subsequent symlink accesses.

This change improves performance for workloads that involve frequent symlink resolution.

---
 fs/9p/vfs_addr.c       | 29 +++++++++++++++--
 fs/9p/vfs_inode.c      |  6 ++--
 fs/9p/vfs_inode_dotl.c | 72 +++++++++++++++++++++++++++++++++++++-----
 3 files changed, 94 insertions(+), 13 deletions(-)
fs/9p/vfs_addr.c +26 -3
index 862164181bac..0683090a5f15 100644
@@ -70,10 +70,24 @@ static void v9fs_issue_read(struct netfs_io_subrequest *subreq)
 {
 	struct netfs_io_request *rreq = subreq->rreq;
 	struct p9_fid *fid = rreq->netfs_priv;
+	char *target;
 	unsigned long long pos = subreq->start + subreq->transferred;
-	int total, err;
-
-	total = p9_client_read(fid, pos, &subreq->io_iter, &err);
+	int total, err, len, n;
+
+	if (S_ISLNK(rreq->inode->i_mode)) {
+		/* p9_client_readlink() must not be called for legacy protocols
+		 * 9p2000 or 9p2000.u.
+		 */
+		BUG_ON(!p9_is_proto_dotl(fid->clnt));
+		err = p9_client_readlink(fid, &target);
+		len = strnlen(target, PAGE_SIZE - 1);
+		n = copy_to_iter(target, len, &subreq->io_iter);
+		if (n != len)
+			err = -EFAULT;
+		total = i_size_read(rreq->inode);
+	} else {
+		total = p9_client_read(fid, pos, &subreq->io_iter, &err);
+	}
 
 	/* if we just extended the file size, any portion not in
 	 * cache won't be on server and is zeroes */
@@ -99,6 +113,7 @@ static void v9fs_issue_read(struct netfs_io_subrequest *subreq)
 static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file)
 {
 	struct p9_fid *fid;
+	struct dentry *dentry;
 	bool writing = (rreq->origin == NETFS_READ_FOR_WRITE ||
 			rreq->origin == NETFS_WRITETHROUGH ||
 			rreq->origin == NETFS_UNBUFFERED_WRITE ||
@@ -115,6 +130,14 @@ static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file)
 		if (!fid)
 			goto no_fid;
 		p9_fid_get(fid);
+	} else if (S_ISLNK(rreq->inode->i_mode)){
+		dentry = d_find_alias(rreq->inode);
+		if (!dentry)
+			goto no_fid;
+		fid = v9fs_fid_lookup(dentry);
+		dput(dentry);
+		if (IS_ERR(fid))
+			goto no_fid;
 	} else {
 		fid = v9fs_fid_find_inode(rreq->inode, writing, INVALID_UID, true);
 		if (!fid)
fs/9p/vfs_inode.c +4 -2
index c82db6fe0c39..98644f27d6f1 100644
@@ -302,10 +302,12 @@ int v9fs_init_inode(struct v9fs_session_info *v9ses,
 			goto error;
 		}
 
-		if (v9fs_proto_dotl(v9ses))
+		if (v9fs_proto_dotl(v9ses)) {
 			inode->i_op = &v9fs_symlink_inode_operations_dotl;
-		else
+			inode_nohighmem(inode);
+		} else {
 			inode->i_op = &v9fs_symlink_inode_operations;
+		}
 
 		break;
 	case S_IFDIR:
fs/9p/vfs_inode_dotl.c +64 -8

117 lines not on this page · raw message

Signature · 1 line
2.52.0
#3 lore raw

PATCH v3 2/4 9p: Add mount option for negative dentry cache retention

In reply to Remi Pommarel

Introduce a new mount option, ndentrycache, for v9fs that allows users to specify how long negative dentries are retained in the cache. The retention time can be set in milliseconds (e.g. ndentrycache=10000 for a 10secs retention time), or negative entries can be kept until the buffer cache management removes them by using the option without a value (i.e. ndentrycache).

For consistency reasons, this option should only be used in exclusive or read-only mount scenarios, aligning with the cache=loose usage.

---
 fs/9p/v9fs.c | 73 ++++++++++++++++++++++++++++++++--------------------
 fs/9p/v9fs.h | 23 ++++++++++-------
 2 files changed, 58 insertions(+), 38 deletions(-)
fs/9p/v9fs.c +45 -28
index c5dca81a553e..a26bd9070786 100644
@@ -39,11 +39,12 @@ enum {
 	 * source if we rejected it as EINVAL */
 	Opt_source,
 	/* Options that take integer arguments */
-	Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid,
+	Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid, Opt_ndentrycachetmo,
 	/* String options */
 	Opt_uname, Opt_remotename, Opt_cache, Opt_cachetag,
 	/* Options that take no arguments */
 	Opt_nodevmap, Opt_noxattr, Opt_directio, Opt_ignoreqv,
+	Opt_ndentrycache,
 	/* Access options */
 	Opt_access, Opt_posixacl,
 	/* Lock timeout option */
@@ -77,41 +78,43 @@ static const struct constant_table p9_versions[] = {
  * the client, and all the transports.
  */
 const struct fs_parameter_spec v9fs_param_spec[] = {
-	fsparam_string	("source",	Opt_source),
-	fsparam_u32hex	("debug",	Opt_debug),
-	fsparam_uid	("dfltuid",	Opt_dfltuid),
-	fsparam_gid	("dfltgid",	Opt_dfltgid),
-	fsparam_u32	("afid",	Opt_afid),
-	fsparam_string	("uname",	Opt_uname),
-	fsparam_string	("aname",	Opt_remotename),
-	fsparam_flag	("nodevmap",	Opt_nodevmap),
-	fsparam_flag	("noxattr",	Opt_noxattr),
-	fsparam_flag	("directio",	Opt_directio),
-	fsparam_flag	("ignoreqv",	Opt_ignoreqv),
-	fsparam_string	("cache",	Opt_cache),
-	fsparam_string	("cachetag",	Opt_cachetag),
-	fsparam_string	("access",	Opt_access),
-	fsparam_flag	("posixacl",	Opt_posixacl),
-	fsparam_u32	("locktimeout",	Opt_locktimeout),
+	fsparam_string	("source",		Opt_source),
+	fsparam_u32hex	("debug",		Opt_debug),
+	fsparam_uid	("dfltuid",		Opt_dfltuid),
+	fsparam_gid	("dfltgid",		Opt_dfltgid),
+	fsparam_u32	("afid",		Opt_afid),
+	fsparam_string	("uname",		Opt_uname),
+	fsparam_string	("aname",		Opt_remotename),
+	fsparam_flag	("nodevmap",		Opt_nodevmap),
+	fsparam_flag	("noxattr",		Opt_noxattr),
+	fsparam_flag	("directio",		Opt_directio),
+	fsparam_flag	("ignoreqv",		Opt_ignoreqv),
+	fsparam_string	("cache",		Opt_cache),
+	fsparam_string	("cachetag",		Opt_cachetag),
+	fsparam_string	("access",		Opt_access),
+	fsparam_flag	("posixacl",		Opt_posixacl),
+	fsparam_u32	("locktimeout",		Opt_locktimeout),
+	fsparam_flag	("ndentrycache",	Opt_ndentrycache),
+	fsparam_u32	("ndentrycache",	Opt_ndentrycachetmo),
 
 	/* client options */
-	fsparam_u32	("msize",	Opt_msize),
-	fsparam_flag	("noextend",	Opt_legacy),
-	fsparam_string	("trans",	Opt_trans),
-	fsparam_enum	("version",	Opt_version, p9_versions),
+	fsparam_u32	("msize",		Opt_msize),
+	fsparam_flag	("noextend",		Opt_legacy),
+	fsparam_string	("trans",		Opt_trans),
+	fsparam_enum	("version",		Opt_version, p9_versions),
 
 	/* fd transport options */
-	fsparam_u32	("rfdno",	Opt_rfdno),
-	fsparam_u32	("wfdno",	Opt_wfdno),
+	fsparam_u32	("rfdno",		Opt_rfdno),
+	fsparam_u32	("wfdno",		Opt_wfdno),
 
 	/* rdma transport options */
-	fsparam_u32	("sq",		Opt_sq_depth),
-	fsparam_u32	("rq",		Opt_rq_depth),
-	fsparam_u32	("timeout",	Opt_timeout),
+	fsparam_u32	("sq",			Opt_sq_depth),
+	fsparam_u32	("rq",			Opt_rq_depth),
+	fsparam_u32	("timeout",		Opt_timeout),
 
 	/* fd and rdma transprt options */
-	fsparam_u32	("port",	Opt_port),
-	fsparam_flag	("privport",	Opt_privport),
+	fsparam_u32	("port",		Opt_port),
+	fsparam_flag	("privport",		Opt_privport),
 	{}
 };
 
@@ -159,6 +162,10 @@ int v9fs_show_options(struct seq_file *m, struct dentry *root)
 			   from_kgid_munged(&init_user_ns, v9ses->dfltgid));
 	if (v9ses->afid != ~0)
 		seq_printf(m, ",afid=%u", v9ses->afid);
+	if (v9ses->ndentry_timeout_ms == NDENTRY_TMOUT_NEVER)
+		seq_printf(m, ",ndentrycache");
+	else if (v9ses->flags & V9FS_NDENTRY_TMOUT_SET)
+		seq_printf(m, ",ndentrycache=%u", v9ses->ndentry_timeout_ms);
 	if (strcmp(v9ses->uname, V9FS_DEFUSER) != 0)
 		seq_printf(m, ",uname=%s", v9ses->uname);
 	if (strcmp(v9ses->aname, V9FS_DEFANAME) != 0)
@@ -337,6 +344,16 @@ int v9fs_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		session_opts->session_lock_timeout = (long)result.uint_32 * HZ;
 		break;
 
+	case Opt_ndentrycache:
+		session_opts->flags |= V9FS_NDENTRY_TMOUT_SET;
+		session_opts->ndentry_timeout_ms = NDENTRY_TMOUT_NEVER;
+		break;
+
+	case Opt_ndentrycachetmo:
+		session_opts->flags |= V9FS_NDENTRY_TMOUT_SET;
+		session_opts->ndentry_timeout_ms = result.uint_64;
+		break;
+
 	/* Options for client */
 	case Opt_msize:
 		if (result.uint_32 < 4096) {
fs/9p/v9fs.h +13 -10
index 8410f7883109..2e42729c6c20 100644
@@ -24,6 +24,8 @@
  * @V9FS_ACCESS_ANY: use a single attach for all users
  * @V9FS_ACCESS_MASK: bit mask of different ACCESS options
  * @V9FS_POSIX_ACL: POSIX ACLs are enforced
+ * @V9FS_NDENTRY_TMOUT_SET: Has negative dentry timeout retention time been
+ *			    overriden by ndentrycache mount option
  *
  * Session flags reflect options selected by users at mount time
  */
@@ -34,16 +36,17 @@
 #define V9FS_ACL_MASK V9FS_POSIX_ACL
 
 enum p9_session_flags {
-	V9FS_PROTO_2000U    = 0x01,
-	V9FS_PROTO_2000L    = 0x02,
-	V9FS_ACCESS_SINGLE  = 0x04,
-	V9FS_ACCESS_USER    = 0x08,
-	V9FS_ACCESS_CLIENT  = 0x10,
-	V9FS_POSIX_ACL      = 0x20,
-	V9FS_NO_XATTR       = 0x40,
-	V9FS_IGNORE_QV      = 0x80, /* ignore qid.version for cache hints */
-	V9FS_DIRECT_IO      = 0x100,
-	V9FS_SYNC           = 0x200
+	V9FS_PROTO_2000U       = 0x01,
+	V9FS_PROTO_2000L       = 0x02,
+	V9FS_ACCESS_SINGLE     = 0x04,
+	V9FS_ACCESS_USER       = 0x08,
+	V9FS_ACCESS_CLIENT     = 0x10,
+	V9FS_POSIX_ACL         = 0x20,
+	V9FS_NO_XATTR          = 0x40,
+	V9FS_IGNORE_QV         = 0x80, /* ignore qid.version for cache hints */
+	V9FS_DIRECT_IO         = 0x100,
+	V9FS_SYNC              = 0x200,
+	V9FS_NDENTRY_TMOUT_SET = 0x400,
 };
 
 /**
Signature · 1 line
2.52.0
#4 lore raw

Re: [PATCH v3 2/4] 9p: Add mount option for negative dentry cache retention

Quoted 62 lines · On Friday, 27 February 2026 08:56:53 CET Remi Pommarel wrote:

Introduce a new mount option, ndentrycache, for v9fs that allows users to specify how long negative dentries are retained in the cache. The retention time can be set in milliseconds (e.g. ndentrycache=10000 for a 10secs retention time), or negative entries can be kept until the buffer cache management removes them by using the option without a value (i.e. ndentrycache).

For consistency reasons, this option should only be used in exclusive or read-only mount scenarios, aligning with the cache=loose usage.

---
 fs/9p/v9fs.c | 73 ++++++++++++++++++++++++++++++++--------------------
 fs/9p/v9fs.h | 23 ++++++++++-------
 2 files changed, 58 insertions(+), 38 deletions(-)
fs/9p/v9fs.c +10 -17
index c5dca81a553e..a26bd9070786 100644
@@ -39,11 +39,12 @@ enum {
 	 * source if we rejected it as EINVAL */
 	Opt_source,
 	/* Options that take integer arguments */
-	Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid,
+	Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid, Opt_ndentrycachetmo,
 	/* String options */
 	Opt_uname, Opt_remotename, Opt_cache, Opt_cachetag,
 	/* Options that take no arguments */
 	Opt_nodevmap, Opt_noxattr, Opt_directio, Opt_ignoreqv,
+	Opt_ndentrycache,
 	/* Access options */
 	Opt_access, Opt_posixacl,
 	/* Lock timeout option */
@@ -77,41 +78,43 @@ static const struct constant_table p9_versions[] = {
  * the client, and all the transports.
  */
 const struct fs_parameter_spec v9fs_param_spec[] = {
-	fsparam_string	("source",	Opt_source),
-	fsparam_u32hex	("debug",	Opt_debug),
-	fsparam_uid	("dfltuid",	Opt_dfltuid),
-	fsparam_gid	("dfltgid",	Opt_dfltgid),
-	fsparam_u32	("afid",	Opt_afid),
-	fsparam_string	("uname",	Opt_uname),
-	fsparam_string	("aname",	Opt_remotename),
-	fsparam_flag	("nodevmap",	Opt_nodevmap),
-	fsparam_flag	("noxattr",	Opt_noxattr),
-	fsparam_flag	("directio",	Opt_directio),
-	fsparam_flag	("ignoreqv",	Opt_ignoreqv),
-	fsparam_string	("cache",	Opt_cache),
-	fsparam_string	("cachetag",	Opt_cachetag),
-	fsparam_string	("access",	Opt_access),
-	fsparam_flag	("posixacl",	Opt_posixacl),
-	fsparam_u32	("locktimeout",	Opt_locktimeout),
+	fsparam_string	("source",		Opt_source),
+	fsparam_u32hex	("debug",		Opt_debug),
+	fsparam_uid	("dfltuid",		Opt_dfltuid),
+	fsparam_gid	("dfltgid",		Opt_dfltgid),
+	fsparam_u32	("afid",		Opt_afid),
+	fsparam_string	("uname",		Opt_uname),
+	fsparam_string	("aname",		Opt_remotename),
+	fsparam_flag	("nodevmap",		Opt_nodevmap),

fs/9p/v9fs.c static const struct constant_table p9_versions[] = { · line 98

Quoted 10 lines
fs/9p/v9fs.c +10 -0
+	fsparam_flag	("noxattr",		Opt_noxattr),
+	fsparam_flag	("directio",		Opt_directio),
+	fsparam_flag	("ignoreqv",		Opt_ignoreqv),
+	fsparam_string	("cache",		Opt_cache),
+	fsparam_string	("cachetag",		Opt_cachetag),
+	fsparam_string	("access",		Opt_access),
+	fsparam_flag	("posixacl",		Opt_posixacl),
+	fsparam_u32	("locktimeout",		Opt_locktimeout),
+	fsparam_flag	("ndentrycache",	Opt_ndentrycache),
+	fsparam_u32	("ndentrycache",	Opt_ndentrycachetmo),

That double entry is surprising. So this mount option is supposed to be used like ndentrycache=n for a specific timeout value (in ms) and just ndentrycache (without any assignment) for infinite timeout. That's a bit weird.

Documentation/filesystems/9p.rst should be updated as well BTW.

Nevertheless, like mentioned before, I really think the string "timeout" should be used, at least in a user visible mount option. Keep in mind that timeouts are a common issue to look at, so it is common to just grep for "timeout" in a code base or documentation. An abbrevation like "tmo" or leaving it out entirely is for me therefore IMHO inappropriate.

You found "ndentrycachetimeout" too horribly long, or was that again just motivated by the code indention below? I personally find those indention alignments completely irrelevant, not sure how Dominique sees that. Personally I avoid them, as they cost unnecessary time on git blame.

/Christian

Quoted 101 lines
fs/9p/v9fs.c +15 -11
 	/* client options */
-	fsparam_u32	("msize",	Opt_msize),
-	fsparam_flag	("noextend",	Opt_legacy),
-	fsparam_string	("trans",	Opt_trans),
-	fsparam_enum	("version",	Opt_version, p9_versions),
+	fsparam_u32	("msize",		Opt_msize),
+	fsparam_flag	("noextend",		Opt_legacy),
+	fsparam_string	("trans",		Opt_trans),
+	fsparam_enum	("version",		Opt_version, p9_versions),
 
 	/* fd transport options */
-	fsparam_u32	("rfdno",	Opt_rfdno),
-	fsparam_u32	("wfdno",	Opt_wfdno),
+	fsparam_u32	("rfdno",		Opt_rfdno),
+	fsparam_u32	("wfdno",		Opt_wfdno),
 
 	/* rdma transport options */
-	fsparam_u32	("sq",		Opt_sq_depth),
-	fsparam_u32	("rq",		Opt_rq_depth),
-	fsparam_u32	("timeout",	Opt_timeout),
+	fsparam_u32	("sq",			Opt_sq_depth),
+	fsparam_u32	("rq",			Opt_rq_depth),
+	fsparam_u32	("timeout",		Opt_timeout),
 
 	/* fd and rdma transprt options */
-	fsparam_u32	("port",	Opt_port),
-	fsparam_flag	("privport",	Opt_privport),
+	fsparam_u32	("port",		Opt_port),
+	fsparam_flag	("privport",		Opt_privport),
 	{}
 };
 
@@ -159,6 +162,10 @@ int v9fs_show_options(struct seq_file *m, struct dentry
 *root) from_kgid_munged(&init_user_ns, v9ses->dfltgid));
 	if (v9ses->afid != ~0)
 		seq_printf(m, ",afid=%u", v9ses->afid);
+	if (v9ses->ndentry_timeout_ms == NDENTRY_TMOUT_NEVER)
+		seq_printf(m, ",ndentrycache");
+	else if (v9ses->flags & V9FS_NDENTRY_TMOUT_SET)
+		seq_printf(m, ",ndentrycache=%u", v9ses->ndentry_timeout_ms);
 	if (strcmp(v9ses->uname, V9FS_DEFUSER) != 0)
 		seq_printf(m, ",uname=%s", v9ses->uname);
 	if (strcmp(v9ses->aname, V9FS_DEFANAME) != 0)
@@ -337,6 +344,16 @@ int v9fs_parse_param(struct fs_context *fc, struct

fs_parameter *param) session_opts->session_lock_timeout = (long)result.uint_32 * HZ; break;

fs/9p/v9fs.c +10 -0
+	case Opt_ndentrycache:
+		session_opts->flags |= V9FS_NDENTRY_TMOUT_SET;
+		session_opts->ndentry_timeout_ms = NDENTRY_TMOUT_NEVER;
+		break;
+
+	case Opt_ndentrycachetmo:
+		session_opts->flags |= V9FS_NDENTRY_TMOUT_SET;
+		session_opts->ndentry_timeout_ms = result.uint_64;
+		break;
+
 	/* Options for client */
 	case Opt_msize:
 		if (result.uint_32 < 4096) {
fs/9p/v9fs.h +13 -10
index 8410f7883109..2e42729c6c20 100644
@@ -24,6 +24,8 @@
  * @V9FS_ACCESS_ANY: use a single attach for all users
  * @V9FS_ACCESS_MASK: bit mask of different ACCESS options
  * @V9FS_POSIX_ACL: POSIX ACLs are enforced
+ * @V9FS_NDENTRY_TMOUT_SET: Has negative dentry timeout retention time been
+ *			    overriden by ndentrycache mount option
  *
  * Session flags reflect options selected by users at mount time
  */
@@ -34,16 +36,17 @@
 #define V9FS_ACL_MASK V9FS_POSIX_ACL
 
 enum p9_session_flags {
-	V9FS_PROTO_2000U    = 0x01,
-	V9FS_PROTO_2000L    = 0x02,
-	V9FS_ACCESS_SINGLE  = 0x04,
-	V9FS_ACCESS_USER    = 0x08,
-	V9FS_ACCESS_CLIENT  = 0x10,
-	V9FS_POSIX_ACL      = 0x20,
-	V9FS_NO_XATTR       = 0x40,
-	V9FS_IGNORE_QV      = 0x80, /* ignore qid.version for cache hints */
-	V9FS_DIRECT_IO      = 0x100,
-	V9FS_SYNC           = 0x200
+	V9FS_PROTO_2000U       = 0x01,
+	V9FS_PROTO_2000L       = 0x02,
+	V9FS_ACCESS_SINGLE     = 0x04,
+	V9FS_ACCESS_USER       = 0x08,
+	V9FS_ACCESS_CLIENT     = 0x10,
+	V9FS_POSIX_ACL         = 0x20,
+	V9FS_NO_XATTR          = 0x40,
+	V9FS_IGNORE_QV         = 0x80, /* ignore qid.version for cache hints */
+	V9FS_DIRECT_IO         = 0x100,
+	V9FS_SYNC              = 0x200,
+	V9FS_NDENTRY_TMOUT_SET = 0x400,
 };
 
 /**
#5 lore raw

Re: [PATCH v3 2/4] 9p: Add mount option for negative dentry cache retention

Christian Schoenebeck wrote on Tue, Mar 03, 2026 at 03:53:47PM +0100:

Quoted 14 lines
Quoted 14 lines
fs/9p/v9fs.c +14 -0
+	fsparam_string	("source",		Opt_source),
+	fsparam_u32hex	("debug",		Opt_debug),
+	fsparam_uid	("dfltuid",		Opt_dfltuid),
+	fsparam_gid	("dfltgid",		Opt_dfltgid),
+	fsparam_u32	("afid",		Opt_afid),
+	fsparam_string	("uname",		Opt_uname),
+	fsparam_string	("aname",		Opt_remotename),
+	fsparam_flag	("nodevmap",		Opt_nodevmap),
+	fsparam_flag	("noxattr",		Opt_noxattr),
+	fsparam_flag	("directio",		Opt_directio),
+	fsparam_flag	("ignoreqv",		Opt_ignoreqv),
+	fsparam_string	("cache",		Opt_cache),
+	fsparam_string	("cachetag",		Opt_cachetag),
+	fsparam_string	("access",		Opt_access),
Quoted 8 lines

fs/9p/v9fs.c static const struct constant_table p9_versions[] = { · line 98

Quoted 4 lines
fs/9p/v9fs.c +4 -0
+	fsparam_flag	("posixacl",		Opt_posixacl),
+	fsparam_u32	("locktimeout",		Opt_locktimeout),
+	fsparam_flag	("ndentrycache",	Opt_ndentrycache),
+	fsparam_u32	("ndentrycache",	Opt_ndentrycachetmo),

That double entry is surprising. So this mount option is supposed to be used like ndentrycache=n for a specific timeout value (in ms) and just ndentrycache (without any assignment) for infinite timeout. That's a bit weird.

Could make it a s32 and say <0 means infinite? I think we have that somewhere

Quoted 8 lines

Documentation/filesystems/9p.rst should be updated as well BTW.

Nevertheless, like mentioned before, I really think the string "timeout" should be used, at least in a user visible mount option. Keep in mind that timeouts are a common issue to look at, so it is common to just grep for "timeout" in a code base or documentation. An abbrevation like "tmo" or leaving it out entirely is for me therefore IMHO inappropriate.

Quoted 4 lines

You found "ndentrycachetimeout" too horribly long, or was that again just motivated by the code indention below? I personally find those indention alignments completely irrelevant, not sure how Dominique sees that. Personally I avoid them, as they cost unnecessary time on git blame.

I rarely use blame at all and it's possible to ignore whitespaces for blame, but I'd tend to agree here, I don't care if this stays aligned.

OTOH ndentrycachetimeout as a mount option is a mouthful, negativetimeout or negtimeout sounds clear enough to me? I can't think of anything else that'd be negative related to timeouts, but perhaps it's the lack of sleep speaking

Signature · 1 line
Dominique Martinet | Asmadeus
#6 lore raw

Re: [PATCH v3 2/4] 9p: Add mount option for negative dentry cache retention

Quoted 23 lines · Dominique Martinet

Christian Schoenebeck wrote on Tue, Mar 03, 2026 at 03:53:47PM +0100:

Quoted 22 lines
Quoted 8 lines
fs/9p/v9fs.c +8 -0
+	fsparam_string	("source",		Opt_source),
+	fsparam_u32hex	("debug",		Opt_debug),
+	fsparam_uid	("dfltuid",		Opt_dfltuid),
+	fsparam_gid	("dfltgid",		Opt_dfltgid),
+	fsparam_u32	("afid",		Opt_afid),
+	fsparam_string	("uname",		Opt_uname),
+	fsparam_string	("aname",		Opt_remotename),
+	fsparam_flag	("nodevmap",		Opt_nodevmap),

fs/9p/v9fs.c static const struct constant_table p9_versions[] = { · line 98

Quoted 10 lines
fs/9p/v9fs.c +10 -0
+	fsparam_flag	("noxattr",		Opt_noxattr),
+	fsparam_flag	("directio",		Opt_directio),
+	fsparam_flag	("ignoreqv",		Opt_ignoreqv),
+	fsparam_string	("cache",		Opt_cache),
+	fsparam_string	("cachetag",		Opt_cachetag),
+	fsparam_string	("access",		Opt_access),
+	fsparam_flag	("posixacl",		Opt_posixacl),
+	fsparam_u32	("locktimeout",		Opt_locktimeout),
+	fsparam_flag	("ndentrycache",	Opt_ndentrycache),
+	fsparam_u32	("ndentrycache",	Opt_ndentrycachetmo),

That double entry is surprising. So this mount option is supposed to be used like ndentrycache=n for a specific timeout value (in ms) and just ndentrycache (without any assignment) for infinite timeout. That's a bit weird.

Yes I have seen this used in several other fs (see init_itable mount option for ext4fs or compress one for btrfs). I do agree that is a bit weird but this allow the whole 32bit range for timeout.

Quoted 3 lines

Could make it a s32 and say <0 means infinite? I think we have that somewhere

I did that on previous version, but was afraid that ~20days timeout max value may be too restrictive?

I do agree that this is a bit odd though and if you both think s32 is better that is fine with me.

Quoted 14 lines
Quoted 9 lines

Documentation/filesystems/9p.rst should be updated as well BTW.

Nevertheless, like mentioned before, I really think the string "timeout" should be used, at least in a user visible mount option. Keep in mind that timeouts are a common issue to look at, so it is common to just grep for "timeout" in a code base or documentation. An abbrevation like "tmo" or leaving it out entirely is for me therefore IMHO inappropriate.

Quoted 4 lines

You found "ndentrycachetimeout" too horribly long, or was that again just motivated by the code indention below? I personally find those indention alignments completely irrelevant, not sure how Dominique sees that. Personally I avoid them, as they cost unnecessary time on git blame.

Quoted 7 lines

I rarely use blame at all and it's possible to ignore whitespaces for blame, but I'd tend to agree here, I don't care if this stays aligned.

OTOH ndentrycachetimeout as a mount option is a mouthful, negativetimeout or negtimeout sounds clear enough to me? I can't think of anything else that'd be negative related to timeouts, but perhaps it's the lack of sleep speaking

No strong opinion on the option name though so any name that suits you is alse fine by me.

Signature · 1 line
Remi
#7 lore raw

Re: [PATCH v3 2/4] 9p: Add mount option for negative dentry cache retention

Quoted 29 lines · On Wednesday, 4 March 2026 09:25:27 CET Remi Pommarel wrote:
Quoted 24 lines · Dominique Martinet

Christian Schoenebeck wrote on Tue, Mar 03, 2026 at 03:53:47PM +0100:

Quoted 23 lines
Quoted 8 lines
fs/9p/v9fs.c +8 -0
+	fsparam_string	("source",		Opt_source),
+	fsparam_u32hex	("debug",		Opt_debug),
+	fsparam_uid	("dfltuid",		Opt_dfltuid),
+	fsparam_gid	("dfltgid",		Opt_dfltgid),
+	fsparam_u32	("afid",		Opt_afid),
+	fsparam_string	("uname",		Opt_uname),
+	fsparam_string	("aname",		Opt_remotename),
+	fsparam_flag	("nodevmap",		Opt_nodevmap),

fs/9p/v9fs.c static const struct constant_table p9_versions[] = { · line 98

Quoted 10 lines
fs/9p/v9fs.c +10 -0
+	fsparam_flag	("noxattr",		Opt_noxattr),
+	fsparam_flag	("directio",		Opt_directio),
+	fsparam_flag	("ignoreqv",		Opt_ignoreqv),
+	fsparam_string	("cache",		Opt_cache),
+	fsparam_string	("cachetag",		Opt_cachetag),
+	fsparam_string	("access",		Opt_access),
+	fsparam_flag	("posixacl",		Opt_posixacl),
+	fsparam_u32	("locktimeout",		Opt_locktimeout),
+	fsparam_flag	("ndentrycache",	Opt_ndentrycache),
+	fsparam_u32	("ndentrycache",	Opt_ndentrycachetmo),

That double entry is surprising. So this mount option is supposed to be used like ndentrycache=n for a specific timeout value (in ms) and just ndentrycache (without any assignment) for infinite timeout. That's a bit weird.

Yes I have seen this used in several other fs (see init_itable mount option for ext4fs or compress one for btrfs). I do agree that is a bit weird but this allow the whole 32bit range for timeout.

Quoted 8 lines
Quoted 2 lines

Could make it a s32 and say <0 means infinite? I think we have that somewhere

I did that on previous version, but was afraid that ~20days timeout max value may be too restrictive?

I do agree that this is a bit odd though and if you both think s32 is better that is fine with me.

What about just making this mount option a string and doing the parsing on our end? That would have the benefit of simply allowing arguments like "i00s", "5d", "1y", and if you really wanted "inf".

I would find units for this much more useful in practice than allowing infinite. Like discussed before, it is in general a bad idea to configure negative dentries to persist for good due to the huge amount of bogus entries that pile up.

Quoted 18 lines
Quoted 18 lines
Quoted 9 lines

Documentation/filesystems/9p.rst should be updated as well BTW.

Nevertheless, like mentioned before, I really think the string "timeout" should be used, at least in a user visible mount option. Keep in mind that
timeouts are a common issue to look at, so it is common to just grep for "timeout" in a code base or documentation. An abbrevation like "tmo" or leaving it out entirely is for me therefore IMHO inappropriate.

Quoted 5 lines

You found "ndentrycachetimeout" too horribly long, or was that again just
motivated by the code indention below? I personally find those indention alignments completely irrelevant, not sure how Dominique sees that. Personally I avoid them, as they cost unnecessary time on git blame.

I rarely use blame at all and it's possible to ignore whitespaces for blame, but I'd tend to agree here, I don't care if this stays aligned.

Quoted 7 lines
Quoted 4 lines

OTOH ndentrycachetimeout as a mount option is a mouthful, negativetimeout or negtimeout sounds clear enough to me? I can't think of anything else that'd be negative related to timeouts, but perhaps it's the lack of sleep speaking

No strong opinion on the option name though so any name that suits you is alse fine by me.

Another suggestion: "ndtimeout"?

/Christian

#8 lore raw

Re: [PATCH v3 2/4] 9p: Add mount option for negative dentry cache retention

Christian Schoenebeck wrote on Wed, Mar 04, 2026 at 10:01:42AM +0100:

Quoted 6 lines
Quoted 5 lines

I did that on previous version, but was afraid that ~20days timeout max value may be too restrictive?

I do agree that this is a bit odd though and if you both think s32 is better that is fine with me.

Quoted 8 lines

What about just making this mount option a string and doing the parsing on our end? That would have the benefit of simply allowing arguments like "i00s", "5d", "1y", and if you really wanted "inf".

I would find units for this much more useful in practice than allowing infinite. Like discussed before, it is in general a bad idea to configure negative dentries to persist for good due to the huge amount of bogus entries that pile up.

I don't mind either way -- I think 20 days for such a timeout is enough, but I agree being able to set something like '60s' or '100ms' would certainly be convenient.

I'm actually surprised there's no such parsing helper in the kernel?! The only related code I could find was parse_ns_duration / parse_seconds_duration in tools/tracing/rtla/src/utils.c but that's for tools, and there doesn't seem to be anything we could use..

Well, it's not that bad, so I'm not fussy here.

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

OTOH ndentrycachetimeout as a mount option is a mouthful, negativetimeout or negtimeout sounds clear enough to me? I can't think of anything else that'd be negative related to timeouts, but perhaps it's the lack of sleep speaking

No strong opinion on the option name though so any name that suits you is alse fine by me.

Another suggestion: "ndtimeout"?

I'd slightly favor negtimeout over ndtimeout but am fine with either here.
('nd' sounds like something network-y to me, network discovery or ndo, but that's not a hard no)

Thanks,

Signature · 1 line
Dominique Martinet | Asmadeus
#9 lore raw

Re: [PATCH v3 2/4] 9p: Add mount option for negative dentry cache retention

In reply to Remi Pommarel

On Friday, 27 February 2026 08:56:53 CET Remi Pommarel wrote:
[...]

fs/9p/v9fs.h line 28

Quoted 10 lines
fs/9p/v9fs.h +2 -0
index 8410f7883109..2e42729c6c20 100644
@@ -24,6 +24,8 @@
  * @V9FS_ACCESS_ANY: use a single attach for all users
  * @V9FS_ACCESS_MASK: bit mask of different ACCESS options
  * @V9FS_POSIX_ACL: POSIX ACLs are enforced
+ * @V9FS_NDENTRY_TMOUT_SET: Has negative dentry timeout retention time been
+ *			    overriden by ndentrycache mount option

Nit: misaligned indention due to tabs. :-)

/Christian

reviewer Reviewed-by on v3 1/4
#2 lore raw

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

In reply to Remi Pommarel
Quoted 30 lines · 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.

---
 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(-)

[...]

Quoted 31 lines
fs/9p/v9fs.h +1 -0
index 6a12445d3858..8410f7883109 100644
@@ -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() .

fs/9p/v9fs.h +1 -0
@@ -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 */
 };

[...]

Quoted 13 lines
include/net/9p/client.h +0 -0
index 838a94218b59..55c6cb54bd25 100644
@@ -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

include/net/9p/client.h struct p9_session_opts { · line 210

Quoted 7 lines
include/net/9p/client.h +1 -0
@@ -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:

reviewer Reviewed-by on v3 3/4
#11 lore raw

Re: [PATCH v3 3/4] 9p: Set default negative dentry retention time for cache=loose

In reply to Remi Pommarel
Quoted 13 lines · On Friday, 27 February 2026 08:56:54 CET Remi Pommarel wrote:

For cache=loose mounts, set the default negative dentry cache retention time to 24 hours.

---
 fs/9p/v9fs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
fs/9p/v9fs.c +0 -0
index a26bd9070786..d14f6eda94d6 100644

fs/9p/v9fs.c line 29

Quoted 6 lines
fs/9p/v9fs.c +3 -0
@@ -24,6 +24,9 @@
 #include "v9fs_vfs.h"
 #include "cache.h"
 
+/* cache=loose default negative dentry retention time is 24hours */
+#define CACHE_LOOSE_NDENTRY_TMOUT_DEFAULT (24 * 60 * 60 * 1000)
+

Come on, really worth to save 4 characters here as well? :)

Whatever:

Quoted 17 lines
fs/9p/v9fs.c +7 -0
 static DEFINE_SPINLOCK(v9fs_sessionlist_lock);
 static LIST_HEAD(v9fs_sessionlist);
 struct kmem_cache *v9fs_inode_cache;
@@ -440,6 +443,13 @@ static void v9fs_apply_options(struct v9fs_session_info
 *v9ses, v9ses->uid = ctx->session_opts.uid;
 	v9ses->session_lock_timeout = ctx->session_opts.session_lock_timeout;
 	v9ses->ndentry_timeout_ms = ctx->session_opts.ndentry_timeout_ms;
+
+	/* If negative dentry timeout has not been overriden set default for
+	 * cache=loose
+	 */
+	if (!(v9ses->flags & V9FS_NDENTRY_TMOUT_SET) &&
+	    (v9ses->cache & CACHE_LOOSE))
+		v9ses->ndentry_timeout_ms = CACHE_LOOSE_NDENTRY_TMOUT_DEFAULT;
 }
 
 /**
reviewer Reviewed-by on v3 4/4
#13 lore raw

Re: [PATCH v3 4/4] 9p: Enable symlink caching in page cache

In reply to Remi Pommarel
Quoted 25 lines · On Friday, 27 February 2026 08:56:55 CET Remi Pommarel wrote:

Currently, when cache=loose is enabled, file reads are cached in the page cache, but symlink reads are not. This patch allows the results of p9_client_readlink() to be stored in the page cache, eliminating the need for repeated 9P transactions on subsequent symlink accesses.

This change improves performance for workloads that involve frequent symlink resolution.

---
 fs/9p/vfs_addr.c       | 29 +++++++++++++++--
 fs/9p/vfs_inode.c      |  6 ++--
 fs/9p/vfs_inode_dotl.c | 72 +++++++++++++++++++++++++++++++++++++-----
 3 files changed, 94 insertions(+), 13 deletions(-)
fs/9p/vfs_addr.c +1 -0
index 862164181bac..0683090a5f15 100644
@@ -70,10 +70,24 @@ static void v9fs_issue_read(struct netfs_io_subrequest
 *subreq) {
 	struct netfs_io_request *rreq = subreq->rreq;
 	struct p9_fid *fid = rreq->netfs_priv;
+	char *target;
 	unsigned long long pos = subreq->start + subreq->transferred;

fs/9p/vfs_addr.c static void v9fs_issue_read(struct netfs_io_subrequest · line 81

Quoted 10 lines
fs/9p/vfs_addr.c +7 -3
-	int total, err;
-
-	total = p9_client_read(fid, pos, &subreq->io_iter, &err);
+	int total, err, len, n;
+
+	if (S_ISLNK(rreq->inode->i_mode)) {
+		/* p9_client_readlink() must not be called for legacy protocols
+		 * 9p2000 or 9p2000.u.
+		 */
+		BUG_ON(!p9_is_proto_dotl(fid->clnt));

I would have added this to p9_client_readlink() instead, as it is in general a bug if someone calls that function without 9p2000.L. But I take it that you wanted to make it clear that way that this context is only executed by 9p2000.L in the first place, so OK.

Quoted 21 lines
fs/9p/vfs_addr.c +10 -0
+		err = p9_client_readlink(fid, &target);
+		len = strnlen(target, PAGE_SIZE - 1);
+		n = copy_to_iter(target, len, &subreq->io_iter);
+		if (n != len)
+			err = -EFAULT;
+		total = i_size_read(rreq->inode);
+	} else {
+		total = p9_client_read(fid, pos, &subreq->io_iter, &err);
+	}
 
 	/* if we just extended the file size, any portion not in
 	 * cache won't be on server and is zeroes */
@@ -99,6 +113,7 @@ static void v9fs_issue_read(struct netfs_io_subrequest
 *subreq) static int v9fs_init_request(struct netfs_io_request *rreq, struct
 file *file) {
 	struct p9_fid *fid;
+	struct dentry *dentry;
 	bool writing = (rreq->origin == NETFS_READ_FOR_WRITE ||
 			rreq->origin == NETFS_WRITETHROUGH ||
 			rreq->origin == NETFS_UNBUFFERED_WRITE ||

fs/9p/vfs_addr.c static int v9fs_init_request(struct netfs_io_request · line 133

Quoted 4 lines
fs/9p/vfs_addr.c +1 -0
@@ -115,6 +130,14 @@ static int v9fs_init_request(struct netfs_io_request
 *rreq, struct file *file) if (!fid)
 			goto no_fid;
 		p9_fid_get(fid);
+	} else if (S_ISLNK(rreq->inode->i_mode)){

Nit: missing space between ) and {

Except of that:

/Christian

Quoted 157 lines
fs/9p/vfs_addr.c +7 -0
+		dentry = d_find_alias(rreq->inode);
+		if (!dentry)
+			goto no_fid;
+		fid = v9fs_fid_lookup(dentry);
+		dput(dentry);
+		if (IS_ERR(fid))
+			goto no_fid;
 	} else {
 		fid = v9fs_fid_find_inode(rreq->inode, writing, INVALID_UID, true);
 		if (!fid)
fs/9p/vfs_inode.c +4 -2
index c82db6fe0c39..98644f27d6f1 100644
@@ -302,10 +302,12 @@ int v9fs_init_inode(struct v9fs_session_info *v9ses,
 			goto error;
 		}
 
-		if (v9fs_proto_dotl(v9ses))
+		if (v9fs_proto_dotl(v9ses)) {
 			inode->i_op = &v9fs_symlink_inode_operations_dotl;
-		else
+			inode_nohighmem(inode);
+		} else {
 			inode->i_op = &v9fs_symlink_inode_operations;
+		}
 
 		break;
 	case S_IFDIR:
fs/9p/vfs_inode_dotl.c +34 -0
index 643e759eacb2..a286a078d6a6 100644
@@ -686,9 +686,13 @@ v9fs_vfs_symlink_dotl(struct mnt_idmap *idmap, struct
 inode *dir, int err;
 	kgid_t gid;
 	const unsigned char *name;
+	umode_t mode;
+	struct v9fs_session_info *v9ses;
 	struct p9_qid qid;
 	struct p9_fid *dfid;
 	struct p9_fid *fid = NULL;
+	struct inode *inode;
+	struct posix_acl *dacl = NULL, *pacl = NULL;
 
 	name = dentry->d_name.name;
 	p9_debug(P9_DEBUG_VFS, "%lu,%s,%s\n", dir->i_ino, name, symname);
@@ -702,6 +706,14 @@ v9fs_vfs_symlink_dotl(struct mnt_idmap *idmap, struct
 inode *dir,
 
 	gid = v9fs_get_fsgid_for_create(dir);
 
+	/* Update mode based on ACL value */
+	err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
+	if (err) {
+		p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mknod %d\n",
+			 err);
+		goto error;
+	}
+
 	/* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
 	err = p9_client_symlink(dfid, name, symname, gid, &qid);
@@ -712,8 +724,30 @@ v9fs_vfs_symlink_dotl(struct mnt_idmap *idmap, struct
 inode *dir,
 
 	v9fs_invalidate_inode_attr(dir);
 
+	/* instantiate inode and assign the unopened fid to the dentry */
+	fid = p9_client_walk(dfid, 1, &name, 1);
+	if (IS_ERR(fid)) {
+		err = PTR_ERR(fid);
+		p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
+			 err);
+		goto error;
+	}
+
+	v9ses = v9fs_inode2v9ses(dir);
+	inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
+	if (IS_ERR(inode)) {
+		err = PTR_ERR(inode);
+		p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
+			 err);
+		goto error;
+	}
+	v9fs_set_create_acl(inode, fid, dacl, pacl);
+	v9fs_fid_add(dentry, &fid);
+	d_instantiate(dentry, inode);
+	err = 0;
 error:
 	p9_fid_put(fid);
+	v9fs_put_acl(dacl, pacl);
 	p9_fid_put(dfid);
 	return err;

}

fs/9p/vfs_inode_dotl.c +30 -8
@@ -853,24 +887,23 @@ v9fs_vfs_mknod_dotl(struct mnt_idmap *idmap, struct
 inode *dir, }
 
 /**
- * v9fs_vfs_get_link_dotl - follow a symlink path
+ * v9fs_vfs_get_link_nocache_dotl - Resolve a symlink directly.
+ *
+ * To be used when symlink caching is not enabled.
+ *
  * @dentry: dentry for symlink
  * @inode: inode for symlink
  * @done: destructor for return value
  */
-
 static const char *
-v9fs_vfs_get_link_dotl(struct dentry *dentry,
-		       struct inode *inode,
-		       struct delayed_call *done)
+v9fs_vfs_get_link_nocache_dotl(struct dentry *dentry,
+			       struct inode *inode,
+			       struct delayed_call *done)
 {
 	struct p9_fid *fid;
 	char *target;
 	int retval;
 
-	if (!dentry)
-		return ERR_PTR(-ECHILD);
-
 	p9_debug(P9_DEBUG_VFS, "%pd\n", dentry);
 
 	fid = v9fs_fid_lookup(dentry);
@@ -884,6 +917,29 @@ v9fs_vfs_get_link_dotl(struct dentry *dentry,
 	return target;
 }
 
+/**
+ * v9fs_vfs_get_link_dotl - follow a symlink path
+ * @dentry: dentry for symlink
+ * @inode: inode for symlink
+ * @done: destructor for return value
+ */
+static const char *
+v9fs_vfs_get_link_dotl(struct dentry *dentry,
+		       struct inode *inode,
+		       struct delayed_call *done)
+{
+	struct v9fs_session_info *v9ses;
+
+	if (!dentry)
+		return ERR_PTR(-ECHILD);
+
+	v9ses = v9fs_inode2v9ses(inode);
+	if (v9ses->cache & (CACHE_META|CACHE_LOOSE))
+		return page_get_link(dentry, inode, done);
+
+	return v9fs_vfs_get_link_nocache_dotl(dentry, inode, done);
+}
+
 int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
 {
 	struct p9_stat_dotl *st;