From: David Howells <dhowells@redhat.com>
To: willy@infradead.org
Cc: dhowells@redhat.com, trond.myklebust@primarydata.com,
darrick.wong@oracle.com, hch@lst.de, jlayton@kernel.org,
sfrench@samba.org, torvalds@linux-foundation.org,
linux-nfs@vger.kernel.org, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] mm: Make swap_readpage() for SWP_FS_OPS use ->direct_IO() not ->readpage()
Date: Thu, 12 Aug 2021 12:57:58 +0100 [thread overview]
Message-ID: <162876947840.3068428.12591293664586646085.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <162876946134.3068428.15475611190876694695.stgit@warthog.procyon.org.uk>
Make swap_readpage(), when accessing a swap file (SWP_FS_OPS) use
the ->direct_IO() method on the filesystem rather then ->readpage().
Suggested-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: David Howells <dhowells@redhat.com>
---
mm/page_io.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 67 insertions(+), 6 deletions(-)
diff --git a/mm/page_io.c b/mm/page_io.c
index edb72bf624d2..108f864cea28 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -354,6 +354,72 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
return 0;
}
+struct swapfile_kiocb {
+ struct kiocb iocb;
+ struct page *page;
+ refcount_t ki_refcnt;
+};
+
+static void swapfile_put_kiocb(struct swapfile_kiocb *ki)
+{
+ if (refcount_dec_and_test(&ki->ki_refcnt)) {
+ fput(ki->iocb.ki_filp);
+ kfree(ki);
+ }
+}
+
+static void swapfile_read_complete(struct kiocb *iocb, long ret, long ret2)
+{
+ struct swapfile_kiocb *ki = container_of(iocb, struct swapfile_kiocb, iocb);
+ struct page *page = ki->page;
+
+ if (ret == PAGE_SIZE) {
+ count_vm_event(PSWPIN);
+ SetPageUptodate(page);
+ } else {
+ pr_err_ratelimited("Read error (%ld) on dio swapfile (%llu)\n",
+ ret, page_file_offset(page));
+ }
+
+ unlock_page(page);
+ swapfile_put_kiocb(ki);
+}
+
+static int swapfile_read(struct swap_info_struct *sis, struct page *page,
+ bool synchronous)
+{
+ struct swapfile_kiocb *ki;
+ struct file *swap_file = sis->swap_file;
+ struct bio_vec bv = {
+ .bv_page = page,
+ .bv_len = PAGE_SIZE,
+ .bv_offset = 0
+ };
+ struct iov_iter to;
+ int ret;
+
+ ki = kzalloc(sizeof(*ki), GFP_KERNEL);
+ if (!ki)
+ return -ENOMEM;
+
+ refcount_set(&ki->ki_refcnt, 2);
+ init_sync_kiocb(&ki->iocb, swap_file);
+ ki->page = page;
+ ki->iocb.ki_flags = IOCB_DIRECT | IOCB_SWAP;
+ ki->iocb.ki_pos = page_file_offset(page);
+ ki->iocb.ki_filp = get_file(swap_file);
+ if (!synchronous)
+ ki->iocb.ki_complete = swapfile_read_complete;
+
+ iov_iter_bvec(&to, READ, &bv, 1, PAGE_SIZE);
+ ret = swap_file->f_mapping->a_ops->direct_IO(&ki->iocb, &to);
+
+ if (ret != -EIOCBQUEUED)
+ swapfile_read_complete(&ki->iocb, ret, 0);
+ swapfile_put_kiocb(ki);
+ return (ret > 0) ? 0 : ret;
+}
+
int swap_readpage(struct page *page, bool synchronous)
{
struct bio *bio;
@@ -381,12 +447,7 @@ int swap_readpage(struct page *page, bool synchronous)
}
if (data_race(sis->flags & SWP_FS_OPS)) {
- struct file *swap_file = sis->swap_file;
- struct address_space *mapping = swap_file->f_mapping;
-
- ret = mapping->a_ops->readpage(swap_file, page);
- if (!ret)
- count_vm_event(PSWPIN);
+ ret = swapfile_read(sis, page, synchronous);
goto out;
}
next prev parent reply other threads:[~2021-08-12 11:58 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-12 11:57 [PATCH 0/2] mm: Fix NFS swapfiles and use DIO read for swapfiles David Howells
2021-08-12 11:57 ` [PATCH 1/2] nfs: Fix write to swapfile failure due to generic_write_checks() David Howells
2021-08-12 11:57 ` David Howells [this message]
2021-08-12 12:21 ` [PATCH 2/2] mm: Make swap_readpage() for SWP_FS_OPS use ->direct_IO() not ->readpage() Christoph Hellwig
2021-08-12 12:57 ` David Howells
2021-08-12 15:39 ` Matthew Wilcox
2021-08-12 17:02 ` Christoph Hellwig
2021-08-12 17:48 ` Darrick J. Wong
2021-08-12 18:14 ` Matthew Wilcox
2021-08-12 20:13 ` Theodore Ts'o
2021-08-13 6:54 ` Christoph Hellwig
2021-08-12 13:00 ` Matthew Wilcox
2021-08-12 13:23 ` David Howells
2021-08-12 13:37 ` David Howells
2021-08-12 13:50 ` Matthew Wilcox
2021-08-12 14:16 ` David Howells
2021-08-12 12:18 ` [PATCH 0/2] mm: Fix NFS swapfiles and use DIO read for swapfiles Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=162876947840.3068428.12591293664586646085.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=darrick.wong@oracle.com \
--cc=hch@lst.de \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nfs@vger.kernel.org \
--cc=sfrench@samba.org \
--cc=torvalds@linux-foundation.org \
--cc=trond.myklebust@primarydata.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).