Skip to contentSkip to conversation

start removing writepage instances

PATCH In review Christoph Hellwig 10 participants 26 messages Nov 13, 2022 – Dec 15, 2023

Subsystems (11)
lore
Share & tools
lore
#0 lore raw

Hi all,

The VM doesn't need or want ->writepage for writeback and is fine with just having ->writepages as long as ->migrate_folio is implemented.

This series removes all ->writepage instances that use block_write_full_page directly and also have a plain mpage_writepages based ->writepages.

Diffstat:

 fs/exfat/inode.c   |    9 ++-------
 fs/ext2/inode.c    |    6 ------
 fs/fat/inode.c     |    9 ++-------
 fs/hfs/inode.c     |    2 +-
 fs/hfsplus/inode.c |    2 +-
 fs/hpfs/file.c     |    9 ++-------
 fs/jfs/inode.c     |    7 +------
 fs/omfs/file.c     |    7 +------
 fs/udf/inode.c     |    7 +------
 9 files changed, 11 insertions(+), 47 deletions(-)
#1 lore raw

PATCH 1/9 extfat: remove ->writepage

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Set ->migrate_folio to the generic buffer_head based helper, and remove the ->writepage implementation.

---
 fs/exfat/inode.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
fs/exfat/inode.c +2 -7
index 5590a1e83126c..eac95bcd9a8aa 100644
@@ -345,11 +345,6 @@ static void exfat_readahead(struct readahead_control *rac)
 	mpage_readahead(rac, exfat_get_block);
 }
 
-static int exfat_writepage(struct page *page, struct writeback_control *wbc)
-{
-	return block_write_full_page(page, exfat_get_block, wbc);
-}
-
 static int exfat_writepages(struct address_space *mapping,
 		struct writeback_control *wbc)
 {
@@ -473,12 +468,12 @@ static const struct address_space_operations exfat_aops = {
 	.invalidate_folio = block_invalidate_folio,
 	.read_folio	= exfat_read_folio,
 	.readahead	= exfat_readahead,
-	.writepage	= exfat_writepage,
 	.writepages	= exfat_writepages,
 	.write_begin	= exfat_write_begin,
 	.write_end	= exfat_write_end,
 	.direct_IO	= exfat_direct_IO,
-	.bmap		= exfat_aop_bmap
+	.bmap		= exfat_aop_bmap,
+	.migrate_folio	= buffer_migrate_folio,
 };
 
 static inline unsigned long exfat_hash(loff_t i_pos)
Signature · 1 line
2.30.2
maintainer Acked-by on v1 1/9
#2 lore raw

Re: [PATCH 1/9] extfat: remove ->writepage

2022-11-14 1:28 GMT+09:00, Christoph Hellwig <[email protected]>:

Quoted 8 lines

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Set ->migrate_folio to the generic buffer_head based helper, and remove the ->writepage implementation.

Thanks!

#3 lore raw

PATCH 2/9 ext2: remove ->writepage

In reply to Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

---
 fs/ext2/inode.c | 6 ------
 1 file changed, 6 deletions(-)
fs/ext2/inode.c +0 -6
index 918ab2f9e4c05..3b2e3e1e0fa25 100644
@@ -869,11 +869,6 @@ int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 	return ret;
 }
 
