Skip to contentSkip to conversation

exports: add support for new riomode= and wiomode= export options

PATCH Superseded Jeff Layton 1 participant 5 messages Oct 27

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jeff Layton

author maintainer
#0 lore raw

cover exports: add support for new riomode= and wiomode= export options

This patchset adds support for riomode= and wiomode= export options to exportd and mountd. This is the companion patchset to [1].

The last patch in this adds a new nfsd-iomode-advisor script that watches various stats on the server and advises the admin what mode to use.

I consider the advisor optional as it was largely vibe-coded. I'm not sure I'd trust its advice that far, but it's probably better than guessing.

[1]: https://lore.kernel.org/linux-nfs/[email protected]/

---
Jeff Layton (4):
exportfs/mountd/exportd: track the svc_export policy highest attribute
exports: Add riomode= and wiomode= export options
exportfs: Display and document riomode= and wiomode=
nfsd-iomode-advisor: recommend riomode= and wiomode= for an export

 configure.ac                                      |    3 +-
 support/export/cache.c                            |   59 +-
 support/export/export_policy.c                    |   29 +-
 support/export/v4root.c                           |    2 +
 support/include/exportfs.h                        |    3 +
 support/include/nfsd_netlink.h                    |   12 +
 support/include/nfslib.h                          |   14 +
 support/nfs/exports.c                             |   51 +
 tools/Makefile.am                                 |    2 +-
 tools/nfsd-iomode-advisor/Makefile.am             |   14 +
 tools/nfsd-iomode-advisor/nfsd-iomode-advisor.man |  232 ++++
 tools/nfsd-iomode-advisor/nfsd-iomode-advisor.py  | 1198 +++++++++++++++++++++
 utils/exportfs/exportfs.c                         |   34 +
 utils/exportfs/exports.man                        |   22 +
 14 files changed, 1671 insertions(+), 4 deletions(-)

---
base-commit: 0ed4324cbbb8020039d338d597c1422a980f7085
change-id: 20261014-master-b5afd69e3772

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>
author maintainer
#1 lore raw

PATCH 1/4 exportfs/mountd/exportd: track the svc_export policy highest attribute

Record max_attr, the highest attribute in the kernel svc_export netlink policy, in struct nfsd_export_policy. Follow-on work needs it to avoid sending attributes that an older kernel would reject the whole entry over.

---
 support/export/export_policy.c | 7 ++++++-
 support/include/exportfs.h     | 2 ++
 2 files changed, 8 insertions(+), 1 deletion(-)
support/export/export_policy.c +6 -1
index 9c0a099fb0c2..a0170cb87f91 100644
@@ -40,6 +40,7 @@ struct export_policy_dump {
 	int		done;
 	int		do_idx;		/* the op's own policy */
 	/* per policy: */
+	int		max_attr[NL_POLICY_SLOTS];
 	int		reqs_idx[NL_POLICY_SLOTS];	/* REQUESTS nests this */
 	uint64_t	flags_mask[NL_POLICY_SLOTS];	/* mask of FLAGS */
 };
@@ -106,6 +107,8 @@ static void nl_policy_attrs(struct export_policy_dump *d, struct nlattr *attr)
 		nla_for_each_nested(a, pol, arem) {
 			int type = nla_type(a);
 
+			if (d->max_attr[idx] < type)
+				d->max_attr[idx] = type;
 			nla_for_each_nested(p, a, rem)
 				nl_policy_type_attr(d, idx, type, p);
 		}
@@ -219,8 +222,10 @@ int nfsd_export_policy_query(struct nfsd_export_policy *pol)
 	 * every kernel with the netlink export interface.
 	 */
 	cached.secinfo_flags = NFSEXP_SECINFO_FLAGS;
+	cached.max_attr = d.max_attr[svc];
 	have_cached = true;
-	xlog(D_NETLINK, "svc_export policy: flags 0x%x", cached.flags);
+	xlog(D_NETLINK, "svc_export policy: max attribute %d, flags 0x%x",
+	     cached.max_attr, cached.flags);
 	*pol = cached;
 	ret = 0;
 out:
