Index: /usr/src/sys/sys/buf.h =================================================================== RCS file: /export/ncvs/src/sys/sys/buf.h,v retrieving revision 1.167.2.1 diff -u -r1.167.2.1 buf.h --- /usr/src/sys/sys/buf.h 31 Jan 2005 23:26:55 -0000 1.167.2.1 +++ /usr/src/sys/sys/buf.h 15 Apr 2005 02:00:44 -0000 @@ -469,6 +469,7 @@ extern int maxswzone; /* Max KVA for swap structures */ extern int maxbcache; /* Max KVA for buffer cache */ extern int runningbufspace; +extern int hibufspace; extern int buf_maxio; /* nominal maximum I/O for buffer */ extern struct buf *buf; /* The buffer headers. */ extern char *buffers; /* The buffer contents. */ Index: /usr/src/sys/kern/vfs_bio.c =================================================================== RCS file: /export/ncvs/src/sys/kern/vfs_bio.c,v retrieving revision 1.444.2.2 diff -u -r1.444.2.2 vfs_bio.c --- /usr/src/sys/kern/vfs_bio.c 31 Jan 2005 23:26:18 -0000 1.444.2.2 +++ /usr/src/sys/kern/vfs_bio.c 15 Apr 2005 01:59:38 -0000 @@ -113,7 +113,7 @@ static int lobufspace; SYSCTL_INT(_vfs, OID_AUTO, lobufspace, CTLFLAG_RD, &lobufspace, 0, "Minimum amount of buffers we want to have"); -static int hibufspace; +int hibufspace; SYSCTL_INT(_vfs, OID_AUTO, hibufspace, CTLFLAG_RD, &hibufspace, 0, "Maximum allowed value of bufspace (excluding buf_daemon)"); static int bufreusecnt; Index: /usr/src/sys/nfsclient/nfs_bio.c =================================================================== RCS file: /export/ncvs/src/sys/nfsclient/nfs_bio.c,v retrieving revision 1.133.2.2 diff -u -r1.133.2.2 nfs_bio.c --- /usr/src/sys/nfsclient/nfs_bio.c 31 Jan 2005 23:26:46 -0000 1.133.2.2 +++ /usr/src/sys/nfsclient/nfs_bio.c 26 Apr 2005 17:12:18 -0000 @@ -755,6 +755,14 @@ */ if (ioflag & (IO_APPEND | IO_SYNC)) { if (np->n_flag & NMODIFIED) { + /* + * Require non-blocking, synchronous writes to + * dirty files to inform the program it needs + * to fsync(2) explicitly. + */ + if (ioflag & IO_NDELAY) + return (EAGAIN); +flush_and_restart: np->n_attrstamp = 0; error = nfs_vinvalbuf(vp, V_SAVE, cred, td, 1); if (error) @@ -832,6 +840,58 @@ } biosize = vp->v_mount->mnt_stat.f_iosize; + /* + * Find all of this file's B_NEEDCOMMIT buffers. If our writes + * would exceed the local maximum per-file write commit size when + * combined with those, we must decide whether to flush, + * go synchronous, or return error. + */ + if (!(ioflag & IO_SYNC)) { + int needrestart = 0; + if (nmp->nm_wcommitsize < uio->uio_resid) { + /* + * If this request could not possibly be completed + * without exceeding the maximum outstanding write + * commit size, see if we can convert it into a + * synchronous write operation. + */ + if (ioflag & IO_NDELAY) + return (EAGAIN); + ioflag |= IO_SYNC; + if (np->n_flag & NMODIFIED) + needrestart = 1; + } else if (np->n_flag & NMODIFIED) { + int wouldcommit = 0; + VI_LOCK(vp); + TAILQ_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs) { + if (bp->b_flags & B_NEEDCOMMIT) + wouldcommit += bp->b_bcount; + } + VI_UNLOCK(vp); + /* + * Since we're not operating synchronously and + * bypassing the buffer cache, we are in a commit + * and holding all of these buffers whether + * transmitted or not. If not limited, this + * will lead to the buffer cache deadlocking, + * as no one else can flush our uncommitted buffers. + */ + wouldcommit += uio->uio_resid; + /* + * If we would initially exceed the maximum + * outstanding write commit size, flush and restart. + */ + if (wouldcommit > nmp->nm_wcommitsize) + needrestart = 1; + } + if (needrestart) { + if (haverslock) { + nfs_rsunlock(np, td); + haverslock = 0; + } + goto flush_and_restart; + } + } do { nfsstats.biocache_writes++; @@ -932,12 +992,6 @@ break; } } - if (!bp) { - error = nfs_sigintr(nmp, NULL, td); - if (!error) - error = EINTR; - break; - } if (bp->b_wcred == NOCRED) bp->b_wcred = crhold(cred); np->n_flag |= NMODIFIED; Index: /usr/src/sys/nfsclient/nfs_vfsops.c =================================================================== RCS file: /export/ncvs/src/sys/nfsclient/nfs_vfsops.c,v retrieving revision 1.158.2.3 diff -u -r1.158.2.3 nfs_vfsops.c --- /usr/src/sys/nfsclient/nfs_vfsops.c 31 Jan 2005 23:26:46 -0000 1.158.2.3 +++ /usr/src/sys/nfsclient/nfs_vfsops.c 15 Apr 2005 02:03:05 -0000 @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include #include #include @@ -625,6 +627,12 @@ else nmp->nm_readahead = NFS_MAXRAHEAD; } + if ((argp->flags & NFSMNT_WCOMMITSIZE) && argp->wcommitsize >= 0) { + if (argp->wcommitsize < nmp->nm_wsize) + nmp->nm_wcommitsize = nmp->nm_wsize; + else + nmp->nm_wcommitsize = argp->wcommitsize; + } if ((argp->flags & NFSMNT_DEADTHRESH) && argp->deadthresh >= 0) { if (argp->deadthresh <= NFS_MAXDEADTHRESH) nmp->nm_deadthresh = argp->deadthresh; @@ -785,6 +793,7 @@ nmp->nm_wsize = NFS_WSIZE; nmp->nm_rsize = NFS_RSIZE; } + nmp->nm_wcommitsize = hibufspace / (desiredvnodes / 1000); nmp->nm_readdirsize = NFS_READDIRSIZE; nmp->nm_numgrps = NFS_MAXGRPS; nmp->nm_readahead = NFS_DEFRAHEAD; Index: /usr/src/sys/nfsclient/nfsargs.h =================================================================== RCS file: /export/ncvs/src/sys/nfsclient/nfsargs.h,v retrieving revision 1.66.2.1 diff -u -r1.66.2.1 nfsargs.h --- /usr/src/sys/nfsclient/nfsargs.h 31 Jan 2005 23:26:46 -0000 1.66.2.1 +++ /usr/src/sys/nfsclient/nfsargs.h 26 Apr 2005 17:13:22 -0000 @@ -56,7 +56,7 @@ int retrans; /* times to retry send */ int maxgrouplist; /* Max. size of group list */ int readahead; /* # of blocks to readahead */ - int __pad1; /* was "leaseterm" */ + int wcommitsize; /* Max. write commit size in bytes */ int deadthresh; /* Retrans threshold */ char *hostname; /* server's name */ int acregmin; /* cache attrs for reg files min time */ @@ -80,7 +80,7 @@ #define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */ /* 0x400 free, was NFSMNT_KERB */ #define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */ -/* 0x1000 free, was NFSMNT_LEASETERM */ +#define NFSMNT_WCOMMITSIZE 0x00001000 /* set max write commit size */ #define NFSMNT_READAHEAD 0x00002000 /* set read ahead */ #define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */ #define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */ Index: /usr/src/sys/nfsclient/nfsmount.h =================================================================== RCS file: /export/ncvs/src/sys/nfsclient/nfsmount.h,v retrieving revision 1.27.2.1 diff -u -r1.27.2.1 nfsmount.h --- /usr/src/sys/nfsclient/nfsmount.h 31 Jan 2005 23:26:46 -0000 1.27.2.1 +++ /usr/src/sys/nfsclient/nfsmount.h 15 Apr 2005 01:21:57 -0000 @@ -66,6 +66,7 @@ int nm_wsize; /* Max size of write rpc */ int nm_readdirsize; /* Size of a readdir rpc */ int nm_readahead; /* Num. of blocks to readahead */ + int nm_wcommitsize; /* Max size of commit for write */ int nm_acdirmin; /* Directory attr cache min lifetime */ int nm_acdirmax; /* Directory attr cache max lifetime */ int nm_acregmin; /* Reg file attr cache min lifetime */