From 8497b9348fbbc5a8e7612a390f3b43b40bf4a722 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 23 Jan 2015 11:28:15 -0800 Subject: [PATCH] pxeboot - Add option to improve NFS performance * Allow nfs.read_size=N to be specified in /boot/loader.conf (1024-4096 allowed). This allows the pxe server to tell the pxeboot code to use larger NFS data packets, significantly reducing kernel binary and module load times. --- etc/rc.d/initdiskless | 2 +- lib/libstand/nfs.c | 32 ++++++++++++++++++++++++++------ sys/boot/pc32/pxeldr/pxeboot.8 | 9 +++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/etc/rc.d/initdiskless b/etc/rc.d/initdiskless index 5601680550..830b7feb56 100644 --- a/etc/rc.d/initdiskless +++ b/etc/rc.d/initdiskless @@ -227,7 +227,7 @@ for i in base default ${bootp_ipbca} ${bootp_ipa} ; do done done -# - Create all required MFS filesystems and populate them from +# - Create all required TMPFS filesystems and populate them from # our templates. Support both a direct template and a dir.cpio.gz # archive. Support dir.remove files containing a list of relative # paths to remove. diff --git a/lib/libstand/nfs.c b/lib/libstand/nfs.c index b4cf58ac5d..39dd8361f0 100644 --- a/lib/libstand/nfs.c +++ b/lib/libstand/nfs.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -74,13 +75,19 @@ struct nfs_read_args { n_long xxx; /* XXX what's this for? */ }; -/* Data part of nfs rpc reply (also the largest thing we receive) */ -#define NFSREAD_SIZE 1024 +/* + * Data part of nfs rpc reply (also the largest thing we receive). + * Worry about the size of the structure declared on the stack. + */ + +#define NFSREAD_MIN_SIZE 1024 +#define NFSREAD_MAX_SIZE 4096 + struct nfs_read_repl { n_long errno; struct nfsv2_fattrs fa; n_long count; - u_char data[NFSREAD_SIZE]; + u_char data[NFSREAD_MAX_SIZE]; }; #ifndef NFS_NOSYMLINK @@ -140,6 +147,8 @@ struct fs_ops nfs_fsops = { nfs_readdir }; +static int nfs_read_size = NFSREAD_MIN_SIZE; + /* * Fetch the root file handle (call mount daemon) * Return zero or error number. @@ -193,6 +202,17 @@ nfs_getrootfh(struct iodesc *d, char *path, u_char *fhp) if (repl->errno) return (ntohl(repl->errno)); bcopy(repl->fh, fhp, sizeof(repl->fh)); + + /* + * Improve boot performance over NFS + */ + if (getenv("nfs.read_size") != NULL) + nfs_read_size = strtol(getenv("nfs.read_size"), NULL, 0); + if (nfs_read_size < NFSREAD_MIN_SIZE) + nfs_read_size = NFSREAD_MIN_SIZE; + if (nfs_read_size > NFSREAD_MAX_SIZE) + nfs_read_size = NFSREAD_MAX_SIZE; + return (0); } @@ -330,11 +350,11 @@ nfs_readdata(struct nfs_iodesc *d, off_t off, void *addr, size_t len) bcopy(d->fh, args->fh, NFS_FHSIZE); args->off = htonl((n_long)off); - if (len > NFSREAD_SIZE) - len = NFSREAD_SIZE; + if (len > nfs_read_size) + len = nfs_read_size; args->len = htonl((n_long)len); args->xxx = htonl((n_long)0); - hlen = sizeof(*repl) - NFSREAD_SIZE; + hlen = offsetof(struct nfs_read_repl, data[0]); cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READ, args, sizeof(*args), diff --git a/sys/boot/pc32/pxeldr/pxeboot.8 b/sys/boot/pc32/pxeldr/pxeboot.8 index 45a68ad1b9..cc31041cb8 100644 --- a/sys/boot/pc32/pxeldr/pxeboot.8 +++ b/sys/boot/pc32/pxeldr/pxeboot.8 @@ -73,6 +73,15 @@ subnet 10.0.0.0 netmask 255.255.255.0 { .Ed .Nm +defaults to a conservative 1024 byte NFS data packet. This may be changed +by setting the +.Va nfs.read_size +variable in +.Pa /boot/loader.conf +.. +Valid values range from 1024 to 4096 bytes. +.Pp +.Nm recognizes .Va next-server and -- 2.41.0