svn commit: r251641 - in stable/9/sys: conf fs/nfs fs/nfsclient fs/nfsserver modules/nfsd modules/nfsserver nfs nfsserver
Kenneth D. Merry
ken at FreeBSD.org
Tue Jun 11 23:19:06 UTC 2013
Author: ken
Date: Tue Jun 11 23:19:02 2013
New Revision: 251641
URL: http://svnweb.freebsd.org/changeset/base/251641
Log:
MFC NFS FHA changes 249592 and 249596:
------------------------------------------------------------------------
r249592 | ken | 2013-04-17 15:00:22 -0600 (Wed, 17 Apr 2013) | 180 lines
Revamp the old NFS server's File Handle Affinity (FHA) code so that
it will work with either the old or new server.
The FHA code keeps a cache of currently active file handles for
NFSv2 and v3 requests, so that read and write requests for the same
file are directed to the same group of threads (reads) or thread
(writes). It does not currently work for NFSv4 requests. They are
more complex, and will take more work to support.
This improves read-ahead performance, especially with ZFS, if the
FHA tuning parameters are configured appropriately. Without the
FHA code, concurrent reads that are part of a sequential read from
a file will be directed to separate NFS threads. This has the
effect of confusing the ZFS zfetch (prefetch) code and makes
sequential reads significantly slower with clients like Linux that
do a lot of prefetching.
The FHA code has also been updated to direct write requests to nearby
file offsets to the same thread in the same way it batches reads,
and the FHA code will now also send writes to multiple threads when
needed.
This improves sequential write performance in ZFS, because writes
to a file are now more ordered. Since NFS writes (generally
less than 64K) are smaller than the typical ZFS record size
(usually 128K), out of order NFS writes to the same block can
trigger a read in ZFS. Sending them down the same thread increases
the odds of their being in order.
In order for multiple write threads per file in the FHA code to be
useful, writes in the NFS server have been changed to use a LK_SHARED
vnode lock, and upgrade that to LK_EXCLUSIVE if the filesystem
doesn't allow multiple writers to a file at once. ZFS is currently
the only filesystem that allows multiple writers to a file, because
it has internal file range locking. This change does not affect the
NFSv4 code.
This improves random write performance to a single file in ZFS, since
we can now have multiple writers inside ZFS at one time.
I have changed the default tuning parameters to a 22 bit (4MB)
window size (from 256K) and unlimited commands per thread as a
result of my benchmarking with ZFS.
The FHA code has been updated to allow configuring the tuning
parameters from loader tunable variables in addition to sysctl
variables. The read offset window calculation has been slightly
modified as well. Instead of having separate bins, each file
handle has a rolling window of bin_shift size. This minimizes
glitches in throughput when shifting from one bin to another.
sys/conf/files:
Add nfs_fha_new.c and nfs_fha_old.c. Compile nfs_fha.c
when either the old or the new NFS server is built.
sys/fs/nfs/nfsport.h,
sys/fs/nfs/nfs_commonport.c:
Bring in changes from Rick Macklem to newnfs_realign that
allow it to operate in blocking (M_WAITOK) or non-blocking
(M_NOWAIT) mode.
sys/fs/nfs/nfs_commonsubs.c,
sys/fs/nfs/nfs_var.h:
Bring in a change from Rick Macklem to allow telling
nfsm_dissect() whether or not to wait for mallocs.
sys/fs/nfs/nfsm_subs.h:
Bring in changes from Rick Macklem to create a new
nfsm_dissect_nonblock() inline function and
NFSM_DISSECT_NONBLOCK() macro.
sys/fs/nfs/nfs_commonkrpc.c,
sys/fs/nfsclient/nfs_clkrpc.c:
Add the malloc wait flag to a newnfs_realign() call.
sys/fs/nfsserver/nfs_nfsdkrpc.c:
Setup the new NFS server's RPC thread pool so that it will
call the FHA code.
Add the malloc flag argument to newnfs_realign().
Unstaticize newnfs_nfsv3_procid[] so that we can use it in
the FHA code.
sys/fs/nfsserver/nfs_nfsdsocket.c:
In nfsrvd_dorpc(), add NFSPROC_WRITE to the list of RPC types
that use the LK_SHARED lock type.
sys/fs/nfsserver/nfs_nfsdport.c:
In nfsd_fhtovp(), if we're starting a write, check to see
whether the underlying filesystem supports shared writes.
If not, upgrade the lock type from LK_SHARED to LK_EXCLUSIVE.
sys/nfsserver/nfs_fha.c:
Remove all code that is specific to the NFS server
implementation. Anything that is server-specific is now
accessed through a callback supplied by that server's FHA
shim in the new softc.
There are now separate sysctls and tunables for the FHA
implementations for the old and new NFS servers. The new
NFS server has its tunables under vfs.nfsd.fha, the old
NFS server's tunables are under vfs.nfsrv.fha as before.
In fha_extract_info(), use callouts for all server-specific
code. Getting file handles and offsets is now done in the
individual server's shim module.
In fha_hash_entry_choose_thread(), change the way we decide
whether two reads are in proximity to each other.
Previously, the calculation was a simple shift operation to
see whether the offsets were in the same power of 2 bucket.
The issue was that there would be a bucket (and therefore
thread) transition, even if the reads were in close
proximity. When there is a thread transition, reads wind
up going somewhat out of order, and ZFS gets confused.
The new calculation simply tries to see whether the offsets
are within 1 << bin_shift of each other. If they are, the
reads will be sent to the same thread.
The effect of this change is that for sequential reads, if
the client doesn't exceed the max_reqs_per_nfsd parameter
and the bin_shift is set to a reasonable value (22, or
4MB works well in my tests), the reads in any sequential
stream will largely be confined to a single thread.
Change fha_assign() so that it takes a softc argument. It
is now called from the individual server's shim code, which
will pass in the softc.
Change fhe_stats_sysctl() so that it takes a softc
parameter. It is now called from the individual server's
shim code. Add the current offset to the list of things
printed out about each active thread.
Change the num_reads and num_writes counters in the
fha_hash_entry structure to 32-bit values, and rename them
num_rw and num_exclusive, respectively, to reflect their
changed usage.
Add an enable sysctl and tunable that allows the user to
disable the FHA code (when vfs.XXX.fha.enable = 0). This
is useful for before/after performance comparisons.
nfs_fha.h:
Move most structure definitions out of nfs_fha.c and into
the header file, so that the individual server shims can
see them.
Change the default bin_shift to 22 (4MB) instead of 18
(256K). Allow unlimited commands per thread.
sys/nfsserver/nfs_fha_old.c,
sys/nfsserver/nfs_fha_old.h,
sys/fs/nfsserver/nfs_fha_new.c,
sys/fs/nfsserver/nfs_fha_new.h:
Add shims for the old and new NFS servers to interface with
the FHA code, and callbacks for the
The shims contain all of the code and definitions that are
specific to the NFS servers.
They setup the server-specific callbacks and set the server
name for the sysctl and loader tunable variables.
sys/nfsserver/nfs_srvkrpc.c:
Configure the RPC code to call fhaold_assign() instead of
fha_assign().
sys/modules/nfsd/Makefile:
Add nfs_fha.c and nfs_fha_new.c.
sys/modules/nfsserver/Makefile:
Add nfs_fha_old.c.
Reviewed by: rmacklem
Sponsored by: Spectra Logic
------------------------------------------------------------------------
r249596 | ken | 2013-04-17 16:42:43 -0600 (Wed, 17 Apr 2013) | 7 lines
Move the NFS FHA (File Handle Affinity) code from sys/nfsserver to
sys/nfs, since it is now shared by the two NFS servers.
Suggested by: rmacklem
Sponsored by: Spectra Logic
------------------------------------------------------------------------
Sponsored by: Spectra Logic
Added:
stable/9/sys/fs/nfsserver/nfs_fha_new.c
- copied, changed from r249592, head/sys/fs/nfsserver/nfs_fha_new.c
stable/9/sys/fs/nfsserver/nfs_fha_new.h
- copied unchanged from r249592, head/sys/fs/nfsserver/nfs_fha_new.h
stable/9/sys/nfs/nfs_fha.c
- copied unchanged from r249596, head/sys/nfs/nfs_fha.c
stable/9/sys/nfs/nfs_fha.h
- copied unchanged from r249596, head/sys/nfs/nfs_fha.h
stable/9/sys/nfsserver/nfs_fha_old.c
- copied, changed from r249592, head/sys/nfsserver/nfs_fha_old.c
stable/9/sys/nfsserver/nfs_fha_old.h
- copied unchanged from r249592, head/sys/nfsserver/nfs_fha_old.h
Deleted:
stable/9/sys/nfsserver/nfs_fha.c
stable/9/sys/nfsserver/nfs_fha.h
Modified:
stable/9/sys/conf/files
stable/9/sys/fs/nfs/nfs_commonkrpc.c
stable/9/sys/fs/nfs/nfs_commonport.c
stable/9/sys/fs/nfs/nfs_commonsubs.c
stable/9/sys/fs/nfs/nfs_var.h
stable/9/sys/fs/nfs/nfsm_subs.h
stable/9/sys/fs/nfs/nfsport.h
stable/9/sys/fs/nfsclient/nfs_clkrpc.c
stable/9/sys/fs/nfsserver/nfs_nfsdkrpc.c
stable/9/sys/fs/nfsserver/nfs_nfsdport.c
stable/9/sys/fs/nfsserver/nfs_nfsdsocket.c
stable/9/sys/modules/nfsd/Makefile
stable/9/sys/modules/nfsserver/Makefile
stable/9/sys/nfsserver/nfs_srvkrpc.c
Directory Properties:
stable/9/sys/ (props changed)
stable/9/sys/conf/ (props changed)
stable/9/sys/fs/ (props changed)
stable/9/sys/modules/ (props changed)
Modified: stable/9/sys/conf/files
==============================================================================
--- stable/9/sys/conf/files Tue Jun 11 21:47:16 2013 (r251640)
+++ stable/9/sys/conf/files Tue Jun 11 23:19:02 2013 (r251641)
@@ -2169,6 +2169,7 @@ fs/nfsclient/nfs_clvfsops.c optional nfs
fs/nfsclient/nfs_clport.c optional nfscl
fs/nfsclient/nfs_clbio.c optional nfscl
fs/nfsclient/nfs_clnfsiod.c optional nfscl
+fs/nfsserver/nfs_fha_new.c optional nfsd inet
fs/nfsserver/nfs_nfsdsocket.c optional nfsd inet
fs/nfsserver/nfs_nfsdsubs.c optional nfsd inet
fs/nfsserver/nfs_nfsdstate.c optional nfsd inet
@@ -2991,6 +2992,7 @@ nfs/bootp_subr.c optional bootp nfsclie
nfs/krpc_subr.c optional bootp nfsclient | bootp nfscl
nfs/nfs_common.c optional nfsclient | nfsserver
nfs/nfs_diskless.c optional nfsclient nfs_root | nfscl nfs_root
+nfs/nfs_fha.c optional nfsserver | nfsd
nfs/nfs_lock.c optional nfsclient | nfscl | nfslockd | nfsd
nfsclient/nfs_bio.c optional nfsclient
nfsclient/nfs_node.c optional nfsclient
@@ -2999,7 +3001,7 @@ nfsclient/nfs_subs.c optional nfsclient
nfsclient/nfs_nfsiod.c optional nfsclient
nfsclient/nfs_vfsops.c optional nfsclient
nfsclient/nfs_vnops.c optional nfsclient
-nfsserver/nfs_fha.c optional nfsserver
+nfsserver/nfs_fha_old.c optional nfsserver
nfsserver/nfs_serv.c optional nfsserver
nfsserver/nfs_srvkrpc.c optional nfsserver
nfsserver/nfs_srvsubs.c optional nfsserver
Modified: stable/9/sys/fs/nfs/nfs_commonkrpc.c
==============================================================================
--- stable/9/sys/fs/nfs/nfs_commonkrpc.c Tue Jun 11 21:47:16 2013 (r251640)
+++ stable/9/sys/fs/nfs/nfs_commonkrpc.c Tue Jun 11 23:19:02 2013 (r251641)
@@ -771,7 +771,7 @@ tryagain:
* These could cause pointer alignment problems, so copy them to
* well aligned mbufs.
*/
- newnfs_realign(&nd->nd_mrep);
+ newnfs_realign(&nd->nd_mrep, M_WAITOK);
nd->nd_md = nd->nd_mrep;
nd->nd_dpos = NFSMTOD(nd->nd_md, caddr_t);
nd->nd_repstat = 0;
Modified: stable/9/sys/fs/nfs/nfs_commonport.c
==============================================================================
--- stable/9/sys/fs/nfs/nfs_commonport.c Tue Jun 11 21:47:16 2013 (r251640)
+++ stable/9/sys/fs/nfs/nfs_commonport.c Tue Jun 11 23:19:02 2013 (r251641)
@@ -126,11 +126,11 @@ static int nfssvc_call(struct thread *,
/*
* These architectures don't need re-alignment, so just return.
*/
-void
-newnfs_realign(struct mbuf **pm)
+int
+newnfs_realign(struct mbuf **pm, int how)
{
- return;
+ return (0);
}
#else /* !__NO_STRICT_ALIGNMENT */
/*
@@ -149,8 +149,8 @@ newnfs_realign(struct mbuf **pm)
* with TCP. Use vfs.nfs.realign_count and realign_test to check this.
*
*/
-void
-newnfs_realign(struct mbuf **pm)
+int
+newnfs_realign(struct mbuf **pm, int how)
{
struct mbuf *m, *n;
int off, space;
@@ -167,11 +167,11 @@ newnfs_realign(struct mbuf **pm)
space = m_length(m, NULL);
if (space >= MINCLSIZE) {
/* NB: m_copyback handles space > MCLBYTES */
- n = m_getcl(M_WAITOK, MT_DATA, 0);
+ n = m_getcl(how, MT_DATA, 0);
} else
- n = m_get(M_WAITOK, MT_DATA);
+ n = m_get(how, MT_DATA);
if (n == NULL)
- return;
+ return (ENOMEM);
/*
* Align the remainder of the mbuf chain.
*/
@@ -189,6 +189,8 @@ newnfs_realign(struct mbuf **pm)
}
pm = &m->m_next;
}
+
+ return (0);
}
#endif /* __NO_STRICT_ALIGNMENT */
Modified: stable/9/sys/fs/nfs/nfs_commonsubs.c
==============================================================================
--- stable/9/sys/fs/nfs/nfs_commonsubs.c Tue Jun 11 21:47:16 2013 (r251640)
+++ stable/9/sys/fs/nfs/nfs_commonsubs.c Tue Jun 11 23:19:02 2013 (r251641)
@@ -252,7 +252,7 @@ out:
* cases.
*/
APPLESTATIC void *
-nfsm_dissct(struct nfsrv_descript *nd, int siz)
+nfsm_dissct(struct nfsrv_descript *nd, int siz, int how)
{
mbuf_t mp2;
int siz2, xfer;
@@ -277,7 +277,9 @@ nfsm_dissct(struct nfsrv_descript *nd, i
} else if (siz > ncl_mbuf_mhlen) {
panic("nfs S too big");
} else {
- NFSMGET(mp2);
+ MGET(mp2, MT_DATA, how);
+ if (mp2 == NULL)
+ return (NULL);
mbuf_setnext(mp2, mbuf_next(nd->nd_md));
mbuf_setnext(nd->nd_md, mp2);
mbuf_setlen(nd->nd_md, mbuf_len(nd->nd_md) - left);
Modified: stable/9/sys/fs/nfs/nfs_var.h
==============================================================================
--- stable/9/sys/fs/nfs/nfs_var.h Tue Jun 11 21:47:16 2013 (r251640)
+++ stable/9/sys/fs/nfs/nfs_var.h Tue Jun 11 23:19:02 2013 (r251641)
@@ -232,7 +232,7 @@ int nfsm_strtom(struct nfsrv_descript *,
int nfsm_mbufuio(struct nfsrv_descript *, struct uio *, int);
int nfsm_fhtom(struct nfsrv_descript *, u_int8_t *, int, int);
int nfsm_advance(struct nfsrv_descript *, int, int);
-void *nfsm_dissct(struct nfsrv_descript *, int);
+void *nfsm_dissct(struct nfsrv_descript *, int, int);
void newnfs_trimleading(struct nfsrv_descript *);
void newnfs_trimtrailing(struct nfsrv_descript *, mbuf_t,
caddr_t);
Modified: stable/9/sys/fs/nfs/nfsm_subs.h
==============================================================================
--- stable/9/sys/fs/nfs/nfsm_subs.h Tue Jun 11 21:47:16 2013 (r251640)
+++ stable/9/sys/fs/nfs/nfsm_subs.h Tue Jun 11 23:19:02 2013 (r251641)
@@ -100,7 +100,23 @@ nfsm_dissect(struct nfsrv_descript *nd,
retp = (void *)nd->nd_dpos;
nd->nd_dpos += siz;
} else {
- retp = nfsm_dissct(nd, siz);
+ retp = nfsm_dissct(nd, siz, M_WAITOK);
+ }
+ return (retp);
+}
+
+static __inline void *
+nfsm_dissect_nonblock(struct nfsrv_descript *nd, int siz)
+{
+ int tt1;
+ void *retp;
+
+ tt1 = NFSMTOD(nd->nd_md, caddr_t) + nd->nd_md->m_len - nd->nd_dpos;
+ if (tt1 >= siz) {
+ retp = (void *)nd->nd_dpos;
+ nd->nd_dpos += siz;
+ } else {
+ retp = nfsm_dissct(nd, siz, M_NOWAIT);
}
return (retp);
}
@@ -113,6 +129,15 @@ nfsm_dissect(struct nfsrv_descript *nd,
goto nfsmout; \
} \
} while (0)
+
+#define NFSM_DISSECT_NONBLOCK(a, c, s) \
+ do { \
+ (a) = (c)nfsm_dissect_nonblock(nd, (s)); \
+ if ((a) == NULL) { \
+ error = EBADRPC; \
+ goto nfsmout; \
+ } \
+ } while (0)
#endif /* !APPLE */
#define NFSM_STRSIZ(s, m) \
Modified: stable/9/sys/fs/nfs/nfsport.h
==============================================================================
--- stable/9/sys/fs/nfs/nfsport.h Tue Jun 11 21:47:16 2013 (r251640)
+++ stable/9/sys/fs/nfs/nfsport.h Tue Jun 11 23:19:02 2013 (r251641)
@@ -730,7 +730,7 @@ MALLOC_DECLARE(M_NEWNFSDROLLBACK);
*/
int nfscl_loadattrcache(struct vnode **, struct nfsvattr *, void *, void *,
int, int);
-void newnfs_realign(struct mbuf **);
+int newnfs_realign(struct mbuf **, int);
/*
* If the port runs on an SMP box that can enforce Atomic ops with low
Modified: stable/9/sys/fs/nfsclient/nfs_clkrpc.c
==============================================================================
--- stable/9/sys/fs/nfsclient/nfs_clkrpc.c Tue Jun 11 21:47:16 2013 (r251640)
+++ stable/9/sys/fs/nfsclient/nfs_clkrpc.c Tue Jun 11 23:19:02 2013 (r251641)
@@ -82,7 +82,7 @@ nfscb_program(struct svc_req *rqst, SVCX
*/
nd.nd_mrep = rqst->rq_args;
rqst->rq_args = NULL;
- newnfs_realign(&nd.nd_mrep);
+ newnfs_realign(&nd.nd_mrep, M_WAITOK);
nd.nd_md = nd.nd_mrep;
nd.nd_dpos = mtod(nd.nd_md, caddr_t);
nd.nd_nam = svc_getrpccaller(rqst);
Copied and modified: stable/9/sys/fs/nfsserver/nfs_fha_new.c (from r249592, head/sys/fs/nfsserver/nfs_fha_new.c)
==============================================================================
--- head/sys/fs/nfsserver/nfs_fha_new.c Wed Apr 17 21:00:22 2013 (r249592, copy source)
+++ stable/9/sys/fs/nfsserver/nfs_fha_new.c Tue Jun 11 23:19:02 2013 (r251641)
@@ -30,11 +30,11 @@ __FBSDID("$FreeBSD$");
#include <fs/nfs/nfsport.h>
#include <rpc/rpc.h>
+#include <nfs/nfs_fha.h>
#include <fs/nfs/xdr_subs.h>
#include <fs/nfs/nfs.h>
#include <fs/nfs/nfsproto.h>
#include <fs/nfs/nfsm_subs.h>
-#include <nfsserver/nfs_fha.h>
#include <fs/nfsserver/nfs_fha_new.h>
static void fhanew_init(void *foo);
Copied: stable/9/sys/fs/nfsserver/nfs_fha_new.h (from r249592, head/sys/fs/nfsserver/nfs_fha_new.h)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ stable/9/sys/fs/nfsserver/nfs_fha_new.h Tue Jun 11 23:19:02 2013 (r251641, copy of r249592, head/sys/fs/nfsserver/nfs_fha_new.h)
@@ -0,0 +1,39 @@
+/*-
+ * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
+ * Copyright (c) 2013 Spectra Logic Corporation
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/* $FreeBSD$ */
+
+#ifndef _NFS_FHA_NEW_H
+#define _NFS_FHA_NEW_H 1
+
+#ifdef _KERNEL
+
+#define FHANEW_SERVER_NAME "nfsd"
+
+SVCTHREAD *fhanew_assign(SVCTHREAD *this_thread, struct svc_req *req);
+#endif /* _KERNEL */
+
+#endif /* _NFS_FHA_NEW_H */
Modified: stable/9/sys/fs/nfsserver/nfs_nfsdkrpc.c
==============================================================================
--- stable/9/sys/fs/nfsserver/nfs_nfsdkrpc.c Tue Jun 11 21:47:16 2013 (r251640)
+++ stable/9/sys/fs/nfsserver/nfs_nfsdkrpc.c Tue Jun 11 23:19:02 2013 (r251641)
@@ -42,6 +42,9 @@ __FBSDID("$FreeBSD$");
#include <rpc/rpc.h>
#include <rpc/rpcsec_gss.h>
+#include <nfs/nfs_fha.h>
+#include <fs/nfsserver/nfs_fha_new.h>
+
#include <security/mac/mac_framework.h>
NFSDLOCKMUTEX;
@@ -51,7 +54,7 @@ struct nfsv4lock nfsd_suspend_lock;
/*
* Mapping of old NFS Version 2 RPC numbers to generic numbers.
*/
-static int newnfs_nfsv3_procid[NFS_V3NPROCS] = {
+int newnfs_nfsv3_procid[NFS_V3NPROCS] = {
NFSPROC_NULL,
NFSPROC_GETATTR,
NFSPROC_SETATTR,
@@ -147,7 +150,7 @@ nfssvc_program(struct svc_req *rqst, SVC
*/
nd.nd_mrep = rqst->rq_args;
rqst->rq_args = NULL;
- newnfs_realign(&nd.nd_mrep);
+ newnfs_realign(&nd.nd_mrep, M_WAITOK);
nd.nd_md = nd.nd_mrep;
nd.nd_dpos = mtod(nd.nd_md, caddr_t);
nd.nd_nam = svc_getrpccaller(rqst);
@@ -491,8 +494,8 @@ nfsrvd_init(int terminating)
nfsrvd_pool = svcpool_create("nfsd", SYSCTL_STATIC_CHILDREN(_vfs_nfsd));
nfsrvd_pool->sp_rcache = NULL;
- nfsrvd_pool->sp_assign = NULL;
- nfsrvd_pool->sp_done = NULL;
+ nfsrvd_pool->sp_assign = fhanew_assign;
+ nfsrvd_pool->sp_done = fha_nd_complete;
NFSD_LOCK();
}
Modified: stable/9/sys/fs/nfsserver/nfs_nfsdport.c
==============================================================================
--- stable/9/sys/fs/nfsserver/nfs_nfsdport.c Tue Jun 11 21:47:16 2013 (r251640)
+++ stable/9/sys/fs/nfsserver/nfs_nfsdport.c Tue Jun 11 23:19:02 2013 (r251641)
@@ -2707,9 +2707,11 @@ nfsd_fhtovp(struct nfsrv_descript *nd, s
goto out;
}
- if (startwrite)
+ if (startwrite) {
vn_start_write(NULL, mpp, V_WAIT);
-
+ if (lktype == LK_SHARED && !(MNT_SHARED_WRITES(mp)))
+ lktype = LK_EXCLUSIVE;
+ }
nd->nd_repstat = nfsvno_fhtovp(mp, fhp, nd->nd_nam, lktype, vpp, exp,
&credanon);
vfs_unbusy(mp);
Modified: stable/9/sys/fs/nfsserver/nfs_nfsdsocket.c
==============================================================================
--- stable/9/sys/fs/nfsserver/nfs_nfsdsocket.c Tue Jun 11 21:47:16 2013 (r251640)
+++ stable/9/sys/fs/nfsserver/nfs_nfsdsocket.c Tue Jun 11 23:19:02 2013 (r251641)
@@ -379,6 +379,7 @@ nfsrvd_dorpc(struct nfsrv_descript *nd,
goto out;
}
if (nd->nd_procnum == NFSPROC_READ ||
+ nd->nd_procnum == NFSPROC_WRITE ||
nd->nd_procnum == NFSPROC_READDIR ||
nd->nd_procnum == NFSPROC_READLINK ||
nd->nd_procnum == NFSPROC_GETATTR ||
Modified: stable/9/sys/modules/nfsd/Makefile
==============================================================================
--- stable/9/sys/modules/nfsd/Makefile Tue Jun 11 21:47:16 2013 (r251640)
+++ stable/9/sys/modules/nfsd/Makefile Tue Jun 11 23:19:02 2013 (r251641)
@@ -1,8 +1,10 @@
# $FreeBSD$
-.PATH: ${.CURDIR}/../../fs/nfsserver
+.PATH: ${.CURDIR}/../../fs/nfsserver ${.CURDIR}/../../nfs
KMOD= nfsd
SRCS= vnode_if.h \
+ nfs_fha.c \
+ nfs_fha_new.c \
nfs_nfsdserv.c \
nfs_nfsdcache.c \
nfs_nfsdkrpc.c \
Modified: stable/9/sys/modules/nfsserver/Makefile
==============================================================================
--- stable/9/sys/modules/nfsserver/Makefile Tue Jun 11 21:47:16 2013 (r251640)
+++ stable/9/sys/modules/nfsserver/Makefile Tue Jun 11 23:19:02 2013 (r251641)
@@ -1,9 +1,9 @@
# $FreeBSD$
-.PATH: ${.CURDIR}/../../nfsserver
+.PATH: ${.CURDIR}/../../nfsserver ${.CURDIR}/../../nfs
KMOD= nfsserver
SRCS= vnode_if.h \
- nfs_fha.c nfs_serv.c nfs_srvkrpc.c nfs_srvsubs.c \
+ nfs_fha.c nfs_fha_old.c nfs_serv.c nfs_srvkrpc.c nfs_srvsubs.c \
opt_mac.h \
opt_kgssapi.h \
opt_nfs.h
Copied: stable/9/sys/nfs/nfs_fha.c (from r249596, head/sys/nfs/nfs_fha.c)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ stable/9/sys/nfs/nfs_fha.c Tue Jun 11 23:19:02 2013 (r251641, copy of r249596, head/sys/nfs/nfs_fha.c)
@@ -0,0 +1,556 @@
+/*-
+ * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/sysproto.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/vnode.h>
+#include <sys/malloc.h>
+#include <sys/mount.h>
+#include <sys/mbuf.h>
+#include <sys/sbuf.h>
+
+#include <rpc/rpc.h>
+#include <nfs/nfs_fha.h>
+
+static MALLOC_DEFINE(M_NFS_FHA, "NFS FHA", "NFS FHA");
+
+/*
+ * XXX need to commonize definitions between old and new NFS code. Define
+ * this here so we don't include one nfsproto.h over the other.
+ */
+#define NFS_PROG 100003
+
+void
+fha_init(struct fha_params *softc)
+{
+ char tmpstr[128];
+
+ /*
+ * A small hash table to map filehandles to fha_hash_entry
+ * structures.
+ */
+ softc->g_fha.hashtable = hashinit(256, M_NFS_FHA,
+ &softc->g_fha.hashmask);
+
+ /*
+ * Set the default tuning parameters.
+ */
+ softc->ctls.enable = FHA_DEF_ENABLE;
+ softc->ctls.bin_shift = FHA_DEF_BIN_SHIFT;
+ softc->ctls.max_nfsds_per_fh = FHA_DEF_MAX_NFSDS_PER_FH;
+ softc->ctls.max_reqs_per_nfsd = FHA_DEF_MAX_REQS_PER_NFSD;
+
+ /*
+ * Allow the user to override the defaults at boot time with
+ * tunables.
+ */
+ snprintf(tmpstr, sizeof(tmpstr), "vfs.%s.fha.enable",
+ softc->server_name);
+ TUNABLE_INT_FETCH(tmpstr, &softc->ctls.enable);
+ snprintf(tmpstr, sizeof(tmpstr), "vfs.%s.fha.bin_shift",
+ softc->server_name);
+ TUNABLE_INT_FETCH(tmpstr, &softc->ctls.bin_shift);
+ snprintf(tmpstr, sizeof(tmpstr), "vfs.%s.fha.max_nfsds_per_fh",
+ softc->server_name);
+ TUNABLE_INT_FETCH(tmpstr, &softc->ctls.max_nfsds_per_fh);
+ snprintf(tmpstr, sizeof(tmpstr), "vfs.%s.fha.max_reqs_per_nfsd",
+ softc->server_name);
+ TUNABLE_INT_FETCH(tmpstr, &softc->ctls.max_reqs_per_nfsd);
+
+ /*
+ * Add sysctls so the user can change the tuning parameters at
+ * runtime.
+ */
+ SYSCTL_ADD_UINT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
+ OID_AUTO, "enable", CTLFLAG_RW,
+ &softc->ctls.enable, 0, "Enable NFS File Handle Affinity (FHA)");
+
+ SYSCTL_ADD_UINT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
+ OID_AUTO, "bin_shift", CTLFLAG_RW,
+ &softc->ctls.bin_shift, 0, "For FHA reads, no two requests will "
+ "contend if they're 2^(bin_shift) bytes apart");
+
+ SYSCTL_ADD_UINT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
+ OID_AUTO, "max_nfsds_per_fh", CTLFLAG_RW,
+ &softc->ctls.max_nfsds_per_fh, 0, "Maximum nfsd threads that "
+ "should be working on requests for the same file handle");
+
+ SYSCTL_ADD_UINT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
+ OID_AUTO, "max_reqs_per_nfsd", CTLFLAG_RW,
+ &softc->ctls.max_reqs_per_nfsd, 0, "Maximum requests that "
+ "single nfsd thread should be working on at any time");
+
+ SYSCTL_ADD_OID(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
+ OID_AUTO, "fhe_stats", CTLTYPE_STRING | CTLFLAG_RD, 0, 0,
+ softc->callbacks.fhe_stats_sysctl, "A", "");
+
+}
+
+void
+fha_uninit(struct fha_params *softc)
+{
+ sysctl_ctx_free(&softc->sysctl_ctx);
+ hashdestroy(softc->g_fha.hashtable, M_NFS_FHA, softc->g_fha.hashmask);
+}
+
+/*
+ * This just specifies that offsets should obey affinity when within
+ * the same 1Mbyte (1<<20) chunk for the file (reads only for now).
+ */
+static void
+fha_extract_info(struct svc_req *req, struct fha_info *i,
+ struct fha_callbacks *cb)
+{
+ struct mbuf *md;
+ fhandle_t fh;
+ caddr_t dpos;
+ static u_int64_t random_fh = 0;
+ int error;
+ int v3 = (req->rq_vers == 3);
+ rpcproc_t procnum;
+
+ /*
+ * We start off with a random fh. If we get a reasonable
+ * procnum, we set the fh. If there's a concept of offset
+ * that we're interested in, we set that.
+ */
+ i->fh = ++random_fh;
+ i->offset = 0;
+ i->locktype = LK_EXCLUSIVE;
+
+ /*
+ * Extract the procnum and convert to v3 form if necessary,
+ * taking care to deal with out-of-range procnums. Caller will
+ * ensure that rq_vers is either 2 or 3.
+ */
+ procnum = req->rq_proc;
+ if (!v3) {
+ rpcproc_t tmp_procnum;
+
+ tmp_procnum = cb->get_procnum(procnum);
+ if (tmp_procnum == -1)
+ goto out;
+ procnum = tmp_procnum;
+ }
+
+ /*
+ * We do affinity for most. However, we divide a realm of affinity
+ * by file offset so as to allow for concurrent random access. We
+ * only do this for reads today, but this may change when IFS supports
+ * efficient concurrent writes.
+ */
+ if (cb->no_offset(procnum))
+ goto out;
+
+ error = cb->realign(&req->rq_args, M_NOWAIT);
+ if (error)
+ goto out;
+ md = req->rq_args;
+ dpos = mtod(md, caddr_t);
+
+ /* Grab the filehandle. */
+ error = cb->get_fh(&fh, v3, &md, &dpos);
+ if (error)
+ goto out;
+
+ bcopy(fh.fh_fid.fid_data, &i->fh, sizeof(i->fh));
+
+ /* Content ourselves with zero offset for all but reads. */
+ if (cb->is_read(procnum) || cb->is_write(procnum))
+ cb->get_offset(&md, &dpos, v3, i);
+
+out:
+ cb->set_locktype(procnum, i);
+}
+
+static struct fha_hash_entry *
+fha_hash_entry_new(u_int64_t fh)
+{
+ struct fha_hash_entry *e;
+
+ e = malloc(sizeof(*e), M_NFS_FHA, M_WAITOK);
+ e->fh = fh;
+ e->num_rw = 0;
+ e->num_exclusive = 0;
+ e->num_threads = 0;
+ LIST_INIT(&e->threads);
+
+ return (e);
+}
+
+static void
+fha_hash_entry_destroy(struct fha_hash_entry *e)
+{
+
+ if (e->num_rw + e->num_exclusive)
+ panic("nonempty fhe");
+ free(e, M_NFS_FHA);
+}
+
+static void
+fha_hash_entry_remove(struct fha_hash_entry *e)
+{
+
+ LIST_REMOVE(e, link);
+ fha_hash_entry_destroy(e);
+}
+
+static struct fha_hash_entry *
+fha_hash_entry_lookup(struct fha_params *softc, u_int64_t fh)
+{
+ SVCPOOL *pool;
+
+ pool = *softc->pool;
+
+ struct fha_hash_entry *fhe, *new_fhe;
+
+ LIST_FOREACH(fhe, &softc->g_fha.hashtable[fh % softc->g_fha.hashmask],
+ link)
+ if (fhe->fh == fh)
+ break;
+
+ if (!fhe) {
+ /* Allocate a new entry. */
+ mtx_unlock(&pool->sp_lock);
+ new_fhe = fha_hash_entry_new(fh);
+ mtx_lock(&pool->sp_lock);
+
+ /* Double-check to make sure we still need the new entry. */
+ LIST_FOREACH(fhe,
+ &softc->g_fha.hashtable[fh % softc->g_fha.hashmask], link)
+ if (fhe->fh == fh)
+ break;
+ if (!fhe) {
+ fhe = new_fhe;
+ LIST_INSERT_HEAD(
+ &softc->g_fha.hashtable[fh % softc->g_fha.hashmask],
+ fhe, link);
+ } else
+ fha_hash_entry_destroy(new_fhe);
+ }
+
+ return (fhe);
+}
+
+static void
+fha_hash_entry_add_thread(struct fha_hash_entry *fhe, SVCTHREAD *thread)
+{
+
+ LIST_INSERT_HEAD(&fhe->threads, thread, st_alink);
+ fhe->num_threads++;
+}
+
+static void
+fha_hash_entry_remove_thread(struct fha_hash_entry *fhe, SVCTHREAD *thread)
+{
+
+ LIST_REMOVE(thread, st_alink);
+ fhe->num_threads--;
+}
+
+/*
+ * Account for an ongoing operation associated with this file.
+ */
+static void
+fha_hash_entry_add_op(struct fha_hash_entry *fhe, int locktype, int count)
+{
+
+ if (LK_EXCLUSIVE == locktype)
+ fhe->num_exclusive += count;
+ else
+ fhe->num_rw += count;
+}
+
+static SVCTHREAD *
+get_idle_thread(SVCPOOL *pool)
+{
+ SVCTHREAD *st;
+
+ LIST_FOREACH(st, &pool->sp_idlethreads, st_ilink) {
+ if (st->st_xprt == NULL && STAILQ_EMPTY(&st->st_reqs))
+ return (st);
+ }
+ return (NULL);
+}
+
+
+/*
+ * Get the service thread currently associated with the fhe that is
+ * appropriate to handle this operation.
+ */
+SVCTHREAD *
+fha_hash_entry_choose_thread(struct fha_params *softc,
+ struct fha_hash_entry *fhe, struct fha_info *i, SVCTHREAD *this_thread);
+
+SVCTHREAD *
+fha_hash_entry_choose_thread(struct fha_params *softc,
+ struct fha_hash_entry *fhe, struct fha_info *i, SVCTHREAD *this_thread)
+{
+ SVCTHREAD *thread, *min_thread = NULL;
+ SVCPOOL *pool;
+ int req_count, min_count = 0;
+ off_t offset1, offset2;
+
+ pool = *softc->pool;
+
+ LIST_FOREACH(thread, &fhe->threads, st_alink) {
+ req_count = thread->st_reqcount;
+
+ /* If there are any writes in progress, use the first thread. */
+ if (fhe->num_exclusive) {
+#if 0
+ ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO,
+ "fha: %p(%d)w", thread, req_count);
+#endif
+ return (thread);
+ }
+
+ /*
+ * Check for read locality, making sure that we won't
+ * exceed our per-thread load limit in the process.
+ */
+ offset1 = i->offset;
+ offset2 = STAILQ_FIRST(&thread->st_reqs)->rq_p3;
+
+ if (((offset1 >= offset2)
+ && ((offset1 - offset2) < (1 << softc->ctls.bin_shift)))
+ || ((offset2 > offset1)
+ && ((offset2 - offset1) < (1 << softc->ctls.bin_shift)))) {
+ if ((softc->ctls.max_reqs_per_nfsd == 0) ||
+ (req_count < softc->ctls.max_reqs_per_nfsd)) {
+#if 0
+ ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO,
+ "fha: %p(%d)r", thread, req_count);
+#endif
+ return (thread);
+ }
+ }
+
+ /*
+ * We don't have a locality match, so skip this thread,
+ * but keep track of the most attractive thread in case
+ * we need to come back to it later.
+ */
+#if 0
+ ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO,
+ "fha: %p(%d)s off1 %llu off2 %llu", thread,
+ req_count, offset1, offset2);
+#endif
+ if ((min_thread == NULL) || (req_count < min_count)) {
+ min_count = req_count;
+ min_thread = thread;
+ }
+ }
+
+ /*
+ * We didn't find a good match yet. See if we can add
+ * a new thread to this file handle entry's thread list.
+ */
+ if ((softc->ctls.max_nfsds_per_fh == 0) ||
+ (fhe->num_threads < softc->ctls.max_nfsds_per_fh)) {
+ /*
+ * We can add a new thread, so try for an idle thread
+ * first, and fall back to this_thread if none are idle.
+ */
+ if (STAILQ_EMPTY(&this_thread->st_reqs)) {
+ thread = this_thread;
+#if 0
+ ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO,
+ "fha: %p(%d)t", thread, thread->st_reqcount);
+#endif
+ } else if ((thread = get_idle_thread(pool))) {
+#if 0
+ ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO,
+ "fha: %p(%d)i", thread, thread->st_reqcount);
+#endif
+ } else {
+ thread = this_thread;
+#if 0
+ ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO,
+ "fha: %p(%d)b", thread, thread->st_reqcount);
+#endif
+ }
+ fha_hash_entry_add_thread(fhe, thread);
+ } else {
+ /*
+ * We don't want to use any more threads for this file, so
+ * go back to the most attractive nfsd we're already using.
+ */
+ thread = min_thread;
+ }
+
+ return (thread);
+}
+
+/*
+ * After getting a request, try to assign it to some thread. Usually we
+ * handle it ourselves.
+ */
+SVCTHREAD *
+fha_assign(SVCTHREAD *this_thread, struct svc_req *req,
+ struct fha_params *softc)
+{
+ SVCPOOL *pool;
+ SVCTHREAD *thread;
+ struct fha_info i;
+ struct fha_hash_entry *fhe;
+ struct fha_callbacks *cb;
+
+ cb = &softc->callbacks;
+
+ /* Check to see whether we're enabled. */
+ if (softc->ctls.enable == 0)
+ return (this_thread);
+
+ /*
+ * Only do placement if this is an NFS request.
+ */
+ if (req->rq_prog != NFS_PROG)
+ return (this_thread);
+
+ if (req->rq_vers != 2 && req->rq_vers != 3)
+ return (this_thread);
+
+ pool = req->rq_xprt->xp_pool;
+ fha_extract_info(req, &i, cb);
+
+ /*
+ * We save the offset associated with this request for later
+ * nfsd matching.
+ */
+ fhe = fha_hash_entry_lookup(softc, i.fh);
+ req->rq_p1 = fhe;
+ req->rq_p2 = i.locktype;
+ req->rq_p3 = i.offset;
+
+ /*
+ * Choose a thread, taking into consideration locality, thread load,
+ * and the number of threads already working on this file.
+ */
+ thread = fha_hash_entry_choose_thread(softc, fhe, &i, this_thread);
+ KASSERT(thread, ("fha_assign: NULL thread!"));
+ fha_hash_entry_add_op(fhe, i.locktype, 1);
+
+ return (thread);
+}
+
+/*
+ * Called when we're done with an operation. The request has already
+ * been de-queued.
+ */
+void
+fha_nd_complete(SVCTHREAD *thread, struct svc_req *req)
+{
+ struct fha_hash_entry *fhe = req->rq_p1;
+
+ /*
+ * This may be called for reqs that didn't go through
+ * fha_assign (e.g. extra NULL ops used for RPCSEC_GSS.
+ */
+ if (!fhe)
+ return;
+
+ fha_hash_entry_add_op(fhe, req->rq_p2, -1);
+
+ if (thread->st_reqcount == 0) {
+ fha_hash_entry_remove_thread(fhe, thread);
+ if (0 == fhe->num_rw + fhe->num_exclusive)
+ fha_hash_entry_remove(fhe);
+ }
+}
+
+int
+fhe_stats_sysctl(SYSCTL_HANDLER_ARGS, struct fha_params *softc)
+{
+ int error, count, i;
+ struct sbuf sb;
+ struct fha_hash_entry *fhe;
+ bool_t first = TRUE;
+ SVCTHREAD *thread;
+ SVCPOOL *pool;
+
+ sbuf_new(&sb, NULL, 4096, SBUF_FIXEDLEN);
+
+ pool = NULL;
+
+ if (!*softc->pool) {
+ sbuf_printf(&sb, "NFSD not running\n");
+ goto out;
+ }
+ pool = *softc->pool;
+
+ mtx_lock(&pool->sp_lock);
+ count = 0;
+ for (i = 0; i <= softc->g_fha.hashmask; i++)
+ if (!LIST_EMPTY(&softc->g_fha.hashtable[i]))
+ count++;
+
+ if (count == 0) {
+ sbuf_printf(&sb, "No file handle entries.\n");
+ goto out;
+ }
+
+ for (i = 0; i <= softc->g_fha.hashmask; i++) {
+ LIST_FOREACH(fhe, &softc->g_fha.hashtable[i], link) {
+ sbuf_printf(&sb, "%sfhe %p: {\n", first ? "" : ", ", fhe);
+
+ sbuf_printf(&sb, " fh: %ju\n", (uintmax_t) fhe->fh);
+ sbuf_printf(&sb, " num_rw: %d\n", fhe->num_rw);
+ sbuf_printf(&sb, " num_exclusive: %d\n", fhe->num_exclusive);
+ sbuf_printf(&sb, " num_threads: %d\n", fhe->num_threads);
+
+ LIST_FOREACH(thread, &fhe->threads, st_alink) {
+ sbuf_printf(&sb, " thread %p offset %ju "
+ "(count %d)\n", thread,
+ STAILQ_FIRST(&thread->st_reqs)->rq_p3,
+ thread->st_reqcount);
+ }
+
+ sbuf_printf(&sb, "}");
+ first = FALSE;
+
+ /* Limit the output. */
+ if (++count > 128) {
+ sbuf_printf(&sb, "...");
+ break;
+ }
+ }
+ }
+
+ out:
+ if (pool)
+ mtx_unlock(&pool->sp_lock);
+ sbuf_trim(&sb);
+ sbuf_finish(&sb);
+ error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
+ sbuf_delete(&sb);
+ return (error);
+}
Copied: stable/9/sys/nfs/nfs_fha.h (from r249596, head/sys/nfs/nfs_fha.h)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ stable/9/sys/nfs/nfs_fha.h Tue Jun 11 23:19:02 2013 (r251641, copy of r249596, head/sys/nfs/nfs_fha.h)
@@ -0,0 +1,112 @@
+/*-
+ * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/* $FreeBSD$ */
+
+#ifndef _NFS_FHA_H
+#define _NFS_FHA_H 1
+
+#ifdef _KERNEL
+
+/* Sysctl defaults. */
+#define FHA_DEF_ENABLE 1
+#define FHA_DEF_BIN_SHIFT 22 /* 4MB */
+#define FHA_DEF_MAX_NFSDS_PER_FH 8
+#define FHA_DEF_MAX_REQS_PER_NFSD 0 /* Unlimited */
+
+/* This is the global structure that represents the state of the fha system. */
+struct fha_global {
+ struct fha_hash_entry_list *hashtable;
+ u_long hashmask;
+};
+
+struct fha_ctls {
+ int enable;
+ uint32_t bin_shift;
+ uint32_t max_nfsds_per_fh;
+ uint32_t max_reqs_per_nfsd;
+};
+
+/*
+ * These are the entries in the filehandle hash. They talk about a specific
+ * file, requests against which are being handled by one or more nfsds. We
+ * keep a chain of nfsds against the file. We only have more than one if reads
+ * are ongoing, and then only if the reads affect disparate regions of the
+ * file.
+ *
+ * In general, we want to assign a new request to an existing nfsd if it is
+ * going to contend with work happening already on that nfsd, or if the
+ * operation is a read and the nfsd is already handling a proximate read. We
+ * do this to avoid jumping around in the read stream unnecessarily, and to
+ * avoid contention between threads over single files.
+ */
+struct fha_hash_entry {
+ LIST_ENTRY(fha_hash_entry) link;
+ u_int64_t fh;
+ u_int32_t num_rw;
+ u_int32_t num_exclusive;
+ u_int8_t num_threads;
+ struct svcthread_list threads;
+};
+
+LIST_HEAD(fha_hash_entry_list, fha_hash_entry);
+
+/* A structure used for passing around data internally. */
+struct fha_info {
+ u_int64_t fh;
+ off_t offset;
+ int locktype;
+};
+
+struct fha_callbacks {
+ rpcproc_t (*get_procnum)(rpcproc_t procnum);
+ int (*realign)(struct mbuf **mb, int malloc_flags);
+ int (*get_fh)(fhandle_t *fh, int v3, struct mbuf **md, caddr_t *dpos);
+ int (*is_read)(rpcproc_t procnum);
+ int (*is_write)(rpcproc_t procnum);
+ int (*get_offset)(struct mbuf **md, caddr_t *dpos, int v3, struct
+ fha_info *info);
+ int (*no_offset)(rpcproc_t procnum);
+ void (*set_locktype)(rpcproc_t procnum, struct fha_info *info);
+ int (*fhe_stats_sysctl)(SYSCTL_HANDLER_ARGS);
+};
+
+struct fha_params {
+ struct fha_global g_fha;
+ struct sysctl_ctx_list sysctl_ctx;
+ struct sysctl_oid *sysctl_tree;
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-stable-9
mailing list