exports: add support for new read_io= and write_io= export options
Subsystems (2)
Jeff Layton
maintainerv2 cover exports: add support for new read_io= and write_io= export options
This is the companion patch series to [1]. Chuck suggested we change the export options to read_io= and write_io=. That's the only real change in this version.
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. I did test it on a range of different machine types and it seemed to do the right thing.
[1]: https://lore.kernel.org/linux-nfs/[email protected]/
---
Changes in v2:
- Rename riomode=/wiomode= to read_io=/write_io= to match the kernel series.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Jeff Layton (4):
exportfs/mountd/exportd: track the svc_export policy highest attribute
exports: Add read_io= and write_io= export options
exportfs: Display and document read_io= and write_io=
nfsd-iomode-advisor: recommend read_io= and write_io= 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]>
Jeff Layton
maintainerPATCH v2 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
@@ -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
@@ -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
Jeff Layton
maintainerPATCH v2 2/4 exports: Add read_io= and write_io= export options
In reply to Jeff LaytonParse read_io=/write_io= (buffered/dontcache/direct) into new e_read_io/e_write_io exportent fields, defaulting to unset, and pass explicitly-set values to the kernel over the netlink svc_export interface.
- Kernels without the I/O mode 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_IO.
--- 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
@@ -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_IO;]])], [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
@@ -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 read_io/write_io, 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_IO ; +} +/** * nfsd_nl_load_export_features - learn the kernel's export flags over netlink *
support/export/v4root.c +2 -0
@@ -47,6 +47,8 @@ static nfs_export pseudo_root = { .e_fsid = 0, .e_mountpoint = NULL, .e_ttl = 0, + .e_read_io = NFSD_IO_UNSET, + .e_write_io = NFSD_IO_UNSET, }, .m_exported = 0, .m_xtabent = 1,
support/include/exportfs.h +1 -0
@@ -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
@@ -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_IO , +NFSD_A_SVC_EXPORT_WRITE_IO , __NFSD_A_SVC_EXPORT_MAX,NFSD_A_SVC_EXPORT_MAX = (__NFSD_A_SVC_EXPORT_MAX -1 )
support/include/nfslib.h +13 -0
@@ -75,6 +75,16 @@ struct xprtsec_entry {int flags; }; +/* +* Per-export I/O modes for read_io=/write_io=. 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_read_io; +int e_write_io; };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
Jeff Layton
maintainerPATCH v2 3/4 exportfs: Display and document read_io= and write_io=
In reply to Jeff LaytonShow 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
@@ -79,6 +79,7 @@ struct xprtsec_entry {* Per-export I/O modes for read_io=/write_io=. 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
@@ -614,6 +614,32 @@ try_proc:return 1 ; } +/* +* mountd passes read_io= and write_io= 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_read_io ==NFSD_IO_UNSET && + exp->m_export.e_write_io ==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 read_io= and write_io=: %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_read_io !=NFSD_IO_UNSET ) + c =dumpopt (c,"read_io=%s" , +iomode_name (ep->e_read_io)); +if (ep->e_write_io !=NFSD_IO_UNSET ) + c =dumpopt (c,"write_io=%s" , +iomode_name (ep->e_write_io));if (ep->e_flags &NFSEXP_FSID ) c =dumpopt (c,"fsid=%d" , ep->e_fsid);if (ep->e_uuid)
utils/exportfs/exports.man +22 -0
@@ -477,6 +477,28 @@ devices. The default can be explicitly requested with the .I no_pnfs option. +.TP +.IR read_io= 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 write_io= 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 read_io= . + .TP .IR security_label With this option set, clients using NFSv4.2 or higher will be able to
Signature · 1 line
2.56.0
Jeff Layton
maintainerPATCH v2 4/4 nfsd-iomode-advisor: recommend read_io= and write_io= for an export
In reply to Jeff LaytonAdmins 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 write_io=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 read_io=/write_io= 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
@@ -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
@@ -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
@@ -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
Quoted 43 lines · Jeff Layton
This is the companion patch series to [1]. Chuck suggested we change the export options to read_io= and write_io=. That's the only real change in this version.
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. I did test it on a range of different machine types and it seemed to do the right thing.
[1]: https://lore.kernel.org/linux-nfs/[email protected]/
Signed-off-by Jeff Layton <[email protected]>---
Changes in v2:
- Rename riomode=/wiomode= to read_io=/write_io= to match the kernel series.
- Link to v1: https://lore.kernel.org/r/[email protected]---
Jeff Layton (4):
exportfs/mountd/exportd: track thesvc_exportpolicy highest attribute
exports: Add read_io= and write_io= export options
exportfs: Display and document read_io= and write_io=
nfsd-iomode-advisor: recommend read_io= and write_io= for an exportconfigure.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(-)
Quoted 5 lines
---
base-commit:0ed4324cbbb8020039d338d597c1422a980f7085
change-id: 20261014-master-b5afd69e3772Best regards,
Committed... (tag: nfs-utils-3-1-2.rc3)
steved