All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: tytso@mit.edu, adilger.kernel@dilger.ca
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH v2 23/29] ext4: Convert ext4_mpage_readpages() to work on folios
Date: Fri, 24 Mar 2023 18:01:23 +0000	[thread overview]
Message-ID: <20230324180129.1220691-24-willy@infradead.org> (raw)
In-Reply-To: <20230324180129.1220691-1-willy@infradead.org>

This definitely doesn't include support for large folios; there
are all kinds of assumptions about the number of buffers attached
to a folio.  But it does remove several calls to compound_head().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/ext4/ext4.h     |  2 +-
 fs/ext4/inode.c    |  7 +++---
 fs/ext4/readpage.c | 58 ++++++++++++++++++++++------------------------
 3 files changed, 32 insertions(+), 35 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 1de5d838996a..57357ef1659b 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -3647,7 +3647,7 @@ static inline void ext4_set_de_type(struct super_block *sb,
 
 /* readpages.c */
 extern int ext4_mpage_readpages(struct inode *inode,
-		struct readahead_control *rac, struct page *page);
+		struct readahead_control *rac, struct folio *folio);
 extern int __init ext4_init_post_read_processing(void);
 extern void ext4_exit_post_read_processing(void);
 
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index c88ce6f43c01..116acc5fe00c 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3154,17 +3154,16 @@ static sector_t ext4_bmap(struct address_space *mapping, sector_t block)
 
 static int ext4_read_folio(struct file *file, struct folio *folio)
 {
-	struct page *page = &folio->page;
 	int ret = -EAGAIN;
-	struct inode *inode = page->mapping->host;
+	struct inode *inode = folio->mapping->host;
 
-	trace_ext4_readpage(page);
+	trace_ext4_readpage(&folio->page);
 
 	if (ext4_has_inline_data(inode))
 		ret = ext4_readpage_inline(inode, folio);
 
 	if (ret == -EAGAIN)
-		return ext4_mpage_readpages(inode, NULL, page);
+		return ext4_mpage_readpages(inode, NULL, folio);
 
 	return ret;
 }
diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c
index c61dc8a7c014..fed4ddb652df 100644
--- a/fs/ext4/readpage.c
+++ b/fs/ext4/readpage.c
@@ -218,7 +218,7 @@ static inline loff_t ext4_readpage_limit(struct inode *inode)
 }
 
 int ext4_mpage_readpages(struct inode *inode,
-		struct readahead_control *rac, struct page *page)
+		struct readahead_control *rac, struct folio *folio)
 {
 	struct bio *bio = NULL;
 	sector_t last_block_in_bio = 0;
@@ -247,16 +247,15 @@ int ext4_mpage_readpages(struct inode *inode,
 		int fully_mapped = 1;
 		unsigned first_hole = blocks_per_page;
 
-		if (rac) {
-			page = readahead_page(rac);
-			prefetchw(&page->flags);
-		}
+		if (rac)
+			folio = readahead_folio(rac);
+		prefetchw(&folio->flags);
 
-		if (page_has_buffers(page))
+		if (folio_buffers(folio))
 			goto confused;
 
 		block_in_file = next_block =
-			(sector_t)page->index << (PAGE_SHIFT - blkbits);
+			(sector_t)folio->index << (PAGE_SHIFT - blkbits);
 		last_block = block_in_file + nr_pages * blocks_per_page;
 		last_block_in_file = (ext4_readpage_limit(inode) +
 				      blocksize - 1) >> blkbits;
@@ -290,7 +289,7 @@ int ext4_mpage_readpages(struct inode *inode,
 
 		/*
 		 * Then do more ext4_map_blocks() calls until we are
-		 * done with this page.
+		 * done with this folio.
 		 */
 		while (page_block < blocks_per_page) {
 			if (block_in_file < last_block) {
@@ -299,10 +298,10 @@ int ext4_mpage_readpages(struct inode *inode,
 
 				if (ext4_map_blocks(NULL, inode, &map, 0) < 0) {
 				set_error_page:
-					SetPageError(page);
-					zero_user_segment(page, 0,
-							  PAGE_SIZE);
-					unlock_page(page);
+					folio_set_error(folio);
+					folio_zero_segment(folio, 0,
+							  folio_size(folio));
+					folio_unlock(folio);
 					goto next_page;
 				}
 			}
@@ -333,22 +332,22 @@ int ext4_mpage_readpages(struct inode *inode,
 			}
 		}
 		if (first_hole != blocks_per_page) {
-			zero_user_segment(page, first_hole << blkbits,
-					  PAGE_SIZE);
+			folio_zero_segment(folio, first_hole << blkbits,
+					  folio_size(folio));
 			if (first_hole == 0) {
-				if (ext4_need_verity(inode, page->index) &&
-				    !fsverity_verify_page(page))
+				if (ext4_need_verity(inode, folio->index) &&
+				    !fsverity_verify_page(&folio->page))
 					goto set_error_page;
-				SetPageUptodate(page);
-				unlock_page(page);
-				goto next_page;
+				folio_mark_uptodate(folio);
+				folio_unlock(folio);
+				continue;
 			}
 		} else if (fully_mapped) {
-			SetPageMappedToDisk(page);
+			folio_set_mappedtodisk(folio);
 		}
 
 		/*
-		 * This page will go to BIO.  Do we need to send this
+		 * This folio will go to BIO.  Do we need to send this
 		 * BIO off first?
 		 */
 		if (bio && (last_block_in_bio != blocks[0] - 1 ||
@@ -366,7 +365,7 @@ int ext4_mpage_readpages(struct inode *inode,
 					REQ_OP_READ, GFP_KERNEL);
 			fscrypt_set_bio_crypt_ctx(bio, inode, next_block,
 						  GFP_KERNEL);
-			ext4_set_bio_post_read_ctx(bio, inode, page->index);
+			ext4_set_bio_post_read_ctx(bio, inode, folio->index);
 			bio->bi_iter.bi_sector = blocks[0] << (blkbits - 9);
 			bio->bi_end_io = mpage_end_io;
 			if (rac)
@@ -374,7 +373,7 @@ int ext4_mpage_readpages(struct inode *inode,
 		}
 
 		length = first_hole << blkbits;
-		if (bio_add_page(bio, page, length, 0) < length)
+		if (!bio_add_folio(bio, folio, length, 0))
 			goto submit_and_realloc;
 
 		if (((map.m_flags & EXT4_MAP_BOUNDARY) &&
@@ -384,19 +383,18 @@ int ext4_mpage_readpages(struct inode *inode,
 			bio = NULL;
 		} else
 			last_block_in_bio = blocks[blocks_per_page - 1];
-		goto next_page;
+		continue;
 	confused:
 		if (bio) {
 			submit_bio(bio);
 			bio = NULL;
 		}
-		if (!PageUptodate(page))
-			block_read_full_folio(page_folio(page), ext4_get_block);
+		if (!folio_test_uptodate(folio))
+			block_read_full_folio(folio, ext4_get_block);
 		else
-			unlock_page(page);
-	next_page:
-		if (rac)
-			put_page(page);
+			folio_unlock(folio);
+next_page:
+		; /* A label shall be followed by a statement until C23 */
 	}
 	if (bio)
 		submit_bio(bio);
-- 
2.39.2


  parent reply	other threads:[~2023-03-24 18:03 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24 18:01 [PATCH v2 00/29] Convert most of ext4 to folios Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 01/29] fs: Add FGP_WRITEBEGIN Matthew Wilcox (Oracle)
2023-04-06 14:56   ` [PATCH v2 1/29] " Theodore Ts'o
2023-04-06 15:04     ` Matthew Wilcox
2023-04-06 15:08       ` Matthew Wilcox
2023-03-24 18:01 ` [PATCH v2 02/29] fscrypt: Add some folio helper functions Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 03/29] ext4: Convert ext4_bio_write_page() to use a folio Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 04/29] ext4: Convert ext4_finish_bio() to use folios Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 05/29] ext4: Turn mpage_process_page() into mpage_process_folio() Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 06/29] ext4: Convert mpage_submit_page() to mpage_submit_folio() Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 07/29] ext4: Convert mpage_page_done() to mpage_folio_done() Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 08/29] ext4: Convert ext4_bio_write_page() to ext4_bio_write_folio() Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 09/29] ext4: Convert ext4_readpage_inline() to take a folio Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 10/29] ext4: Convert ext4_convert_inline_data_to_extent() to use " Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 11/29] ext4: Convert ext4_try_to_write_inline_data() " Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 12/29] ext4: Convert ext4_da_convert_inline_data_to_extent() " Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 13/29] ext4: Convert ext4_da_write_inline_data_begin() " Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 14/29] ext4: Convert ext4_read_inline_page() to ext4_read_inline_folio() Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 15/29] ext4: Convert ext4_write_inline_data_end() to use a folio Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 16/29] ext4: Convert ext4_write_begin() " Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 17/29] ext4: Convert ext4_write_end() " Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 18/29] ext4: Use a folio in ext4_journalled_write_end() Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 19/29] ext4: Convert ext4_journalled_zero_new_buffers() to use a folio Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 20/29] ext4: Convert __ext4_block_zero_page_range() " Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 21/29] ext4: Convert ext4_page_nomap_can_writeout to ext4_folio_nomap_can_writeout Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 22/29] ext4: Use a folio in ext4_da_write_begin() Matthew Wilcox (Oracle)
2023-03-24 18:01 ` Matthew Wilcox (Oracle) [this message]
2023-03-24 22:29   ` [PATCH v2 23/29] ext4: Convert ext4_mpage_readpages() to work on folios Eric Biggers
2023-03-26  3:25     ` Matthew Wilcox
2023-03-24 18:01 ` [PATCH v2 24/29] ext4: Convert ext4_block_write_begin() to take a folio Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 25/29] ext4: Use a folio in ext4_page_mkwrite() Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 26/29] ext4: Use a folio iterator in __read_end_io() Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 27/29] ext4: Convert mext_page_mkuptodate() to take a folio Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 28/29] ext4: Convert pagecache_read() to use " Matthew Wilcox (Oracle)
2023-03-24 18:01 ` [PATCH v2 29/29] ext4: Use a folio in ext4_read_merkle_tree_page Matthew Wilcox (Oracle)
2023-04-18  6:50   ` Eric Biggers
2023-04-18 13:08     ` Matthew Wilcox
2023-04-15  2:29 ` [PATCH v2 00/29] Convert most of ext4 to folios Theodore Ts'o

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=20230324180129.1220691-24-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=adilger.kernel@dilger.ca \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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 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.