Skip to contentSkip to conversation

nfsd: Reduce contention for the nfsd_file nf_rwsem

PATCH In review [email protected] 4 participants 9 messages Jun 17, 2021 – Jun 23, 2021

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 nfsd: Reduce contention for the nfsd_file nf_rwsem

From: Trond Myklebust <[email protected]>

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 5011af4c698a ("nfsd: Fix stable writes")
---
 fs/nfsd/vfs.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +16 -2
index 15adf1f6ab21..46485c04740d 100644
@@ -1123,6 +1123,19 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
 }
 
 #ifdef CONFIG_NFSD_V3
+static int
+nfsd_filemap_write_and_wait_range(struct nfsd_file *nf, loff_t offset,
+				  loff_t end)
+{
+	struct address_space *mapping = nf->nf_file->f_mapping;
+	int ret = filemap_fdatawrite_range(mapping, offset, end);
+
+	if (ret)
+		return ret;
+	filemap_fdatawait_range_keep_errors(mapping, offset, end);
+	return 0;
+}
+
 /*
  * Commit all pending writes to stable storage.
  *
@@ -1153,10 +1166,11 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	if (err)
 		goto out;
 	if (EX_ISSYNC(fhp->fh_export)) {
-		int err2;
+		int err2 = nfsd_filemap_write_and_wait_range(nf, offset, end);
 
 		down_write(&nf->nf_rwsem);
-		err2 = vfs_fsync_range(nf->nf_file, offset, end, 0);
+		if (!err2)
+			err2 = vfs_fsync_range(nf->nf_file, offset, end, 0);
 		switch (err2) {
 		case 0:
 			nfsd_copy_boot_verifier(verf, net_generic(nf->nf_net,
Signature · 1 line
2.31.1
#1 lore raw
Quoted 9 lines · On Jun 17, 2021, at 7:26 PM, [email protected] wrote:

From: Trond Myklebust <[email protected]>

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.

Quoted 6 lines

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 5011af4c698a ("nfsd: Fix stable writes")

I'll toss this onto my server over the weekend for some testing.

Quoted 45 lines

---
fs/nfsd/vfs.c | 18 ++++++++++++++++--

1 file changed, 16 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +16 -2
index 15adf1f6ab21..46485c04740d 100644
@@ -1123,6 +1123,19 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
 }
 
 #ifdef CONFIG_NFSD_V3
+static int
+nfsd_filemap_write_and_wait_range(struct nfsd_file *nf, loff_t offset,
+				  loff_t end)
+{
+	struct address_space *mapping = nf->nf_file->f_mapping;
+	int ret = filemap_fdatawrite_range(mapping, offset, end);
+
+	if (ret)
+		return ret;
+	filemap_fdatawait_range_keep_errors(mapping, offset, end);
+	return 0;
+}
+
 /*
 * Commit all pending writes to stable storage.
 *
@@ -1153,10 +1166,11 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	if (err)
 		goto out;
 	if (EX_ISSYNC(fhp->fh_export)) {
-		int err2;
+		int err2 = nfsd_filemap_write_and_wait_range(nf, offset, end);
 
 		down_write(&nf->nf_rwsem);
-		err2 = vfs_fsync_range(nf->nf_file, offset, end, 0);
+		if (!err2)
+			err2 = vfs_fsync_range(nf->nf_file, offset, end, 0);
 		switch (err2) {
 		case 0:
 			nfsd_copy_boot_verifier(verf, net_generic(nf->nf_net,
Signature · 1 line
2.31.1

--
Chuck Lever

#2 lore raw
In reply to [email protected]

Hi-

Quoted 7 lines · On Jun 17, 2021, at 7:26 PM, [email protected] wrote:

From: Trond Myklebust <[email protected]>

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.

Quoted 6 lines

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 5011af4c698a ("nfsd: Fix stable writes")

The good news is I've found no functional regressions. The bad news is I haven't seen any difference in performance. Is there a particular test that I can run to observe improvement?

I wonder about adding a Fixes: tag for a change that the patch description describes as an optimization.

Quoted 45 lines

---
fs/nfsd/vfs.c | 18 ++++++++++++++++--

1 file changed, 16 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +16 -2
index 15adf1f6ab21..46485c04740d 100644
@@ -1123,6 +1123,19 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
 }
 
 #ifdef CONFIG_NFSD_V3
+static int
+nfsd_filemap_write_and_wait_range(struct nfsd_file *nf, loff_t offset,
+				  loff_t end)
+{
+	struct address_space *mapping = nf->nf_file->f_mapping;
+	int ret = filemap_fdatawrite_range(mapping, offset, end);
+
+	if (ret)
+		return ret;
+	filemap_fdatawait_range_keep_errors(mapping, offset, end);
+	return 0;
+}
+
 /*
 * Commit all pending writes to stable storage.
 *
@@ -1153,10 +1166,11 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	if (err)
 		goto out;
 	if (EX_ISSYNC(fhp->fh_export)) {
-		int err2;
+		int err2 = nfsd_filemap_write_and_wait_range(nf, offset, end);
 
 		down_write(&nf->nf_rwsem);
-		err2 = vfs_fsync_range(nf->nf_file, offset, end, 0);
+		if (!err2)
+			err2 = vfs_fsync_range(nf->nf_file, offset, end, 0);
 		switch (err2) {
 		case 0:
 			nfsd_copy_boot_verifier(verf, net_generic(nf->nf_net,
Signature · 1 line
2.31.1

--
Chuck Lever

#3 lore raw
Quoted 17 lines · Chuck Lever III

Hi-

Quoted 15 lines · On Jun 17, 2021, at 7:26 PM, [email protected] wrote:

From: Trond Myklebust <[email protected]>

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.

Quoted 6 lines
Quoted 2 lines
Fixes 5011af4c698a ("nfsd: Fix stable writes")

The good news is I've found no functional regressions. The bad news is I haven't seen any difference in performance. Is there a particular test that I can run to observe improvement?

I'd expect that re-exported NFS would be the best test since fsync() is a high latency operation when the page cache is loaded. You also want to use a client with relatively limited memory so that it will try to reclaim memory by pushing out dirty pages and doing COMMIT.

Quoted 3 lines

I wonder about adding a Fixes: tag for a change that the patch description describes as an optimization.

I've occasionally hit OOM situations in the re-export case when the r/w lock contention causes softerr failure to be serialised. i.e. if the server is down, and you're essentially hoping that the nfsd threads will give up and return EJUKEBOX/NFS4ERR_DELAY to the client, then that lock ensures that threads fail one-by-one (grab lock, write, timeout, release lock) instead of being able to all fail at once (write, timeout).

Quoted 60 lines
Quoted 46 lines

---
fs/nfsd/vfs.c | 18 ++++++++++++++++--

1 file changed, 16 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +13 -0
index 15adf1f6ab21..46485c04740d 100644
@@ -1123,6 +1123,19 @@ nfsd_write(struct svc_rqst *rqstp, struct
 svc_fh *fhp, loff_t offset,
 }
 
 #ifdef CONFIG_NFSD_V3
+static int
+nfsd_filemap_write_and_wait_range(struct nfsd_file *nf, loff_t
 offset,
+                                 loff_t end)
+{
+       struct address_space *mapping = nf->nf_file->f_mapping;
+       int ret = filemap_fdatawrite_range(mapping, offset, end);
+
+       if (ret)
+               return ret;
+       filemap_fdatawait_range_keep_errors(mapping, offset, end);
+       return 0;
+}
+
 /*

 * Commit all pending writes to stable storage.
 *

fs/nfsd/vfs.c +3 -2
@@ -1153,10 +1166,11 @@ nfsd_commit(struct svc_rqst *rqstp, struct
 svc_fh *fhp,
         if (err)
                 goto out;
         if (EX_ISSYNC(fhp->fh_export)) {
-               int err2;
+               int err2 = nfsd_filemap_write_and_wait_range(nf,
 offset, end);
 
                 down_write(&nf->nf_rwsem);
-               err2 = vfs_fsync_range(nf->nf_file, offset, end,
 0);
+               if (!err2)
+                       err2 = vfs_fsync_range(nf->nf_file, offset,
Quoted 8 lines

end, 0);
                switch (err2) {
                case 0:
                        nfsd_copy_boot_verifier(verf, net_generic(nf->nf_net,

Signature · 1 line
2.31.1

--
Chuck Lever

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
#4 lore raw
Quoted 25 lines · Trond Myklebust
Quoted 20 lines · Chuck Lever III

Hi-

Quoted 17 lines · On Jun 17, 2021, at 7:26 PM, [email protected] wrote:

From: Trond Myklebust <[email protected]>

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 5011af4c698a ("nfsd: Fix stable writes")
Quoted 8 lines
Quoted 3 lines

The good news is I've found no functional regressions. The bad news is I haven't seen any difference in performance. Is there a particular test that I can run to observe improvement?

I'd expect that re-exported NFS would be the best test since fsync() is a high latency operation when the page cache is loaded. You also want to use a client with relatively limited memory so that it will try to reclaim memory by pushing out dirty pages and doing COMMIT.

I thought I was hitting those low-memory cases with direct I/O testing. <shrug>

Quoted 63 lines
Quoted 2 lines

I wonder about adding a Fixes: tag for a change that the patch description describes as an optimization.

I've occasionally hit OOM situations in the re-export case when the r/w lock contention causes softerr failure to be serialised. i.e. if the server is down, and you're essentially hoping that the nfsd threads will give up and return EJUKEBOX/NFS4ERR_DELAY to the client, then that lock ensures that threads fail one-by-one (grab lock, write, timeout, release lock) instead of being able to all fail at once (write, timeout).

Quoted 52 lines
Quoted 52 lines

---
fs/nfsd/vfs.c | 18 ++++++++++++++++--

1 file changed, 16 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +13 -0
index 15adf1f6ab21..46485c04740d 100644
@@ -1123,6 +1123,19 @@ nfsd_write(struct svc_rqst *rqstp, struct
 svc_fh *fhp, loff_t offset,
 }
 
 #ifdef CONFIG_NFSD_V3
+static int
+nfsd_filemap_write_and_wait_range(struct nfsd_file *nf, loff_t
 offset,
+                                 loff_t end)
+{
+       struct address_space *mapping = nf->nf_file->f_mapping;
+       int ret = filemap_fdatawrite_range(mapping, offset, end);
+
+       if (ret)
+               return ret;
+       filemap_fdatawait_range_keep_errors(mapping, offset, end);
+       return 0;
+}
+
 /*

* Commit all pending writes to stable storage.
*

fs/nfsd/vfs.c +3 -2
@@ -1153,10 +1166,11 @@ nfsd_commit(struct svc_rqst *rqstp, struct
 svc_fh *fhp,
        if (err)
                goto out;
        if (EX_ISSYNC(fhp->fh_export)) {
-               int err2;
+               int err2 = nfsd_filemap_write_and_wait_range(nf,
 offset, end);
 
                down_write(&nf->nf_rwsem);
-               err2 = vfs_fsync_range(nf->nf_file, offset, end,
 0);
+               if (!err2)
+                       err2 = vfs_fsync_range(nf->nf_file, offset,
end, 0);
                switch (err2) {
                case 0:
                        nfsd_copy_boot_verifier(verf,

net_generic(nf->nf_net,

Quoted 13 lines
Quoted 8 lines
Quoted 2 lines

2.31.1

--
Chuck Lever

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]

--
Chuck Lever

#5 lore raw
Quoted 40 lines · Chuck Lever III
Quoted 32 lines

On Jun 21, 2021, at 2:00 PM, Trond Myklebust
<[email protected]> wrote:

Quoted 18 lines · Chuck Lever III

Hi-

Quoted 16 lines · On Jun 17, 2021, at 7:26 PM, [email protected] wrote:

From: Trond Myklebust <[email protected]>

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.

Quoted 7 lines
Quoted 3 lines
Fixes 5011af4c698a ("nfsd: Fix stable writes")
Signed-off-by Trond Myklebust

<[email protected]>

The good news is I've found no functional regressions. The bad news is I haven't seen any difference in performance. Is there a particular test that I can run to observe improvement?

Quoted 7 lines

I'd expect that re-exported NFS would be the best test since fsync() is
a high latency operation when the page cache is loaded. You also want
to use a client with relatively limited memory so that it will try to
reclaim memory by pushing out dirty pages and doing COMMIT.

Quoted 2 lines

I thought I was hitting those low-memory cases with direct I/O testing. <shrug>

If you do O_DIRECT with 100MB write() calls, then maybe. If you use < 1MB write()s then you'll rarely if ever hit any COMMIT calls.

Quoted 95 lines
Quoted 76 lines
Quoted 4 lines

I wonder about adding a Fixes: tag for a change that the patch description describes as an optimization.

I've occasionally hit OOM situations in the re-export case when the r/w
lock contention causes softerr failure to be serialised. i.e. if the server is down, and you're essentially hoping that the nfsd
threads will give up and return EJUKEBOX/NFS4ERR_DELAY to the client,
then that lock ensures that threads fail one-by-one (grab lock, write,
timeout, release lock) instead of being able to all fail at once (write, timeout).

Quoted 59 lines
Quoted 59 lines

---
fs/nfsd/vfs.c | 18 ++++++++++++++++--

1 file changed, 16 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +0 -0
index 15adf1f6ab21..46485c04740d 100644
@@ -1123,6 +1123,19 @@ nfsd_write(struct svc_rqst *rqstp,

struct
svc_fh *fhp, loff_t offset,
}

#ifdef CONFIG_NFSD_V3

fs/nfsd/vfs.c +2 -0
+static int
+nfsd_filemap_write_and_wait_range(struct nfsd_file *nf, loff_t

offset,
+                                 loff_t end)
+{
+       struct address_space *mapping = nf->nf_file->f_mapping; +       int ret = filemap_fdatawrite_range(mapping, offset, end);
+
+       if (ret)
+               return ret;
+       filemap_fdatawait_range_keep_errors(mapping, offset, end);
+       return 0;

fs/nfsd/vfs.c +2 -0
+}
+

/*
 * Commit all pending writes to stable storage.
 *

fs/nfsd/vfs.c +0 -0
@@ -1153,10 +1166,11 @@ nfsd_commit(struct svc_rqst *rqstp,

struct
svc_fh *fhp,
        if (err)
                goto out;
        if (EX_ISSYNC(fhp->fh_export)) {
-               int err2;
+               int err2 =
nfsd_filemap_write_and_wait_range(nf,
offset, end);

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

Quoted 13 lines
Quoted 8 lines
Quoted 2 lines

2.31.1

--
Chuck Lever

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]

--
Chuck Lever

Signature · 6 lines
Trond Myklebust
CTO, Hammerspace Inc
4984 El Camino Real, Suite 208
Los Altos, CA 94022
​
www.hammer.space
#6 lore raw
Quoted 44 lines · Trond Myklebust
Quoted 43 lines · Chuck Lever III
Quoted 42 lines

On Jun 21, 2021, at 2:00 PM, Trond Myklebust
<[email protected]> wrote:

Quoted 20 lines · Chuck Lever III

Hi-

Quoted 18 lines · On Jun 17, 2021, at 7:26 PM, [email protected] wrote:

From: Trond Myklebust <[email protected]>

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.

Quoted 7 lines
Quoted 3 lines
Fixes 5011af4c698a ("nfsd: Fix stable writes")
Signed-off-by Trond Myklebust

<[email protected]>

The good news is I've found no functional regressions. The bad news is I haven't seen any difference in performance. Is there a particular test that I can run to observe improvement?

I'd expect that re-exported NFS would be the best test since fsync() is
a high latency operation when the page cache is loaded. You also want
to use a client with relatively limited memory so that it will try
to
reclaim memory by pushing out dirty pages and doing COMMIT.

Quoted 5 lines
Quoted 2 lines

I thought I was hitting those low-memory cases with direct I/O testing. <shrug>

If you do O_DIRECT with 100MB write() calls, then maybe. If you use < 1MB write()s then you'll rarely if ever hit any COMMIT calls.

Let me correct myself: You'd need to do aio/dio with 100MB write system calls so that the flush part of the COMMIT operation takes significant time on the server, and can interfere with other COMMIT operations.

Quoted 101 lines
Quoted 100 lines
Quoted 81 lines
Quoted 5 lines

I wonder about adding a Fixes: tag for a change that the patch description describes as an optimization.

I've occasionally hit OOM situations in the re-export case when the
r/w
lock contention causes softerr failure to be serialised. i.e. if the server is down, and you're essentially hoping that the
nfsd
threads will give up and return EJUKEBOX/NFS4ERR_DELAY to the client,
then that lock ensures that threads fail one-by-one (grab lock, write,
timeout, release lock) instead of being able to all fail at once (write, timeout).

Quoted 61 lines
Quoted 61 lines

---
fs/nfsd/vfs.c | 18 ++++++++++++++++--

1 file changed, 16 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +0 -0
index 15adf1f6ab21..46485c04740d 100644
@@ -1123,6 +1123,19 @@ nfsd_write(struct svc_rqst *rqstp,

struct
svc_fh *fhp, loff_t offset,
}

#ifdef CONFIG_NFSD_V3

fs/nfsd/vfs.c +2 -0
+static int
+nfsd_filemap_write_and_wait_range(struct nfsd_file *nf,

loff_t
offset,
+                                 loff_t end) +{
+       struct address_space *mapping = nf->nf_file-

Quoted 1 line

f_mapping;

+       int ret = filemap_fdatawrite_range(mapping, offset, end);
+
+       if (ret)
+               return ret;
+       filemap_fdatawait_range_keep_errors(mapping, offset, end);
+       return 0;

fs/nfsd/vfs.c +2 -0
+}
+

/*
 * Commit all pending writes to stable storage.
 *

fs/nfsd/vfs.c +0 -0
@@ -1153,10 +1166,11 @@ nfsd_commit(struct svc_rqst *rqstp,

struct
svc_fh *fhp,
        if (err)
                goto out;
        if (EX_ISSYNC(fhp->fh_export)) {
-               int err2;
+               int err2 =
nfsd_filemap_write_and_wait_range(nf,
offset, end);

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

Quoted 13 lines
Quoted 8 lines
Quoted 2 lines

2.31.1

--
Chuck Lever

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]

--
Chuck Lever

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
Tested-by on v1 1/1
#7 lore raw
In reply to [email protected]
Quoted 8 lines · On Jun 17, 2021, at 7:26 PM, [email protected] wrote:

From: Trond Myklebust <[email protected]>

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.

Quoted 6 lines

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 5011af4c698a ("nfsd: Fix stable writes")

I can see write throughput improvement now.

This is NFSv3 against an NVMe-backed XFS export, wsize=8192:

v5.13-rc6:

Command line used: /home/cel/bin/iozone -M -+u -i0 -i1 -s1g -r256k -t12 -I Output is in kBytes/sec
Time Resolution = 0.000001 seconds.
Processor cache size set to 1024 kBytes.
Processor cache line size set to 32 bytes.
File stride size set to 17 * record size.
Throughput test with 12 processes
Each process writes a 1048576 kByte file in 256 kByte records

Children see throughput for 12 initial writers = 416004.59 kB/sec
Parent sees throughput for 12 initial writers = 415691.65 kB/sec
Min throughput per process = 34630.36 kB/sec
Max throughput per process = 34703.62 kB/sec
Avg throughput per process = 34667.05 kB/sec
Min xfer = 1046528.00 kB
CPU Utilization: Wall time 30.239 CPU time 5.854 CPU utilization 19.36 %

Children see throughput for 12 rewriters = 516605.59 kB/sec
Parent sees throughput for 12 rewriters = 516530.05 kB/sec
Min throughput per process = 43007.56 kB/sec
Max throughput per process = 43074.50 kB/sec
Avg throughput per process = 43050.47 kB/sec
Min xfer = 1047040.00 kB
CPU utilization: Wall time 24.347 CPU time 5.882 CPU utilization 24.16 %

v5.13-rc6 + Trond's patch:

Command line used: /home/cel/bin/iozone -M -+u -i0 -i1 -s1g -r256k -t12 -I Output is in kBytes/sec
Time Resolution = 0.000001 seconds.
Processor cache size set to 1024 kBytes.
Processor cache line size set to 32 bytes.
File stride size set to 17 * record size.
Throughput test with 12 processes
Each process writes a 1048576 kByte file in 256 kByte records

Children see throughput for 12 initial writers = 434971.09 kB/sec
Parent sees throughput for 12 initial writers = 434649.13 kB/sec
Min throughput per process = 36209.41 kB/sec
Max throughput per process = 36287.55 kB/sec
Avg throughput per process = 36247.59 kB/sec
Min xfer = 1046528.00 kB
CPU Utilization: Wall time 28.920 CPU time 5.705 CPU utilization 19.73 %

Children see throughput for 12 rewriters = 544700.37 kB/sec
Parent sees throughput for 12 rewriters = 544623.91 kB/sec
Min throughput per process = 45320.82 kB/sec
Max throughput per process = 45456.07 kB/sec
Avg throughput per process = 45391.70 kB/sec
Min xfer = 1045504.00 kB
CPU utilization: Wall time 23.071 CPU time 5.708 CPU utilization 24.74 %

Quoted 45 lines

---
fs/nfsd/vfs.c | 18 ++++++++++++++++--

1 file changed, 16 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +16 -2
index 15adf1f6ab21..46485c04740d 100644
@@ -1123,6 +1123,19 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
 }
 
 #ifdef CONFIG_NFSD_V3
+static int
+nfsd_filemap_write_and_wait_range(struct nfsd_file *nf, loff_t offset,
+				  loff_t end)
+{
+	struct address_space *mapping = nf->nf_file->f_mapping;
+	int ret = filemap_fdatawrite_range(mapping, offset, end);
+
+	if (ret)
+		return ret;
+	filemap_fdatawait_range_keep_errors(mapping, offset, end);
+	return 0;
+}
+
 /*
 * Commit all pending writes to stable storage.
 *
@@ -1153,10 +1166,11 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	if (err)
 		goto out;
 	if (EX_ISSYNC(fhp->fh_export)) {
-		int err2;
+		int err2 = nfsd_filemap_write_and_wait_range(nf, offset, end);
 
 		down_write(&nf->nf_rwsem);
-		err2 = vfs_fsync_range(nf->nf_file, offset, end, 0);
+		if (!err2)
+			err2 = vfs_fsync_range(nf->nf_file, offset, end, 0);
 		switch (err2) {
 		case 0:
 			nfsd_copy_boot_verifier(verf, net_generic(nf->nf_net,
Signature · 1 line
2.31.1

--
Chuck Lever

#8 lore raw
In reply to [email protected]

Applying, with Chuck's Tested-by, thanks.--b.

Quoted 55 lines · On Thu, Jun 17, 2021 at 07:26:52PM -0400, [email protected] wrote:

From: Trond Myklebust <[email protected]>

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 5011af4c698a ("nfsd: Fix stable writes")
---
 fs/nfsd/vfs.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +16 -2
index 15adf1f6ab21..46485c04740d 100644
@@ -1123,6 +1123,19 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,
 }
 
 #ifdef CONFIG_NFSD_V3
+static int
+nfsd_filemap_write_and_wait_range(struct nfsd_file *nf, loff_t offset,
+				  loff_t end)
+{
+	struct address_space *mapping = nf->nf_file->f_mapping;
+	int ret = filemap_fdatawrite_range(mapping, offset, end);
+
+	if (ret)
+		return ret;
+	filemap_fdatawait_range_keep_errors(mapping, offset, end);
+	return 0;
+}
+
 /*
  * Commit all pending writes to stable storage.
  *
@@ -1153,10 +1166,11 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	if (err)
 		goto out;
 	if (EX_ISSYNC(fhp->fh_export)) {
-		int err2;
+		int err2 = nfsd_filemap_write_and_wait_range(nf, offset, end);
 
 		down_write(&nf->nf_rwsem);
-		err2 = vfs_fsync_range(nf->nf_file, offset, end, 0);
+		if (!err2)
+			err2 = vfs_fsync_range(nf->nf_file, offset, end, 0);
 		switch (err2) {
 		case 0:
 			nfsd_copy_boot_verifier(verf, net_generic(nf->nf_net,
Signature · 1 line
2.31.1