support/include/exportfs.h +2 -0
index d762e4533560..a7c145543075 100644
@@ -170,6 +170,8 @@ struct nfskey *			key_lookup(char *hname);
 struct nfsd_export_policy {
 	unsigned int	flags;		/* export flags it knows */
 	unsigned int	secinfo_flags;	/* flags that may vary per flavor */
+	int		max_attr;	/* highest svc_export netlink attribute,
+					 * 0 if it did not say */
 };
 
 struct nfsd_export_policy *get_export_features(void);
Signature · 1 line
2.56.0
author maintainer
#2 lore raw

PATCH 2/4 exports: Add riomode= and wiomode= export options

In reply to Jeff Layton

Parse riomode=/wiomode= (buffered/dontcache/direct) into new e_riomode/e_wiomode exportent fields, defaulting to unset, and pass explicitly-set values to the kernel over the netlink svc_export interface.

- Kernels without the iomode attributes (e.g. v7.2) reject the whole entry. Add nfsd_export_iomode_supported(), which checks the svc_export policy's highest attribute via nfsd_export_policy_query(), and have mountd drop the options with a warning on such kernels instead of leaving the export unmountable.
- The /proc channel cannot carry them either; warn there too.
- Resync nfsd_netlink.h and bump the configure probe to NFSD_A_SVC_EXPORT_WRITE_IOMODE.

---
 configure.ac                   |  2 +-
 support/export/cache.c         | 59 +++++++++++++++++++++++++++++++++++++++++-
 support/export/export_policy.c | 22 ++++++++++++++++
 support/export/v4root.c        |  2 ++
 support/include/exportfs.h     |  1 +
 support/include/nfsd_netlink.h | 12 +++++++++
 support/include/nfslib.h       | 13 ++++++++++
 support/nfs/exports.c          | 51 ++++++++++++++++++++++++++++++++++++
 8 files changed, 160 insertions(+), 2 deletions(-)
configure.ac +1 -1
index 2c13292961bf..ff752b8bd17f 100644
@@ -283,7 +283,7 @@ AC_CHECK_HEADERS(linux/nfsd_netlink.h)
 
 # ensure the system netlink headers have the latest features
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <linux/nfsd_netlink.h>]],
-			                   [[int foo = NFSD_CMD_FILEHANDLE_GET;]])],
+			                   [[int foo = NFSD_A_SVC_EXPORT_WRITE_IOMODE;]])],
 			   [AC_DEFINE([USE_SYSTEM_NFSD_NETLINK_H], 1,
 				      ["Use system's linux/nfsd_netlink.h"])])
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <linux/lockd_netlink.h>]],
support/export/cache.c +58 -1

96 lines not on this page · raw message

support/export/export_policy.c +22 -0
index a0170cb87f91..797a8459e3c0 100644
@@ -244,6 +244,28 @@ int nfsd_export_policy_query(struct nfsd_export_policy *UNUSED(pol))
 
 #endif /* HAVE_GENL_POLICY_DUMP */
 
