diff mbox series

[v3,02/18] swap: Call aops->readahead if appropriate

Message ID 20201016160443.18685-3-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Allow readpage to return a locked page | expand

Commit Message

Matthew Wilcox Oct. 16, 2020, 4:04 p.m. UTC
Some filesystems have a synchronous readpage and an asynchronous
readahead.  Call the readahead operation if we're trying to do swap
readahead.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/page_io.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/mm/page_io.c b/mm/page_io.c
index e485a6e8a6cd..faf5ccb42946 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -367,6 +367,24 @@  int __swap_writepage(struct page *page, struct writeback_control *wbc,
 	return ret;
 }
 
+static int mapping_readpage(struct file *file, struct address_space *mapping,
+		struct page *page, bool synchronous)
+{
+	struct readahead_control ractl = {
+		.file = file,
+		.mapping = mapping,
+		._index = page->index,
+		._nr_pages = 1,
+	};
+
+	if (!synchronous && mapping->a_ops->readahead) {
+		mapping->a_ops->readahead(&ractl);
+		return 0;
+	}
+
+	return mapping->a_ops->readpage(file, page);
+}
+
 int swap_readpage(struct page *page, bool synchronous)
 {
 	struct bio *bio;
@@ -395,9 +413,9 @@  int swap_readpage(struct page *page, bool synchronous)
 
 	if (data_race(sis->flags & SWP_FS)) {
 		struct file *swap_file = sis->swap_file;
-		struct address_space *mapping = swap_file->f_mapping;
 
-		ret = mapping->a_ops->readpage(swap_file, page);
+		ret = mapping_readpage(swap_file, swap_file->f_mapping,
+				page, synchronous);
 		if (!ret)
 			count_vm_event(PSWPIN);
 		goto out;