linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: "Darrick J . Wong " <djwong@kernel.org>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
	Jens Axboe <axboe@kernel.dk>,
	Christoph Hellwig <hch@infradead.org>
Subject: [PATCH v2 17/28] iomap: Convert readahead and readpage to use a folio
Date: Mon,  8 Nov 2021 04:05:40 +0000	[thread overview]
Message-ID: <20211108040551.1942823-18-willy@infradead.org> (raw)
In-Reply-To: <20211108040551.1942823-1-willy@infradead.org>

Handle folios of arbitrary size instead of working in PAGE_SIZE units.
readahead_folio() decreases the page refcount for you, so this is not
quite a mechanical change.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/iomap/buffered-io.c | 53 +++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 27 deletions(-)

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 96a404f11a3b..b0b402e1779e 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -188,8 +188,8 @@ static void iomap_read_end_io(struct bio *bio)
 }
 
 struct iomap_readpage_ctx {
-	struct page		*cur_page;
-	bool			cur_page_in_bio;
+	struct folio		*cur_folio;
+	bool			cur_folio_in_bio;
 	struct bio		*bio;
 	struct readahead_control *rac;
 };
@@ -243,8 +243,7 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter,
 	const struct iomap *iomap = &iter->iomap;
 	loff_t pos = iter->pos + offset;
 	loff_t length = iomap_length(iter) - offset;
-	struct page *page = ctx->cur_page;
-	struct folio *folio = page_folio(page);
+	struct folio *folio = ctx->cur_folio;
 	struct iomap_page *iop;
 	loff_t orig_pos = pos;
 	size_t poff, plen;
@@ -265,7 +264,7 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter,
 		goto done;
 	}
 
-	ctx->cur_page_in_bio = true;
+	ctx->cur_folio_in_bio = true;
 	if (iop)
 		atomic_add(plen, &iop->read_bytes_pending);
 
