Skip to contentSkip to conversation

NFS: Fix read_bytes for buffered reads

PATCH In review Dave Wysochanski 2 participants 3 messages Mar 9, 2023 – Mar 14, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover NFS: Fix read_bytes for buffered reads

This patch fixes the read_bytes count for NFS buffered reads. Simple reproducer follows.

Before this patch:

# mount 127.0.0.1:/ /mnt/nfs
# bash
# function dump_stats { cat /proc/$$/io; }
# trap dump_stats EXIT
# cat /mnt/nfs/file1.bin > /dev/null
# exit
exit
rchar: 3587436
wchar: 1054077
syscr: 544
syscw: 33
read_bytes: 0
write_bytes: 0
cancelled_write_bytes: 0

After this patch:

# mount 127.0.0.1:/ /mnt/nfs
# bash
# function dump_stats { cat /proc/$$/io; }
# trap dump_stats EXIT
# cat /mnt/nfs/file1.bin > /dev/null
# exit
exit
rchar: 3587278
wchar: 1054161
syscr: 544
syscw: 33
read_bytes: 1048576
write_bytes: 0
cancelled_write_bytes: 0

Dave Wysochanski (1):
NFS: Fix /proc/PID/io read_bytes for buffered reads

 fs/nfs/read.c | 3 +++
 1 file changed, 3 insertions(+)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/1 NFS: Fix /proc/PID/io read_bytes for buffered reads

Prior to commit 8786fde8421c ("Convert NFS from readpages to readahead"), nfs_readpages() used the old mm interface read_cache_pages() which called task_io_account_read() for each NFS page read. After this commit, nfs_readpages() is converted to nfs_readahead(), which now uses the new mm interface readahead_page(). The new interface requires callers to call task_io_account_read() themselves. In addition, to nfs_readahead() task_io_account_read() should also be called from nfs_read_folio().

---
 fs/nfs/read.c | 3 +++
 1 file changed, 3 insertions(+)
fs/nfs/read.c +3 -0
index c380cff4108e..e90988591df4 100644
@@ -15,6 +15,7 @@
 #include <linux/stat.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
+#include <linux/task_io_accounting_ops.h>
 #include <linux/pagemap.h>
 #include <linux/sunrpc/clnt.h>
 #include <linux/nfs_fs.h>
@@ -337,6 +338,7 @@ int nfs_read_folio(struct file *file, struct folio *folio)
 
 	trace_nfs_aop_readpage(inode, folio);
 	nfs_inc_stats(inode, NFSIOS_VFSREADPAGE);
+	task_io_account_read(folio_size(folio));
 
 	/*
 	 * Try to flush any pending writes to the file..
@@ -393,6 +395,7 @@ void nfs_readahead(struct readahead_control *ractl)
 
 	trace_nfs_aop_readahead(inode, readahead_pos(ractl), nr_pages);
 	nfs_inc_stats(inode, NFSIOS_VFSREADPAGES);
+	task_io_account_read(readahead_length(ractl));
 
 	ret = -ESTALE;
 	if (NFS_STALE(inode))
Signature · 1 line
2.31.1
Tested-by on v1 1/1
#2 lore raw

Re: [PATCH 1/1] NFS: Fix /proc/PID/io read_bytes for buffered reads

Thanks Dave.

I can confirm that this does indeed fix the reporting of /proc/PID/read_bytes for us. I actually applied it (cleanly) to our v5.18 based kernel as we use that in production on our render farm.

We use the read_bytes in our post render statistics to help track per render IO.

Quoted 48 lines · Dave Wysochanski

Prior to commit 8786fde8421c ("Convert NFS from readpages to readahead"), nfs_readpages() used the old mm interface read_cache_pages() which called task_io_account_read() for each NFS page read. After this commit, nfs_readpages() is converted to nfs_readahead(), which now uses the new mm interface readahead_page(). The new interface requires callers to call task_io_account_read() themselves. In addition, to nfs_readahead() task_io_account_read() should also be called from nfs_read_folio().

---
 fs/nfs/read.c | 3 +++
 1 file changed, 3 insertions(+)
fs/nfs/read.c +3 -1
index c380cff4108e..e90988591df4 100644
@@ -15,6 +15,7 @@
 #include <linux/stat.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
+#include <linux/task_io_accounting_ops.h>
 #include <linux/pagemap.h>
 #include <linux/sunrpc/clnt.h>
 #include <linux/nfs_fs.h>
@@ -337,6 +338,7 @@ int nfs_read_folio(struct file *file, struct folio *folio)
 
        trace_nfs_aop_readpage(inode, folio);
        nfs_inc_stats(inode, NFSIOS_VFSREADPAGE);
+       task_io_account_read(folio_size(folio));
 
        /*
         * Try to flush any pending writes to the file..
@@ -393,6 +395,7 @@ void nfs_readahead(struct readahead_control *ractl)
 
        trace_nfs_aop_readahead(inode, readahead_pos(ractl), nr_pages);
        nfs_inc_stats(inode, NFSIOS_VFSREADPAGES);
+       task_io_account_read(readahead_length(ractl));
 
        ret = -ESTALE;
        if (NFS_STALE(inode))
--

2.31.1