-static int ext2_writepage(struct page *page, struct writeback_control *wbc)
-{
-	return block_write_full_page(page, ext2_get_block, wbc);
-}
-
 static int ext2_read_folio(struct file *file, struct folio *folio)
 {
 	return mpage_read_folio(folio, ext2_get_block);
@@ -948,7 +943,6 @@ const struct address_space_operations ext2_aops = {
 	.invalidate_folio	= block_invalidate_folio,
 	.read_folio		= ext2_read_folio,
 	.readahead		= ext2_readahead,
-	.writepage		= ext2_writepage,
 	.write_begin		= ext2_write_begin,
 	.write_end		= ext2_write_end,
 	.bmap			= ext2_bmap,
Signature · 1 line
2.30.2
reviewer Acked-by on v1 2/9
#4 lore raw

Re: [PATCH 2/9] ext2: remove ->writepage

Quoted 5 lines · Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Looks good! Feel free to add:

Honza

Quoted 31 lines
---
 fs/ext2/inode.c | 6 ------
 1 file changed, 6 deletions(-)
fs/ext2/inode.c +0 -6
index 918ab2f9e4c05..3b2e3e1e0fa25 100644
@@ -869,11 +869,6 @@ int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 	return ret;
 }
 
-static int ext2_writepage(struct page *page, struct writeback_control *wbc)
-{
-	return block_write_full_page(page, ext2_get_block, wbc);
-}
-
 static int ext2_read_folio(struct file *file, struct folio *folio)
 {
 	return mpage_read_folio(folio, ext2_get_block);
@@ -948,7 +943,6 @@ const struct address_space_operations ext2_aops = {
 	.invalidate_folio	= block_invalidate_folio,
 	.read_folio		= ext2_read_folio,
 	.readahead		= ext2_readahead,
-	.writepage		= ext2_writepage,
 	.write_begin		= ext2_write_begin,
 	.write_end		= ext2_write_end,
 	.bmap			= ext2_bmap,
Signature · 1 line
2.30.2
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#5 lore raw

Re: [PATCH 2/9] ext2: remove ->writepage

Quoted 8 lines · Jan Kara
Quoted 5 lines · Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Looks good! Feel free to add:

The testbot found a problem with this:

ext2_commit_chunk calls write_one_page for the IS_DIRSYNC case, and write_one_page calls ->writepage.

So I think I need to drop this one for now (none of the other file systems calls write_one_page). And then think what best to do about write_one_page/write_one_folio. I suspect just passing a writepage pointer to them might make most sense, as they are only used by a few file systems, and the calling convention with the locked page doesn't lend itself to using ->writepages.

reviewer
#6 lore raw

Re: [PATCH 2/9] ext2: remove ->writepageo

Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Jan Kara
Quoted 4 lines · Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Looks good! Feel free to add:

The testbot found a problem with this:

ext2_commit_chunk calls write_one_page for the IS_DIRSYNC case, and write_one_page calls ->writepage.

Right.

Quoted 7 lines

So I think I need to drop this one for now (none of the other file systems calls write_one_page). And then think what best to do about write_one_page/write_one_folio. I suspect just passing a writepage pointer to them might make most sense, as they are only used by a few file systems, and the calling convention with the locked page doesn't lend itself to using ->writepages.

Looking at the code, IMO the write_one_page() looks somewhat premature anyway in that place. AFAICS we could handle the writeout using filemap_write_and_wait() if we moved it to somewhat later moment. So something like attached patch (only basic testing only so far)?

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR

From dc36b90da4c23134ac2fd02d7a21a736fe68d598 Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Wed, 16 Nov 2022 19:08:23 +0100
Subject: [PATCH] ext2: Don't flush page immediately for DIRSYNC directories

We do not need to writeout modified directory blocks immediately when modifying them while the page is locked. It is enough to do the flush somewhat later which has the added benefit that inode times can be flushed as well. It also allows us to stop depending on write_one_page() function.

---
 fs/ext2/dir.c | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)
fs/ext2/dir.c +21 -16
index 8f597753ac12..17efc784af53 100644
@@ -81,11 +81,10 @@ ext2_last_byte(struct inode *inode, unsigned long page_nr)
 	return last_byte;
 }
 
-static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len)
+static void ext2_commit_chunk(struct page *page, loff_t pos, unsigned len)
 {
 	struct address_space *mapping = page->mapping;
 	struct inode *dir = mapping->host;
-	int err = 0;
 
 	inode_inc_iversion(dir);
 	block_write_end(NULL, mapping, pos, len, len, page, NULL);
@@ -94,16 +93,7 @@ static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len)
 		i_size_write(dir, pos+len);
 		mark_inode_dirty(dir);
 	}
-
-	if (IS_DIRSYNC(dir)) {
-		err = write_one_page(page);
-		if (!err)
-			err = sync_inode_metadata(dir, 1);
-	} else {
-		unlock_page(page);
-	}
-
-	return err;
+	unlock_page(page);
 }
 
 static bool ext2_check_page(struct page *page, int quiet, char *kaddr)
@@ -460,6 +450,17 @@ static int ext2_prepare_chunk(struct page *page, loff_t pos, unsigned len)
 	return __block_write_begin(page, pos, len, ext2_get_block);
 }
 
