Skip to content

Commit 474bc33

Browse files
Trond MyklebustJ. Bruce Fields
authored andcommitted
nfsd: Reduce contention for the nfsd_file nf_rwsem
When flushing out the unstable file writes as part of a COMMIT call, try to perform most of of the data writes and waits outside the semaphore. This means that if the client is sending the COMMIT as part of a memory reclaim operation, then it can continue performing I/O, with contention for the lock occurring only once the data sync is finished. Fixes: 5011af4 ("nfsd: Fix stable writes") Signed-off-by: Trond Myklebust <[email protected]> Tested-by: Chuck Lever <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent 0ff5b50 commit 474bc33

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

fs/nfsd/vfs.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,19 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
11231123
}
11241124

11251125
#ifdef CONFIG_NFSD_V3
1126+
static int
1127+
nfsd_filemap_write_and_wait_range(struct nfsd_file *nf, loff_t offset,
1128+
loff_t end)
1129+
{
1130+
struct address_space *mapping = nf->nf_file->f_mapping;
1131+
int ret = filemap_fdatawrite_range(mapping, offset, end);
1132+
1133+
if (ret)
1134+
return ret;
1135+
filemap_fdatawait_range_keep_errors(mapping, offset, end);
1136+
return 0;
1137+
}
1138+
11261139
/*
11271140
* Commit all pending writes to stable storage.
11281141
*
@@ -1153,10 +1166,11 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
11531166
if (err)
11541167
goto out;
11551168
if (EX_ISSYNC(fhp->fh_export)) {
1156-
int err2;
1169+
int err2 = nfsd_filemap_write_and_wait_range(nf, offset, end);
11571170

11581171
down_write(&nf->nf_rwsem);
1159-
err2 = vfs_fsync_range(nf->nf_file, offset, end, 0);
1172+
if (!err2)
1173+
err2 = vfs_fsync_range(nf->nf_file, offset, end, 0);
11601174
switch (err2) {
11611175
case 0:
11621176
nfsd_copy_boot_verifier(verf, net_generic(nf->nf_net,

0 commit comments

Comments
 (0)