From: Omar Sandoval <osandov@osandov.com> To: Alexander Viro <viro@zeniv.linux.org.uk>, Andrew Morton <akpm@linux-foundation.org>, Trond Myklebust <trond.myklebust@primarydata.com>, Christoph Hellwig <hch@infradead.org>, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Omar Sandoval <osandov@osandov.com>, Mel Gorman <mgorman@suse.de> Subject: [PATCH v2 4/5] swapfile: use ->read_iter and ->write_iter Date: Fri, 19 Dec 2014 19:18:28 -0800 [thread overview] Message-ID: <d8819b57849221b3db7c479f070067808912f0d5.1419044605.git.osandov@osandov.com> (raw) In-Reply-To: <cover.1419044605.git.osandov@osandov.com> In-Reply-To: <cover.1419044605.git.osandov@osandov.com> Using ->direct_IO and ->readpage for the generic swap file infrastructure requires all sorts of nasty workarounds. ->readpage implementations don't play nicely with swap cache pages, and ->direct_IO implementations have different locking conventions for every filesystem. Instead, use ->read_iter/->write_iter with an ITER_BVEC and let the filesystem take care of it. This will also allow us to easily transition to kernel AIO if that gets merged in the future. Cc: Mel Gorman <mgorman@suse.de> Signed-off-by: Omar Sandoval <osandov@osandov.com> --- mm/page_io.c | 30 +++++++++++++++++++++++------- mm/swapfile.c | 11 ++++++++++- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/mm/page_io.c b/mm/page_io.c index 532a39b..61165b0 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -263,7 +263,6 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc, if (sis->flags & SWP_FILE) { struct kiocb kiocb; struct file *swap_file = sis->swap_file; - struct address_space *mapping = swap_file->f_mapping; struct iov_iter from; struct bio_vec bv = { .bv_page = page, @@ -279,9 +278,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc, set_page_writeback(page); unlock_page(page); - ret = mapping->a_ops->direct_IO(ITER_BVEC | WRITE, - &kiocb, &from, - kiocb.ki_pos); + ret = swap_file->f_op->write_iter(&kiocb, &from); if (ret == PAGE_SIZE) { count_vm_event(PSWPOUT); ret = 0; @@ -344,12 +341,31 @@ int swap_readpage(struct page *page) } if (sis->flags & SWP_FILE) { + struct kiocb kiocb; struct file *swap_file = sis->swap_file; - struct address_space *mapping = swap_file->f_mapping; + struct iov_iter to; + struct bio_vec bv = { + .bv_page = page, + .bv_len = PAGE_SIZE, + .bv_offset = 0, + }; + + iov_iter_bvec(&to, ITER_BVEC | READ, &bv, 1, PAGE_SIZE); + + init_sync_kiocb(&kiocb, swap_file); + kiocb.ki_pos = page_file_offset(page); + kiocb.ki_nbytes = PAGE_SIZE; - ret = mapping->a_ops->readpage(swap_file, page); - if (!ret) + ret = swap_file->f_op->read_iter(&kiocb, &to); + if (ret == PAGE_SIZE) { + SetPageUptodate(page); count_vm_event(PSWPIN); + ret = 0; + } else { + ClearPageUptodate(page); + SetPageError(page); + } + unlock_page(page); return ret; } diff --git a/mm/swapfile.c b/mm/swapfile.c index 63f55cc..4e14122 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2379,7 +2379,16 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) name = NULL; goto bad_swap; } - swap_file = file_open_name(name, O_RDWR|O_LARGEFILE, 0); + swap_file = file_open_name(name, O_RDWR | O_LARGEFILE | O_DIRECT, 0); + if (swap_file == ERR_PTR(-EINVAL)) { + /* + * XXX: there are several filesystems that implement ->bmap but + * not ->direct_IO. It's unlikely that anyone is using a + * swapfile on, e.g., the MINIX fs, but this kludge will keep us + * from getting a complaint from the one person who does. + */ + swap_file = file_open_name(name, O_RDWR | O_LARGEFILE, 0); + } if (IS_ERR(swap_file)) { error = PTR_ERR(swap_file); swap_file = NULL; -- 2.2.1
WARNING: multiple messages have this Message-ID (diff)
From: Omar Sandoval <osandov@osandov.com> To: Alexander Viro <viro@zeniv.linux.org.uk>, Andrew Morton <akpm@linux-foundation.org>, Trond Myklebust <trond.myklebust@primarydata.com>, Christoph Hellwig <hch@infradead.org>, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Omar Sandoval <osandov@osandov.com>, Mel Gorman <mgorman@suse.de> Subject: [PATCH v2 4/5] swapfile: use ->read_iter and ->write_iter Date: Fri, 19 Dec 2014 19:18:28 -0800 [thread overview] Message-ID: <d8819b57849221b3db7c479f070067808912f0d5.1419044605.git.osandov@osandov.com> (raw) In-Reply-To: <cover.1419044605.git.osandov@osandov.com> In-Reply-To: <cover.1419044605.git.osandov@osandov.com> Using ->direct_IO and ->readpage for the generic swap file infrastructure requires all sorts of nasty workarounds. ->readpage implementations don't play nicely with swap cache pages, and ->direct_IO implementations have different locking conventions for every filesystem. Instead, use ->read_iter/->write_iter with an ITER_BVEC and let the filesystem take care of it. This will also allow us to easily transition to kernel AIO if that gets merged in the future. Cc: Mel Gorman <mgorman@suse.de> Signed-off-by: Omar Sandoval <osandov@osandov.com> --- mm/page_io.c | 30 +++++++++++++++++++++++------- mm/swapfile.c | 11 ++++++++++- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/mm/page_io.c b/mm/page_io.c index 532a39b..61165b0 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -263,7 +263,6 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc, if (sis->flags & SWP_FILE) { struct kiocb kiocb; struct file *swap_file = sis->swap_file; - struct address_space *mapping = swap_file->f_mapping; struct iov_iter from; struct bio_vec bv = { .bv_page = page, @@ -279,9 +278,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc, set_page_writeback(page); unlock_page(page); - ret = mapping->a_ops->direct_IO(ITER_BVEC | WRITE, - &kiocb, &from, - kiocb.ki_pos); + ret = swap_file->f_op->write_iter(&kiocb, &from); if (ret == PAGE_SIZE) { count_vm_event(PSWPOUT); ret = 0; @@ -344,12 +341,31 @@ int swap_readpage(struct page *page) } if (sis->flags & SWP_FILE) { + struct kiocb kiocb; struct file *swap_file = sis->swap_file; - struct address_space *mapping = swap_file->f_mapping; + struct iov_iter to; + struct bio_vec bv = { + .bv_page = page, + .bv_len = PAGE_SIZE, + .bv_offset = 0, + }; + + iov_iter_bvec(&to, ITER_BVEC | READ, &bv, 1, PAGE_SIZE); + + init_sync_kiocb(&kiocb, swap_file); + kiocb.ki_pos = page_file_offset(page); + kiocb.ki_nbytes = PAGE_SIZE; - ret = mapping->a_ops->readpage(swap_file, page); - if (!ret) + ret = swap_file->f_op->read_iter(&kiocb, &to); + if (ret == PAGE_SIZE) { + SetPageUptodate(page); count_vm_event(PSWPIN); + ret = 0; + } else { + ClearPageUptodate(page); + SetPageError(page); + } + unlock_page(page); return ret; } diff --git a/mm/swapfile.c b/mm/swapfile.c index 63f55cc..4e14122 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2379,7 +2379,16 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) name = NULL; goto bad_swap; } - swap_file = file_open_name(name, O_RDWR|O_LARGEFILE, 0); + swap_file = file_open_name(name, O_RDWR | O_LARGEFILE | O_DIRECT, 0); + if (swap_file == ERR_PTR(-EINVAL)) { + /* + * XXX: there are several filesystems that implement ->bmap but + * not ->direct_IO. It's unlikely that anyone is using a + * swapfile on, e.g., the MINIX fs, but this kludge will keep us + * from getting a complaint from the one person who does. + */ + swap_file = file_open_name(name, O_RDWR | O_LARGEFILE, 0); + } if (IS_ERR(swap_file)) { error = PTR_ERR(swap_file); swap_file = NULL; -- 2.2.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2014-12-20 3:19 UTC|newest] Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-12-20 3:18 [PATCH v2 0/5] clean up and generalize swap-over-NFS Omar Sandoval 2014-12-20 3:18 ` Omar Sandoval 2014-12-20 3:18 ` [PATCH v2 1/5] iov_iter: add ITER_BVEC helpers Omar Sandoval 2014-12-20 3:18 ` Omar Sandoval 2014-12-20 3:18 ` [PATCH v2 2/5] direct-io: don't dirty ITER_BVEC pages on read Omar Sandoval 2014-12-20 3:18 ` Omar Sandoval 2014-12-20 6:01 ` Al Viro 2014-12-20 6:01 ` Al Viro 2014-12-22 7:12 ` Omar Sandoval 2014-12-22 7:12 ` Omar Sandoval 2014-12-20 3:18 ` [PATCH v2 3/5] nfs: don't dirty ITER_BVEC pages read through direct I/O Omar Sandoval 2014-12-20 3:18 ` Omar Sandoval 2015-01-05 14:41 ` Anna Schumaker 2015-01-05 14:41 ` Anna Schumaker 2015-01-05 14:41 ` Anna Schumaker 2015-01-08 9:25 ` Omar Sandoval 2015-01-08 9:25 ` Omar Sandoval 2015-01-08 9:25 ` Omar Sandoval 2014-12-20 3:18 ` Omar Sandoval [this message] 2014-12-20 3:18 ` [PATCH v2 4/5] swapfile: use ->read_iter and ->write_iter Omar Sandoval 2014-12-20 6:13 ` Al Viro 2014-12-20 6:13 ` Al Viro 2014-12-22 7:32 ` Omar Sandoval 2014-12-22 7:32 ` Omar Sandoval 2014-12-22 7:32 ` Omar Sandoval 2014-12-20 3:18 ` [PATCH v2 5/5] vfs: update swap_{,de}activate documentation Omar Sandoval 2014-12-20 3:18 ` Omar Sandoval 2015-01-14 3:18 ` [PATCH v2 0/5] clean up and generalize swap-over-NFS Omar Sandoval 2015-01-14 3:18 ` Omar Sandoval 2015-01-14 3:18 ` Omar Sandoval 2015-01-21 19:14 ` Omar Sandoval 2015-01-21 19:14 ` Omar Sandoval 2015-01-21 19:14 ` Omar Sandoval
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=d8819b57849221b3db7c479f070067808912f0d5.1419044605.git.osandov@osandov.com \ --to=osandov@osandov.com \ --cc=akpm@linux-foundation.org \ --cc=hch@infradead.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=mgorman@suse.de \ --cc=trond.myklebust@primarydata.com \ --cc=viro@zeniv.linux.org.uk \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.