+
+static int ext2_handle_dirsync(struct inode *dir)
+{
+	int err;
+
+	err = filemap_write_and_wait(dir->i_mapping);
+	if (!err)
+		err = sync_inode_metadata(dir, 1);
+	return err;
+}
+
 void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de,
 		   struct page *page, void *page_addr, struct inode *inode,
 		   int update_times)
@@ -474,11 +475,12 @@ void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de,
 	BUG_ON(err);
 	de->inode = cpu_to_le32(inode->i_ino);
 	ext2_set_de_type(de, inode);
-	err = ext2_commit_chunk(page, pos, len);
+	ext2_commit_chunk(page, pos, len);
 	if (update_times)
 		dir->i_mtime = dir->i_ctime = current_time(dir);
 	EXT2_I(dir)->i_flags &= ~EXT2_BTREE_FL;
 	mark_inode_dirty(dir);
+	ext2_handle_dirsync(dir);
 }
 
 /*
@@ -566,10 +568,11 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)
 	memcpy(de->name, name, namelen);
 	de->inode = cpu_to_le32(inode->i_ino);
 	ext2_set_de_type (de, inode);
-	err = ext2_commit_chunk(page, pos, rec_len);
+	ext2_commit_chunk(page, pos, rec_len);
 	dir->i_mtime = dir->i_ctime = current_time(dir);
 	EXT2_I(dir)->i_flags &= ~EXT2_BTREE_FL;
 	mark_inode_dirty(dir);
+	err = ext2_handle_dirsync(dir);
 	/* OFFSET_CACHE */
 out_put:
 	ext2_put_page(page, page_addr);
@@ -615,10 +618,11 @@ int ext2_delete_entry (struct ext2_dir_entry_2 *dir, struct page *page,
 	if (pde)
 		pde->rec_len = ext2_rec_len_to_disk(to - from);
 	dir->inode = 0;
-	err = ext2_commit_chunk(page, pos, to - from);
+	ext2_commit_chunk(page, pos, to - from);
 	inode->i_ctime = inode->i_mtime = current_time(inode);
 	EXT2_I(inode)->i_flags &= ~EXT2_BTREE_FL;
 	mark_inode_dirty(inode);
+	err = ext2_handle_dirsync(dir);
 out:
 	return err;
 }
@@ -658,7 +662,8 @@ int ext2_make_empty(struct inode *inode, struct inode *parent)
 	memcpy (de->name, "..\0", 4);
 	ext2_set_de_type (de, inode);
 	kunmap_atomic(kaddr);
-	err = ext2_commit_chunk(page, 0, chunk_size);
+	ext2_commit_chunk(page, 0, chunk_size);
+	err = ext2_handle_dirsync(inode);
 fail:
 	put_page(page);
 	return err;
Signature · 1 line
2.35.3
#7 lore raw

Re: [PATCH 2/9] ext2: remove ->writepageo

Quoted 4 lines · Jan Kara

Looking at the code, IMO the write_one_page() looks somewhat premature anyway in that place. AFAICS we could handle the writeout using filemap_write_and_wait() if we moved it to somewhat later moment. So something like attached patch (only basic testing only so far)?

Yes, this looks sensible. Do you want to queue this one and the ext2 and udf patches from this series if the testing works fine?

The same transformation should also be done for minix, sysfs and ufs. And a bunch of the others are probaby similar as well.

reviewer
#8 lore raw

Re: [PATCH 2/9] ext2: remove ->writepageo

Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Jan Kara

Looking at the code, IMO the write_one_page() looks somewhat premature anyway in that place. AFAICS we could handle the writeout using filemap_write_and_wait() if we moved it to somewhat later moment. So something like attached patch (only basic testing only so far)?

Yes, this looks sensible. Do you want to queue this one and the ext2 and udf patches from this series if the testing works fine?

OK, I'll take udf and ext2 patches through my tree.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#9 lore raw

PATCH 3/9 fat: remove ->writepage

In reply to Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Set ->migrate_folio to the generic buffer_head based helper, and remove the ->writepage implementation.

---
 fs/fat/inode.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
