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 01/29] fs: Add FGP_WRITEBEGIN
Date: Fri, 24 Mar 2023 18:01:01 +0000	[thread overview]
Message-ID: <20230324180129.1220691-2-willy@infradead.org> (raw)
In-Reply-To: <20230324180129.1220691-1-willy@infradead.org>

This particular combination of flags is used by most filesystems
in their ->write_begin method, although it does find use in a
few other places.  Before folios, it warranted its own function
(grab_cache_page_write_begin()), but I think that just having specialised
flags is enough.  It certainly helps the few places that have been
converted from grab_cache_page_write_begin() to __filemap_get_folio().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/ext4/move_extent.c    |  5 ++---
 fs/iomap/buffered-io.c   |  2 +-
 fs/netfs/buffered_read.c |  3 +--
 fs/nfs/file.c            | 12 ++----------
 include/linux/pagemap.h  |  2 ++
 mm/folio-compat.c        |  4 +---
 6 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
index 7bf6d069199c..a84a794fed56 100644
--- a/fs/ext4/move_extent.c
+++ b/fs/ext4/move_extent.c
@@ -126,7 +126,6 @@ mext_folio_double_lock(struct inode *inode1, struct inode *inode2,
 {
 	struct address_space *mapping[2];
 	unsigned int flags;
-	unsigned fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE;
 
 	BUG_ON(!inode1 || !inode2);
 	if (inode1 < inode2) {
@@ -139,14 +138,14 @@ mext_folio_double_lock(struct inode *inode1, struct inode *inode2,
 	}
 
 	flags = memalloc_nofs_save();
-	folio[0] = __filemap_get_folio(mapping[0], index1, fgp_flags,
+	folio[0] = __filemap_get_folio(mapping[0], index1, FGP_WRITEBEGIN,
 			mapping_gfp_mask(mapping[0]));
 	if (IS_ERR(folio[0])) {
 		memalloc_nofs_restore(flags);
 		return PTR_ERR(folio[0]);
 	}
 
-	folio[1] = __filemap_get_folio(mapping[1], index2, fgp_flags,
+	folio[1] = __filemap_get_folio(mapping[1], index2, FGP_WRITEBEGIN,
 			mapping_gfp_mask(mapping[1]));
 	memalloc_nofs_restore(flags);
 	if (IS_ERR(folio[1])) {
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 96bb56c203f4..063133ec77f4 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -467,7 +467,7 @@ EXPORT_SYMBOL_GPL(iomap_is_partially_uptodate);
  */
 struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos)
 {
-	unsigned fgp = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE | FGP_NOFS;
+	unsigned fgp = FGP_WRITEBEGIN | FGP_NOFS;
 
 	if (iter->flags & IOMAP_NOWAIT)
 		fgp |= FGP_NOWAIT;
diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c
index 209726a9cfdb..3404707ddbe7 100644
--- a/fs/netfs/buffered_read.c
+++ b/fs/netfs/buffered_read.c
@@ -341,14 +341,13 @@ int netfs_write_begin(struct netfs_inode *ctx,
 {
 	struct netfs_io_request *rreq;
 	struct folio *folio;
-	unsigned int fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE;
 	pgoff_t index = pos >> PAGE_SHIFT;
 	int ret;
 
 	DEFINE_READAHEAD(ractl, file, NULL, mapping, index);
 
 retry:
-	folio = __filemap_get_folio(mapping, index, fgp_flags,
+	folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
 				    mapping_gfp_mask(mapping));
 	if (IS_ERR(folio))
 		return PTR_ERR(folio);
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 1d03406e6c03..dd9ef0655716 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -306,15 +306,6 @@ static bool nfs_want_read_modify_write(struct file *file, struct folio *folio,
 	return false;
 }
 
-static struct folio *
-nfs_folio_grab_cache_write_begin(struct address_space *mapping, pgoff_t index)
-{
-	unsigned fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE;
-
-	return __filemap_get_folio(mapping, index, fgp_flags,
-				   mapping_gfp_mask(mapping));
-}
-
 /*
  * This does the "real" work of the write. We must allocate and lock the
  * page to be sent back to the generic routine, which then copies the
@@ -335,7 +326,8 @@ static int nfs_write_begin(struct file *file, struct address_space *mapping,
 		file, mapping->host->i_ino, len, (long long) pos);
 
 start:
-	folio = nfs_folio_grab_cache_write_begin(mapping, pos >> PAGE_SHIFT);
+	folio = __filemap_get_folio(mapping, pos >> PAGE_SHIFT, FGP_WRITEBEGIN,
+				   mapping_gfp_mask(mapping));
 	if (IS_ERR(folio))
 		return PTR_ERR(folio);
 	*pagep = &folio->page;
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index fdcd595d2294..a56308a9d1a4 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -506,6 +506,8 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping,
 #define FGP_FOR_MMAP		0x00000040
 #define FGP_STABLE		0x00000080
 
+#define FGP_WRITEBEGIN		(FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE)
+
 void *filemap_get_entry(struct address_space *mapping, pgoff_t index);
 struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
 		int fgp_flags, gfp_t gfp);
diff --git a/mm/folio-compat.c b/mm/folio-compat.c
index 2511c055a35f..c6f056c20503 100644
--- a/mm/folio-compat.c
+++ b/mm/folio-compat.c
@@ -106,9 +106,7 @@ EXPORT_SYMBOL(pagecache_get_page);
 struct page *grab_cache_page_write_begin(struct address_space *mapping,
 					pgoff_t index)
 {
-	unsigned fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE;
-
-	return pagecache_get_page(mapping, index, fgp_flags,
+	return pagecache_get_page(mapping, index, FGP_WRITEBEGIN,
 			mapping_gfp_mask(mapping));
 }
 EXPORT_SYMBOL(grab_cache_page_write_begin);
-- 
2.39.2


  reply	other threads:[~2023-03-24 18:02 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 ` Matthew Wilcox (Oracle) [this message]
2023-04-06 14:56   ` [PATCH v2 1/29] fs: Add FGP_WRITEBEGIN 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 ` [PATCH v2 23/29] ext4: Convert ext4_mpage_readpages() to work on folios Matthew Wilcox (Oracle)
2023-03-24 22:29   ` 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-2-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.