@@ -273,7 +272,7 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter,
 	if (!ctx->bio ||
 	    bio_end_sector(ctx->bio) != sector ||
 	    !bio_add_folio(ctx->bio, folio, plen, poff)) {
-		gfp_t gfp = mapping_gfp_constraint(page->mapping, GFP_KERNEL);
+		gfp_t gfp = mapping_gfp_constraint(folio->mapping, GFP_KERNEL);
 		gfp_t orig_gfp = gfp;
 		unsigned int nr_vecs = DIV_ROUND_UP(length, PAGE_SIZE);
 
@@ -312,30 +311,31 @@ static loff_t iomap_readpage_iter(const struct iomap_iter *iter,
 int
 iomap_readpage(struct page *page, const struct iomap_ops *ops)
 {
+	struct folio *folio = page_folio(page);
 	struct iomap_iter iter = {
-		.inode		= page->mapping->host,
-		.pos		= page_offset(page),
-		.len		= PAGE_SIZE,
+		.inode		= folio->mapping->host,
+		.pos		= folio_pos(folio),
+		.len		= folio_size(folio),
 	};
 	struct iomap_readpage_ctx ctx = {
-		.cur_page	= page,
+		.cur_folio	= folio,
 	};
 	int ret;
 
-	trace_iomap_readpage(page->mapping->host, 1);
+	trace_iomap_readpage(iter.inode, 1);
 
 	while ((ret = iomap_iter(&iter, ops)) > 0)
 		iter.processed = iomap_readpage_iter(&iter, &ctx, 0);
 
 	if (ret < 0)
-		SetPageError(page);
+		folio_set_error(folio);
 
 	if (ctx.bio) {
 		submit_bio(ctx.bio);
-		WARN_ON_ONCE(!ctx.cur_page_in_bio);
+		WARN_ON_ONCE(!ctx.cur_folio_in_bio);
 	} else {
-		WARN_ON_ONCE(ctx.cur_page_in_bio);
-		unlock_page(page);
+		WARN_ON_ONCE(ctx.cur_folio_in_bio);
+		folio_unlock(folio);
 	}
 
 	/*
@@ -354,15 +354,15 @@ static loff_t iomap_readahead_iter(const struct iomap_iter *iter,
 	loff_t done, ret;
 
 	for (done = 0; done < length; done += ret) {
-		if (ctx->cur_page && offset_in_page(iter->pos + done) == 0) {
-			if (!ctx->cur_page_in_bio)
-				unlock_page(ctx->cur_page);
-			put_page(ctx->cur_page);
-			ctx->cur_page = NULL;
+		if (ctx->cur_folio &&
+		    offset_in_folio(ctx->cur_folio, iter->pos + done) == 0) {
+			if (!ctx->cur_folio_in_bio)
+				folio_unlock(ctx->cur_folio);
+			ctx->cur_folio = NULL;
 		}
-		if (!ctx->cur_page) {
-			ctx->cur_page = readahead_page(ctx->rac);
-			ctx->cur_page_in_bio = false;
+		if (!ctx->cur_folio) {
+			ctx->cur_folio = readahead_folio(ctx->rac);
+			ctx->cur_folio_in_bio = false;
 		}
 		ret = iomap_readpage_iter(iter, ctx, done);
 	}
@@ -403,10 +403,9 @@ void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops)
 
 	if (ctx.bio)
 		submit_bio(ctx.bio);
-	if (ctx.cur_page) {
-		if (!ctx.cur_page_in_bio)
-			unlock_page(ctx.cur_page);
-		put_page(ctx.cur_page);
+	if (ctx.cur_folio) {
+		if (!ctx.cur_folio_in_bio)
+			folio_unlock(ctx.cur_folio);
 	}
 }
 EXPORT_SYMBOL_GPL(iomap_readahead);
-- 
2.33.0


  parent reply	other threads:[~2021-11-08  4:50 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-08  4:05 [PATCH v2 00/28] iomap/xfs folio patches Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 01/28] csky,sparc: Declare flush_dcache_folio() Matthew Wilcox (Oracle)
2021-11-09  8:36   ` Christoph Hellwig
2021-11-15 15:54     ` Matthew Wilcox
2021-11-16  6:33       ` Christoph Hellwig
2021-11-16 21:49         ` Matthew Wilcox
2021-11-17  9:52           ` Geert Uytterhoeven
2021-11-08  4:05 ` [PATCH v2 02/28] mm: Add functions to zero portions of a folio Matthew Wilcox (Oracle)
2021-11-09  8:40   ` Christoph Hellwig
2021-11-17  4:45   ` Darrick J. Wong
2021-11-17 14:07     ` Matthew Wilcox
2021-11-17 17:07       ` Darrick J. Wong
2021-11-18 15:55         ` Matthew Wilcox
2021-11-18 17:26           ` Darrick J. Wong
2021-11-18 20:08             ` Matthew Wilcox
2021-11-08  4:05 ` [PATCH v2 03/28] fs: Remove FS_THP_SUPPORT Matthew Wilcox (Oracle)
2021-11-17  4:36   ` Darrick J. Wong
2021-11-08  4:05 ` [PATCH v2 04/28] fs: Rename AS_THP_SUPPORT and mapping_thp_support Matthew Wilcox (Oracle)
2021-11-09  8:41   ` Christoph Hellwig
2021-11-15 16:03     ` Matthew Wilcox
2021-11-16  6:33       ` Christoph Hellwig
2021-11-08  4:05 ` [PATCH v2 05/28] block: Add bio_add_folio() Matthew Wilcox (Oracle)
2021-11-17  4:48   ` Darrick J. Wong
2021-11-08  4:05 ` [PATCH v2 06/28] block: Add bio_for_each_folio_all() Matthew Wilcox (Oracle)
2021-11-17  4:48   ` Darrick J. Wong
2021-11-08  4:05 ` [PATCH v2 07/28] fs/buffer: Convert __block_write_begin_int() to take a folio Matthew Wilcox (Oracle)
2021-11-09  8:42   ` Christoph Hellwig
2021-11-17  4:35   ` Darrick J. Wong
2021-11-08  4:05 ` [PATCH v2 08/28] iomap: Convert to_iomap_page " Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 09/28] iomap: Convert iomap_page_create " Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 10/28] iomap: Convert iomap_page_release " Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 11/28] iomap: Convert iomap_releasepage to use " Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 12/28] iomap: Add iomap_invalidate_folio Matthew Wilcox (Oracle)
2021-11-17  2:20   ` Darrick J. Wong
2021-11-08  4:05 ` [PATCH v2 13/28] iomap: Pass the iomap_page into iomap_set_range_uptodate Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 14/28] iomap: Convert bio completions to use folios Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 15/28] iomap: Use folio offsets instead of page offsets Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 16/28] iomap: Convert iomap_read_inline_data to take a folio Matthew Wilcox (Oracle)
2021-11-08  4:05 ` Matthew Wilcox (Oracle) [this message]
2021-11-09  8:43   ` [PATCH v2 17/28] iomap: Convert readahead and readpage to use " Christoph Hellwig
2021-11-08  4:05 ` [PATCH v2 18/28] iomap: Convert iomap_page_mkwrite " Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 19/28] iomap: Convert __iomap_zero_iter " Matthew Wilcox (Oracle)
2021-11-09  8:47   ` Christoph Hellwig
2021-11-17  2:24   ` Darrick J. Wong
2021-11-17 14:20     ` Matthew Wilcox
2021-12-09 21:38   ` Matthew Wilcox
2021-12-10 16:19     ` Matthew Wilcox
2021-12-13  7:34       ` Christoph Hellwig
2021-12-13 18:08         ` Matthew Wilcox
2021-12-16 19:36     ` Darrick J. Wong
2021-12-16 20:43       ` Matthew Wilcox
2021-11-08  4:05 ` [PATCH v2 20/28] iomap: Convert iomap_write_begin() and iomap_write_end() to folios Matthew Wilcox (Oracle)
2021-11-17  4:31   ` Darrick J. Wong
2021-11-17 14:31     ` Matthew Wilcox
2021-11-17 17:10       ` Darrick J. Wong
2021-11-08  4:05 ` [PATCH v2 21/28] iomap: Convert iomap_write_end_inline to take a folio Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 22/28] iomap,xfs: Convert ->discard_page to ->discard_folio Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 23/28] iomap: Simplify iomap_writepage_map() Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 24/28] iomap: Simplify iomap_do_writepage() Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 25/28] iomap: Convert iomap_add_to_ioend() to take a folio Matthew Wilcox (Oracle)
2021-11-17  4:34   ` Darrick J. Wong
2021-11-08  4:05 ` [PATCH v2 26/28] iomap: Convert iomap_migrate_page() to use folios Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 27/28] iomap: Support multi-page folios in invalidatepage Matthew Wilcox (Oracle)
2021-11-08  4:05 ` [PATCH v2 28/28] xfs: Support multi-page folios Matthew Wilcox (Oracle)

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=20211108040551.1942823-18-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=axboe@kernel.dk \
    --cc=djwong@kernel.org \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.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).