fs/fat/inode.c +2 -7
index 1cbcc4608dc78..d99b8549ec8f9 100644
@@ -194,11 +194,6 @@ static int fat_get_block(struct inode *inode, sector_t iblock,
 	return 0;
 }
 
-static int fat_writepage(struct page *page, struct writeback_control *wbc)
-{
-	return block_write_full_page(page, fat_get_block, wbc);
-}
-
 static int fat_writepages(struct address_space *mapping,
 			  struct writeback_control *wbc)
 {
@@ -346,12 +341,12 @@ static const struct address_space_operations fat_aops = {
 	.invalidate_folio = block_invalidate_folio,
 	.read_folio	= fat_read_folio,
 	.readahead	= fat_readahead,
-	.writepage	= fat_writepage,
 	.writepages	= fat_writepages,
 	.write_begin	= fat_write_begin,
 	.write_end	= fat_write_end,
 	.direct_IO	= fat_direct_IO,
-	.bmap		= _fat_bmap
+	.bmap		= _fat_bmap,
+	.migrate_folio	= buffer_migrate_folio,
 };
 
 /*
Signature · 1 line
2.30.2
#10 lore raw

PATCH 4/9 hfs: remove ->writepage

In reply to Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Set ->migrate_folio to the generic buffer_head based helper, and stop wiring up ->writepage for hfs_aops.

---
 fs/hfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/hfs/inode.c +1 -1
index c4526f16355d5..16466a5e88b44 100644
@@ -173,12 +173,12 @@ const struct address_space_operations hfs_aops = {
 	.dirty_folio	= block_dirty_folio,
 	.invalidate_folio = block_invalidate_folio,
 	.read_folio	= hfs_read_folio,
-	.writepage	= hfs_writepage,
 	.write_begin	= hfs_write_begin,
 	.write_end	= generic_write_end,
 	.bmap		= hfs_bmap,
 	.direct_IO	= hfs_direct_IO,
 	.writepages	= hfs_writepages,
+	.migrate_folio	= buffer_migrate_folio,
 };
 
 /*
Signature · 1 line
2.30.2
#11 lore raw

Re: [PATCH 4/9] hfs: remove ->writepage

Quoted 8 lines · Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Set ->migrate_folio to the generic buffer_head based helper, and stop wiring up ->writepage for hfs_aops.

Was there a reason you only did this for hfs_aops and not for hfs_btree_aops? It feels like anything that just calls block_write_full_page() in the writepage handler should be converted to just calling mpage_writepages() in the writepages handler. I have a few of those conversions done, but obviously they're in filesystems that are basically untestable.

#12 lore raw

Re: [PATCH 4/9] hfs: remove ->writepage

Quoted 6 lines · Matthew Wilcox

Was there a reason you only did this for hfs_aops and not for hfs_btree_aops? It feels like anything that just calls block_write_full_page() in the writepage handler should be converted to just calling mpage_writepages() in the writepages handler. I have a few of those conversions done, but obviously they're in filesystems that are basically untestable.

Probably. I remember I had a good reason to skip, and the lack of testability might have been it. Note that for hfsplus in particular we should actually be able to test now that the port of the hfs userspace has returned to distros. I haven't actually gotten to see what the test baseline looks like, though.

#13 lore raw

PATCH 5/9 hfsplus: remove ->writepage

In reply to Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Set ->migrate_folio to the generic buffer_head based helper, and stop wiring up ->writepage for hfsplus_aops.

---
 fs/hfsplus/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/hfsplus/inode.c +1 -1
index aeab83ed1c9c6..d6572ad2407a7 100644
@@ -170,12 +170,12 @@ const struct address_space_operations hfsplus_aops = {
 	.dirty_folio	= block_dirty_folio,
 	.invalidate_folio = block_invalidate_folio,
 	.read_folio	= hfsplus_read_folio,
-	.writepage	= hfsplus_writepage,
 	.write_begin	= hfsplus_write_begin,
 	.write_end	= generic_write_end,
 	.bmap		= hfsplus_bmap,
 	.direct_IO	= hfsplus_direct_IO,
 	.writepages	= hfsplus_writepages,
+	.migrate_folio	= buffer_migrate_folio,
 };
 
 const struct dentry_operations hfsplus_dentry_operations = {
Signature · 1 line
2.30.2
#14 lore raw

PATCH 6/9 hpfs: remove ->writepage

In reply to Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Set ->migrate_folio to the generic buffer_head based helper, and remove the ->writepage implementation.

---
 fs/hpfs/file.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
fs/hpfs/file.c +2 -7
index f7547a62c81f6..88952d4a631e6 100644
@@ -163,11 +163,6 @@ static int hpfs_read_folio(struct file *file, struct folio *folio)
 	return mpage_read_folio(folio, hpfs_get_block);
 }
 
-static int hpfs_writepage(struct page *page, struct writeback_control *wbc)
-{
-	return block_write_full_page(page, hpfs_get_block, wbc);
-}
-
 static void hpfs_readahead(struct readahead_control *rac)
 {
 	mpage_readahead(rac, hpfs_get_block);
@@ -248,12 +243,12 @@ const struct address_space_operations hpfs_aops = {
 	.dirty_folio	= block_dirty_folio,
 	.invalidate_folio = block_invalidate_folio,
 	.read_folio = hpfs_read_folio,
-	.writepage = hpfs_writepage,
 	.readahead = hpfs_readahead,
 	.writepages = hpfs_writepages,
 	.write_begin = hpfs_write_begin,
 	.write_end = hpfs_write_end,
-	.bmap = _hpfs_bmap
+	.bmap = _hpfs_bmap,
+	.migrate_folio = buffer_migrate_folio,
 };
 
 const struct file_operations hpfs_file_ops =
Signature · 1 line
2.30.2
#15 lore raw

PATCH 7/9 jfs: remove ->writepage

In reply to Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Set ->migrate_folio to the generic buffer_head based helper, and remove the ->writepage implementation.

---
 fs/jfs/inode.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/jfs/inode.c +1 -6
index d1ec920aa030a..8ac10e3960508 100644
@@ -264,11 +264,6 @@ int jfs_get_block(struct inode *ip, sector_t lblock,
 	return rc;
 }
 
-static int jfs_writepage(struct page *page, struct writeback_control *wbc)
-{
-	return block_write_full_page(page, jfs_get_block, wbc);
-}
-
 static int jfs_writepages(struct address_space *mapping,
 			struct writeback_control *wbc)
 {
@@ -355,12 +350,12 @@ const struct address_space_operations jfs_aops = {
 	.invalidate_folio = block_invalidate_folio,
 	.read_folio	= jfs_read_folio,
 	.readahead	= jfs_readahead,
-	.writepage	= jfs_writepage,
 	.writepages	= jfs_writepages,
 	.write_begin	= jfs_write_begin,
 	.write_end	= jfs_write_end,
 	.bmap		= jfs_bmap,
 	.direct_IO	= jfs_direct_IO,
+	.migrate_folio	= buffer_migrate_folio,
 };
 
 /*
Signature · 1 line
2.30.2
Acked-by on v1 7/9
#16 lore raw

Re: [PATCH 7/9] jfs: remove ->writepage

Quoted 8 lines · Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Set ->migrate_folio to the generic buffer_head based helper, and remove the ->writepage implementation.

Quoted 34 lines
---
  fs/jfs/inode.c | 7 +------
  1 file changed, 1 insertion(+), 6 deletions(-)
fs/jfs/inode.c +1 -6
index d1ec920aa030a..8ac10e3960508 100644
@@ -264,11 +264,6 @@ int jfs_get_block(struct inode *ip, sector_t lblock,
  	return rc;
  }
 
-static int jfs_writepage(struct page *page, struct writeback_control *wbc)
-{
-	return block_write_full_page(page, jfs_get_block, wbc);
-}
-
  static int jfs_writepages(struct address_space *mapping,
  			struct writeback_control *wbc)
  {
@@ -355,12 +350,12 @@ const struct address_space_operations jfs_aops = {
  	.invalidate_folio = block_invalidate_folio,
  	.read_folio	= jfs_read_folio,
  	.readahead	= jfs_readahead,
-	.writepage	= jfs_writepage,
  	.writepages	= jfs_writepages,
  	.write_begin	= jfs_write_begin,
  	.write_end	= jfs_write_end,
  	.bmap		= jfs_bmap,
  	.direct_IO	= jfs_direct_IO,
+	.migrate_folio	= buffer_migrate_folio,
  };
 
  /*
#17 lore raw

PATCH 8/9 omfs: remove ->writepage

In reply to Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Set ->migrate_folio to the generic buffer_head based helper, and remove the ->writepage implementation.

---
 fs/omfs/file.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/omfs/file.c +1 -6
index fa7fe2393ff68..3a5b4b88a5838 100644
@@ -294,11 +294,6 @@ static void omfs_readahead(struct readahead_control *rac)
 	mpage_readahead(rac, omfs_get_block);
 }
 
-static int omfs_writepage(struct page *page, struct writeback_control *wbc)
-{
-	return block_write_full_page(page, omfs_get_block, wbc);
-}
-
 static int
 omfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
 {
@@ -375,10 +370,10 @@ const struct address_space_operations omfs_aops = {
 	.invalidate_folio = block_invalidate_folio,
 	.read_folio = omfs_read_folio,
 	.readahead = omfs_readahead,
-	.writepage = omfs_writepage,
 	.writepages = omfs_writepages,
 	.write_begin = omfs_write_begin,
 	.write_end = generic_write_end,
 	.bmap = omfs_bmap,
+	.migrate_folio = buffer_migrate_folio,
 };
 
Signature · 1 line
2.30.2
maintainer Acked-by on v1 8/9
#18 lore raw

Re: [PATCH 8/9] omfs: remove ->writepage

Quoted 8 lines · Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Set ->migrate_folio to the generic buffer_head based helper, and remove the ->writepage implementation.

Looks good,

Signature · 1 line
Bob Copeland %% https://bobcopeland.com/
#19 lore raw

PATCH 9/9 udf: remove ->writepage

In reply to Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Set ->migrate_folio to the generic buffer_head based helper, and remove the ->writepage implementation in extfat.

---
 fs/udf/inode.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/udf/inode.c +1 -6
index dce6ae9ae306c..0246b1b86fb91 100644
@@ -182,11 +182,6 @@ static void udf_write_failed(struct address_space *mapping, loff_t to)
 	}
 }
 
-static int udf_writepage(struct page *page, struct writeback_control *wbc)
-{
-	return block_write_full_page(page, udf_get_block, wbc);
-}
-
 static int udf_writepages(struct address_space *mapping,
 			struct writeback_control *wbc)
 {
@@ -239,12 +234,12 @@ const struct address_space_operations udf_aops = {
 	.invalidate_folio = block_invalidate_folio,
 	.read_folio	= udf_read_folio,
 	.readahead	= udf_readahead,
-	.writepage	= udf_writepage,
 	.writepages	= udf_writepages,
 	.write_begin	= udf_write_begin,
 	.write_end	= generic_write_end,
 	.direct_IO	= udf_direct_IO,
 	.bmap		= udf_bmap,
+	.migrate_folio	= buffer_migrate_folio,
 };
 
 /*
Signature · 1 line
2.30.2
reviewer Acked-by on v1 9/9
#20 lore raw

Re: [PATCH 9/9] udf: remove ->writepage

Quoted 8 lines · Christoph Hellwig

->writepage is a very inefficient method to write back data, and only used through write_cache_pages or a a fallback when no ->migrate_folio method is present.

Set ->migrate_folio to the generic buffer_head based helper, and remove the ->writepage implementation in extfat.

Looks good. Feel free to add:

Honza

Quoted 37 lines
---
 fs/udf/inode.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
fs/udf/inode.c +1 -6
index dce6ae9ae306c..0246b1b86fb91 100644
@@ -182,11 +182,6 @@ static void udf_write_failed(struct address_space *mapping, loff_t to)
 	}
 }
 
-static int udf_writepage(struct page *page, struct writeback_control *wbc)
-{
-	return block_write_full_page(page, udf_get_block, wbc);
-}
-
 static int udf_writepages(struct address_space *mapping,
 			struct writeback_control *wbc)
 {
@@ -239,12 +234,12 @@ const struct address_space_operations udf_aops = {
 	.invalidate_folio = block_invalidate_folio,
 	.read_folio	= udf_read_folio,
 	.readahead	= udf_readahead,
-	.writepage	= udf_writepage,
 	.writepages	= udf_writepages,
 	.write_begin	= udf_write_begin,
 	.write_end	= generic_write_end,
 	.direct_IO	= udf_direct_IO,
 	.bmap		= udf_bmap,
+	.migrate_folio	= buffer_migrate_folio,
 };
 
 /*
Signature · 1 line
2.30.2
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#21 lore raw
In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

Hi all,

The VM doesn't need or want ->writepage for writeback and is fine with just having ->writepages as long as ->migrate_folio is implemented.

This series removes all ->writepage instances that use block_write_full_page directly and also have a plain mpage_writepages based ->writepages.

The series looks good from the MM side.

#22 lore raw
In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

Hi all,

The VM doesn't need or want ->writepage for writeback and is fine with just having ->writepages as long as ->migrate_folio is implemented.

Ok, so here is, (what I think) is the motivation for doing this. Please correct me if this is incorrect...
1. writepage is mainly called from pageout, which happens as part of the memory reclaim. Now IIUC from previous discussions [1][2][3], reclaims happens from the tail end of the LRU list which could do an I/O of a single page while an ongoing writeback was in progress of multiple pages. This disrupts the I/O pattern to become more random in nature, compared to, if we would have let writeback/flusher do it's job of writing back dirty pages.

Also many filesystems behave very differently within their ->writepage calls, e.g. ext4 doesn't actually write in ->writepage for DELAYED blocks.

2. Now the other place from where ->writepage can be called from is, writeout() function, which is a fallback function for migration (fallback_migrate_folio()). fallback_migrate_folio() is called from move_to_new_folio() if ->migrate_folio is not defined for the FS.

So what you are doing here is removing the ->writepage from address_space operations of the filesystems which implements ->writepage using block_write_full_page() (i.e. those who uses buffer_heads). This is done for those FS who already have ->migrate_folio() implemented (hence no need of ->writepage).
...Now this is also a step towards reducing the callers from kernel which uses buffer_heads.

[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/
[3]: https://lore.kernel.org/all/[email protected]/

Is above a correct understanding?

Quoted 4 lines

This series removes all ->writepage instances that use block_write_full_page directly and also have a plain mpage_writepages based ->writepages.

Ok.

Quoted 12 lines

Diffstat:

 fs/exfat/inode.c   |    9 ++-------
 fs/ext2/inode.c    |    6 ------
 fs/fat/inode.c     |    9 ++-------
 fs/hfs/inode.c     |    2 +-
 fs/hfsplus/inode.c |    2 +-
 fs/hpfs/file.c     |    9 ++-------
 fs/jfs/inode.c     |    7 +------
 fs/omfs/file.c     |    7 +------
 fs/udf/inode.c     |    7 +------
 9 files changed, 11 insertions(+), 47 deletions(-)
#23 lore raw

Also ->writepage() is called with the page already locked, which is a problem if you need to write out a number of surrounding pages with it.

David

#24 lore raw
In reply to Ritesh Harjani (IBM)
Quoted 5 lines · Ritesh Harjani (IBM)

reclaim. Now IIUC from previous discussions [1][2][3], reclaims happens from the tail end of the LRU list which could do an I/O of a single page while an ongoing writeback was in progress of multiple pages. This disrupts the I/O pattern to become more random in nature, compared to, if we would have let writeback/flusher do it's job of writing back dirty pages.

Yes.

Quoted 2 lines

Also many filesystems behave very differently within their ->writepage calls, e.g. ext4 doesn't actually write in ->writepage for DELAYED blocks.

I don't think it's many file systems. As far as I can tell only ext4 actually is significantly different.

Quoted 4 lines

2. Now the other place from where ->writepage can be called from is, writeout() function, which is a fallback function for migration (fallback_migrate_folio()). fallback_migrate_folio() is called from move_to_new_folio() if ->migrate_folio is not defined for the FS.

Also there is generic_writepages and folio_write_one/write_one_page.

Quoted 1 line

Is above a correct understanding?

Yes.

#25 lore raw
In reply to Christoph Hellwig
Quoted 2 lines · Christoph Hellwig

The VM doesn't need or want ->writepage for writeback and is fine with just having ->writepages as long as ->migrate_folio is implemented.

Yay! :-)

David