Skip to contentSkip to conversation

Convert NFS from readpages to readahead

PATCH In review Matthew Wilcox (Oracle) 2 participants 7 messages Jan 22, 2022 – Feb 28, 2022

Subsystems (5)
lore
Share & tools
lore

Matthew Wilcox (Oracle)

author maintainer
#0 lore raw

PATCH 1/2 Convert NFS from readpages to readahead

NFS is one of the last two users of the deprecated ->readpages aop. This conversion looks straightforward, but I have only compile-tested it.

---
 fs/nfs/file.c          |  2 +-
 fs/nfs/nfstrace.h      |  6 +++---
 fs/nfs/read.c          | 21 +++++++++++++--------
 include/linux/nfs_fs.h |  3 +--
 4 files changed, 18 insertions(+), 14 deletions(-)
fs/nfs/file.c +1 -1
index 76d76acbc594..4d681683d13c 100644
@@ -514,7 +514,7 @@ static void nfs_swap_deactivate(struct file *file)
 
 const struct address_space_operations nfs_file_aops = {
 	.readpage = nfs_readpage,
-	.readpages = nfs_readpages,
+	.readahead = nfs_readahead,
 	.set_page_dirty = __set_page_dirty_nobuffers,
 	.writepage = nfs_writepage,
 	.writepages = nfs_writepages,
fs/nfs/nfstrace.h +3 -3
index 317ce27bdc4b..4611aa3a21a4 100644
@@ -889,11 +889,11 @@ TRACE_EVENT(nfs_aop_readpage_done,
 TRACE_EVENT(nfs_aop_readahead,
 		TP_PROTO(
 			const struct inode *inode,
-			struct page *page,
+			loff_t pos,
 			unsigned int nr_pages
 		),
 
-		TP_ARGS(inode, page, nr_pages),
+		TP_ARGS(inode, pos, nr_pages),
 
 		TP_STRUCT__entry(
 			__field(dev_t, dev)
@@ -911,7 +911,7 @@ TRACE_EVENT(nfs_aop_readahead,
 			__entry->fileid = nfsi->fileid;
 			__entry->fhandle = nfs_fhandle_hash(&nfsi->fh);
 			__entry->version = inode_peek_iversion_raw(inode);
-			__entry->offset = page_index(page) << PAGE_SHIFT;
+			__entry->offset = pos;
 			__entry->nr_pages = nr_pages;
 		),
 
fs/nfs/read.c +13 -8
index eb00229c1a50..2472f962a9a2 100644
@@ -290,9 +290,8 @@ static void nfs_readpage_result(struct rpc_task *task,
 }
 
 static int
-readpage_async_filler(void *data, struct page *page)
+readpage_async_filler(struct nfs_readdesc *desc, struct page *page)
 {
-	struct nfs_readdesc *desc = data;
 	struct inode *inode = page_file_mapping(page)->host;
 	unsigned int rsize = NFS_SERVER(inode)->rsize;
 	struct nfs_page *new;
@@ -397,14 +396,16 @@ int nfs_readpage(struct file *file, struct page *page)
 	return ret;
 }
 
-int nfs_readpages(struct file *file, struct address_space *mapping,
-		struct list_head *pages, unsigned nr_pages)
+void nfs_readahead(struct readahead_control *ractl)
 {
+	unsigned int nr_pages = readahead_count(ractl);
+	struct file *file = ractl->file;
 	struct nfs_readdesc desc;
-	struct inode *inode = mapping->host;
+	struct inode *inode = ractl->mapping->host;
+	struct page *page;
 	int ret;
 
-	trace_nfs_aop_readahead(inode, lru_to_page(pages), nr_pages);
+	trace_nfs_aop_readahead(inode, readahead_pos(ractl), nr_pages);
 	nfs_inc_stats(inode, NFSIOS_VFSREADPAGES);
 
 	ret = -ESTALE;
@@ -422,14 +423,18 @@ int nfs_readpages(struct file *file, struct address_space *mapping,
 	nfs_pageio_init_read(&desc.pgio, inode, false,
 			     &nfs_async_read_completion_ops);
 
-	ret = read_cache_pages(mapping, pages, readpage_async_filler, &desc);
+	while ((page = readahead_page(ractl)) != NULL) {
+		ret = readpage_async_filler(&desc, page);
+		put_page(page);
+		if (ret)
+			break;
+	}
 
 	nfs_pageio_complete_read(&desc.pgio);
 
 	put_nfs_open_context(desc.ctx);
 out:
 	trace_nfs_aop_readahead_done(inode, nr_pages, ret);
-	return ret;
 }
 
 int __init nfs_init_readpagecache(void)
include/linux/nfs_fs.h +1 -2
index 00835bacd236..e6ab516bc3d1 100644
@@ -598,8 +598,7 @@ nfs_have_writebacks(struct inode *inode)
  * linux/fs/nfs/read.c
  */
 extern int  nfs_readpage(struct file *, struct page *);
-extern int  nfs_readpages(struct file *, struct address_space *,
-		struct list_head *, unsigned);
+void nfs_readahead(struct readahead_control *);
 
 /*
  * inline functions
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 2/2 readahead: Remove read_cache_pages()

With no remaining users, remove this function and the related infrastructure.

---
 include/linux/pagemap.h |  2 --
 mm/readahead.c          | 76 -----------------------------------------
 2 files changed, 78 deletions(-)
include/linux/pagemap.h +0 -2
index 270bf5136c34..34682f001344 100644
@@ -632,8 +632,6 @@ struct page *read_cache_page(struct address_space *, pgoff_t index,
 		filler_t *filler, void *data);
 extern struct page * read_cache_page_gfp(struct address_space *mapping,
 				pgoff_t index, gfp_t gfp_mask);
-extern int read_cache_pages(struct address_space *mapping,
-		struct list_head *pages, filler_t *filler, void *data);
 
 static inline struct page *read_mapping_page(struct address_space *mapping,
 				pgoff_t index, void *data)
mm/readahead.c +0 -76

82 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#2 lore raw
In reply to Matthew Wilcox (Oracle)
Quoted 3 lines · Matthew Wilcox (Oracle)

NFS is one of the last two users of the deprecated ->readpages aop. This conversion looks straightforward, but I have only compile-tested it.

These patches still apply to -rc2.

author maintainer
#3 lore raw
Quoted 6 lines · Matthew Wilcox
Quoted 3 lines · Matthew Wilcox (Oracle)

NFS is one of the last two users of the deprecated ->readpages aop. This conversion looks straightforward, but I have only compile-tested it.

These patches still apply to -rc2.

And they still apply to rc3.

I'm just going to send them to Linus as part of the general fs-folio work I'm doing during the next merge window. If anybody would like to test them, I'm happy to stick a Tested-by on them.

#4 lore raw
Quoted 9 lines · Matthew Wilcox
Quoted 8 lines · Matthew Wilcox
Quoted 5 lines · Matthew Wilcox (Oracle)

NFS is one of the last two users of the deprecated ->readpages aop.
This conversion looks straightforward, but I have only compile- tested
it.

Quoted 8 lines
Quoted 1 line

These patches still apply to -rc2.

And they still apply to rc3.

I'm just going to send them to Linus as part of the general fs-folio work I'm doing during the next merge window.  If anybody would like to
test them, I'm happy to stick a Tested-by on them.

Unless there is a strong external dependency, I'd prefer to send them through the NFS tree, both for testing purposes, and in case we need to make changes.

I already have them applied to my 'testing' branch, but I can't move that into linux-next until Anna's pull request against -rc3 comes through.

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
author maintainer
#5 lore raw
Quoted 3 lines · Trond Myklebust

I already have them applied to my 'testing' branch, but I can't move that into linux-next until Anna's pull request against -rc3 comes through.

Hey Trond,

I'm not seeing any patches in linux-next to fs/nfs/ other than those that have gone through Andrew Morton, Jens Axboe and Chuck Lever. Has the linux-nfs tree dropped out of linux-next?

#6 lore raw
Quoted 6 lines · Matthew Wilcox
Quoted 4 lines · Trond Myklebust

I already have them applied to my 'testing' branch, but I can't move
that into linux-next until Anna's pull request against -rc3 comes through.

Quoted 6 lines

Hey Trond,

I'm not seeing any patches in linux-next to fs/nfs/ other than those that have gone through Andrew Morton, Jens Axboe and Chuck Lever. Has the linux-nfs tree dropped out of linux-next?

Sorry about that. As I said, I was first waiting for Anna to merge the remaining 5.17 fixes, then got distracted with other work. Hopefully it should appear in Stephen's tree when he updates it.

Cheers
Trond

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