+/**
+ * nfsd_export_iomode_supported - does the kernel take per-export I/O modes?
+ *
+ * A kernel without them refuses any svc_export entry that carries one.
+ *
+ * Returns 1 if it accepts riomode/wiomode, 0 if not or if that cannot be
+ * found out, or -1 if the nfsd netlink family is not registered, as when
+ * nfsd is not loaded.
+ */
+int nfsd_export_iomode_supported(void)
+{
+	struct nfsd_export_policy pol;
+	int ret;
+
+	ret = nfsd_export_policy_query(&pol);
+	if (ret == -ENOENT)
+		return -1;
+	if (ret < 0)
+		return 0;
+	return pol.max_attr >= NFSD_A_SVC_EXPORT_WRITE_IOMODE;
+}
+
 /**
  * nfsd_nl_load_export_features - learn the kernel's export flags over netlink
  *
support/export/v4root.c +2 -0
index 38286b91ede0..4075b9ef2fef 100644
@@ -47,6 +47,8 @@ static nfs_export pseudo_root = {
 		.e_fsid = 0,
 		.e_mountpoint = NULL,
 		.e_ttl = 0,
+		.e_riomode = NFSD_IO_UNSET,
+		.e_wiomode = NFSD_IO_UNSET,
 	},
 	.m_exported = 0,
 	.m_xtabent = 1,
support/include/exportfs.h +1 -0
index a7c145543075..9096db37a6ee 100644
@@ -177,6 +177,7 @@ struct nfsd_export_policy {
 struct nfsd_export_policy *get_export_features(void);
 void set_export_features(const struct nfsd_export_policy *pol);
 int nfsd_export_policy_query(struct nfsd_export_policy *pol);
+int nfsd_export_iomode_supported(void);
 void nfsd_nl_load_export_features(void);
 
 void fix_pseudoflavor_flags(struct exportent *ep);
support/include/nfsd_netlink.h +12 -0
index dcd2126d848b..6628ed7c0922 100644
@@ -59,6 +59,16 @@ enum nfsd_rpcbind_flags {
 	NFSD_RPCBIND_FLAGS_NO_UDP = 1,
 };
 
+/*
+ * NFS READ/WRITE I/O mode. These values match the global io_cache_read and
+ * io_cache_write debugfs settings.
+ */
+enum nfsd_io_mode {
+	NFSD_IO_MODE_BUFFERED,
+	NFSD_IO_MODE_DONTCACHE,
+	NFSD_IO_MODE_DIRECT,
+};
+
 enum {
 	NFSD_A_CACHE_NOTIFY_CACHE_TYPE = 1,
 
@@ -185,6 +195,8 @@ enum {
 	NFSD_A_SVC_EXPORT_XPRTSEC,
 	NFSD_A_SVC_EXPORT_FLAGS,
 	NFSD_A_SVC_EXPORT_FSID,
+	NFSD_A_SVC_EXPORT_READ_IOMODE,
+	NFSD_A_SVC_EXPORT_WRITE_IOMODE,
 
 	__NFSD_A_SVC_EXPORT_MAX,
 	NFSD_A_SVC_EXPORT_MAX = (__NFSD_A_SVC_EXPORT_MAX - 1)
support/include/nfslib.h +13 -0
index c8601a156cba..f2be65b55f8c 100644
@@ -75,6 +75,16 @@ struct xprtsec_entry {
 	int			flags;
 };
 
+/*
+ * Per-export I/O modes for riomode=/wiomode=. Values must match the
+ * kernel's NFSD_IO_* enum (fs/nfsd/nfsd.h). NFSD_IO_UNSET means no
+ * option was given; the export follows the server's global setting.
+ */
+#define NFSD_IO_BUFFERED	0
+#define NFSD_IO_DONTCACHE	1
+#define NFSD_IO_DIRECT		2
+#define NFSD_IO_UNSET		(-1)
+
 /*
  * Data related to a single exports entry as returned by getexportent.
  * FIXME: export options should probably be parsed at a later time to
@@ -100,6 +110,8 @@ struct exportent {
 	unsigned int	e_ttl;
 	char *		e_realpath;
 	int		e_reexport;
+	int		e_riomode;
+	int		e_wiomode;
 };
 
 struct rmtabent {
@@ -115,6 +127,7 @@ void			setexportent(char *fname, char *type);
 struct exportent *	getexportent(int);
 void 			secinfo_show(FILE *fp, struct exportent *ep);
 void			xprtsecinfo_show(FILE *fp, struct exportent *ep);
+const char *		iomode_name(int mode);
 void			putexportent(struct exportent *xep);
 void			endexportent(void);
 struct exportent *	mkexportent(char *hname, char *path, char *opts);
support/nfs/exports.c +51 -0

75 lines not on this page · raw message

Signature · 1 line
2.56.0
author maintainer
#3 lore raw

PATCH 3/4 exportfs: Display and document riomode= and wiomode=

In reply to Jeff Layton

Show explicitly-set I/O modes in "exportfs -v" output and document the new options in exports(5). Warn when exporting if the running kernel, or no-netlink, means they will be ignored.

---
 support/include/nfslib.h   |  1 +
 utils/exportfs/exportfs.c  | 34 ++++++++++++++++++++++++++++++++++
 utils/exportfs/exports.man | 22 ++++++++++++++++++++++
 3 files changed, 57 insertions(+)
support/include/nfslib.h +1 -0
index f2be65b55f8c..8b515eb1fd5e 100644
@@ -79,6 +79,7 @@ struct xprtsec_entry {
  * Per-export I/O modes for riomode=/wiomode=. Values must match the
  * kernel's NFSD_IO_* enum (fs/nfsd/nfsd.h). NFSD_IO_UNSET means no
  * option was given; the export follows the server's global setting.
+ * It matches the kernel's NFSD_IO_DEFAULT value.
  */
 #define NFSD_IO_BUFFERED	0
 #define NFSD_IO_DONTCACHE	1
utils/exportfs/exportfs.c +34 -0
index ecf66fd07fd1..6061b2f03d7f 100644
@@ -614,6 +614,32 @@ try_proc:
 	return 1;
 }
 
+/*
+ * mountd passes riomode= and wiomode= to the kernel only over netlink, and
+ * only to a kernel that takes them.  @test_result is from can_test().
+ */
+static void
+validate_iomode(nfs_export *exp, const char *path, int test_result)
+{
+	static int supported = -1;
+
+	if (exp->m_export.e_riomode == NFSD_IO_UNSET &&
+	    exp->m_export.e_wiomode == NFSD_IO_UNSET)
+		return;
+
+	if (supported < 0)
+		supported = test_result == 2 ?
+			    nfsd_export_iomode_supported() : 0;
+	/* nfsd is not loaded, so there is no telling yet */
+	if (supported < 0)
+		return;
+
+	if (!supported)
+		xlog(L_WARNING, "%s: ignoring riomode= and wiomode=: %s", path,
+		     no_netlink ? "no-netlink is set" :
+				  "not supported by the running kernel");
+}
+
 static void
 validate_export(nfs_export *exp)
 {
@@ -642,6 +668,8 @@ validate_export(nfs_export *exp)
 	if (!test_result)
 		return;
 
+	validate_iomode(exp, path, test_result);
+
 	/*
 	 * When netlink is available, skip the export_test() probe.
 	 * mountd/exportd will validate exports at cache-fill time.
@@ -838,6 +866,12 @@ dump(int verbose, int export_format)
 				c = dumpopt(c, "no_acl");
 			if (ep->e_flags & NFSEXP_PNFS)
 				c = dumpopt(c, "pnfs");
+			if (ep->e_riomode != NFSD_IO_UNSET)
+				c = dumpopt(c, "riomode=%s",
+					    iomode_name(ep->e_riomode));
+			if (ep->e_wiomode != NFSD_IO_UNSET)
+				c = dumpopt(c, "wiomode=%s",
+					    iomode_name(ep->e_wiomode));
 			if (ep->e_flags & NFSEXP_FSID)
 				c = dumpopt(c, "fsid=%d", ep->e_fsid);
 			if (ep->e_uuid)
utils/exportfs/exports.man +22 -0
index 7f0278fb8d33..2dfb12c6a4db 100644
@@ -477,6 +477,28 @@ devices. The default can be explicitly requested with the
 .I no_pnfs
 option.
 
+.TP
+.IR riomode= buffered|dontcache|direct
+This option selects the I/O mode the server uses for NFS READ requests
+to this export:
+.I buffered
+uses the page cache,
+.I dontcache
+uses the page cache but drops the data behind on completion, and
+.I direct
+uses direct I/O.
+If the option is not specified, the export follows the server's global
+setting, which defaults to
+.IR buffered .
+If the kernel does not support per-export I/O modes, the option is
+ignored and a warning is logged.
+
+.TP
+.IR wiomode= buffered|dontcache|direct
+This option selects the I/O mode the server uses for NFS WRITE requests
+to this export, with the same values and default as
+.IR riomode= .
+
 .TP
 .IR security_label
 With this option set, clients using NFSv4.2 or higher will be able to
Signature · 1 line
2.56.0
author maintainer
#4 lore raw

PATCH 4/4 nfsd-iomode-advisor: recommend riomode= and wiomode= for an export

In reply to Jeff Layton

Admins cannot easily tell which NFSD IO mode suits an export. Add a tool that samples metrics while clients use the export, and recommends buffered, dontcache, or direct for READ and WRITE, with reasons.

Metrics:
- miss ratio: export_stats io_read_storage / io_read. Without
io_read_storage: block device read bytes / io_read of its exports.
- reclaim vs. the export's storage traffic, direct reclaim share, refaults, memory PSI. The tool subtracts cgroups at memory.high or memory.max (not system memory pressure).
- CPU time of the busiest kswapd or kcompactd thread
- Dirty and Writeback vs. the background writeback threshold, sampled each second, from /sys/kernel/debug/bdi or /proc/meminfo
- free memory vs. zone high watermarks, to find a page cache that is not full yet
- average READ (incl. READ_PLUS) and WRITE size from /proc/net/rpc/nfsd
- optional cachestat(2) of the export's largest files

Thresholds are ratios, or relative to export traffic, kernel limits, or storage, so they do not change with server size.
- large-memory servers with slow storage never reclaim a large fraction per minute
- kswapd CPU sums scale with NUMA nodes
- stall counts scale with threads
- large servers often set vm.dirty_background_bytes

Mode limits:
- No mode that NFSD silently falls back from. The tool probes with preadv2(RWF_DONTCACHE) and statx(STATX_DIOALIGN).
- No wiomode=direct when the block device needs more than the 4-byte memory alignment of TCP WRITE data (e.g. device mapper, MD).
- No direct IO on rotational storage.
- Buffered IO for WRITEs smaller than optimal_io_size (e.g. parity RAID stripe width).

Caveats:
- Miss ratio is valid only with buffered IO. Otherwise, or if the mode is not readable, the tool reports "unknown".
- io_read_storage counts only reads that NFSD threads submit. The tool ignores it on filesystems that read from their own threads (FUSE, ZFS), and flags it when the block device reads much more.
- export_stats counters persist across cache updates. The tool skips entries that appear with older counters or leave the cache during the interval, and flags the result incomplete.
- export_stats lists an export only after first client use. The tool also accepts an etab export and reads riomode=/wiomode= from etab.

---
 configure.ac                                      |    1 +
 tools/Makefile.am                                 |    2 +-
 tools/nfsd-iomode-advisor/Makefile.am             |   14 +
 tools/nfsd-iomode-advisor/nfsd-iomode-advisor.man |  232 ++++
 tools/nfsd-iomode-advisor/nfsd-iomode-advisor.py  | 1198 +++++++++++++++++++++
 5 files changed, 1446 insertions(+), 1 deletion(-)
configure.ac +1 -0
index ff752b8bd17f..277cbc2bd109 100644
@@ -779,6 +779,7 @@ AC_CONFIG_FILES([
 	tools/nfsrahead/Makefile
 	tools/rpcctl/Makefile
 	tools/nfsdclnts/Makefile
+	tools/nfsd-iomode-advisor/Makefile
 	tools/nfsconf/Makefile
 	tools/nfsdclddb/Makefile
 	utils/Makefile
tools/Makefile.am +1 -1
index 48fd0cdf1f83..817bf34f0ea6 100644
@@ -16,6 +16,6 @@ if CONFIG_NFSRAHEAD
 OPTDIRS += nfsrahead
 endif
 
-SUBDIRS = locktest rpcdebug nlmtest mountstats nfs-iostat rpcctl nfsdclnts $(OPTDIRS)
+SUBDIRS = locktest rpcdebug nlmtest mountstats nfs-iostat rpcctl nfsdclnts nfsd-iomode-advisor $(OPTDIRS)
 
 MAINTAINERCLEANFILES = Makefile.in
tools/nfsd-iomode-advisor/Makefile.am new file +14 -0
new file mode 100644
index 000000000000..fe97e0ac66c8
@@ -0,0 +1,14 @@
+## Process this file with automake to produce Makefile.in
+PYTHON_FILES = nfsd-iomode-advisor.py
+
+man8_MANS       = nfsd-iomode-advisor.man
+
+EXTRA_DIST      = $(man8_MANS) $(PYTHON_FILES)
+
+all-local: $(PYTHON_FILES)
+
+install-data-hook:
+	$(MKDIR_P) $(DESTDIR)$(sbindir)
+	$(INSTALL) -m 755 nfsd-iomode-advisor.py $(DESTDIR)$(sbindir)/nfsd-iomode-advisor
+
+MAINTAINERCLEANFILES=Makefile.in
tools/nfsd-iomode-advisor/nfsd-iomode-advisor.man new file +232 -0

232 lines not on this page · raw message

tools/nfsd-iomode-advisor/nfsd-iomode-advisor.py new file +1198 -0

1,198 lines not on this page · raw message

Signature · 1 line
2.56.0