cleanup AOP_WRITEPAGE_ACTIVATE use in f2fs
Hi all,
this almost entirely cleans up usage of AOP_WRITEPAGE_ACTIVATE in f2fs.
f2fs_sync_node_pages can still return it in a way that is not handled by any caller and eventually is propagated to userspace. This does look like a bug and needs attention by someone who actually knows the code.
Diffstat:
checkpoint.c | 22 +++++++++++----------- compress.c | 5 +---- data.c | 13 ++++--------- node.c | 43 ++++++++++++++++++++----------------------- 4 files changed, 36 insertions(+), 47 deletions(-)
PATCH 1/4 f2fs: return bool from __f2fs_write_meta_folio
__f2fs_write_meta_folio can only return 0 or AOP_WRITEPAGE_ACTIVATE. As part of phasing out AOP_WRITEPAGE_ACTIVATE, switch to a bool return instead.
--- fs/f2fs/checkpoint.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
fs/f2fs/checkpoint.c +11 -11
@@ -340,7 +340,7 @@ void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index,f2fs_ra_meta_pages (sbi, index, ra_blocks,META_POR , true); } -static int __f2fs_write_meta_folio (struct folio *folio, +static bool __f2fs_write_meta_folio (struct folio *folio,struct writeback_control *wbc,enum iostat_type io_type) {
@@ -353,7 +353,7 @@ static int __f2fs_write_meta_folio(struct folio *folio,folio_clear_uptodate (folio);dec_page_count (sbi,F2FS_DIRTY_META );folio_unlock (folio); -return 0 ; +return true; } goto redirty_out; }
@@ -373,11 +373,11 @@ static int __f2fs_write_meta_folio(struct folio *folio,if (unlikely (f2fs_cp_error (sbi)))f2fs_submit_merged_write (sbi,META ); -return 0 ; +return true; redirty_out:folio_redirty_for_writepage (wbc, folio); -return AOP_WRITEPAGE_ACTIVATE ; +return false; } static int f2fs_write_meta_pages(struct address_space *mapping,
@@ -461,7 +461,7 @@ long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,if (!folio_clear_dirty_for_io (folio)) goto continue_unlock; -if (__f2fs_write_meta_folio (folio, &wbc, +if (!__f2fs_write_meta_folio (folio, &wbc, io_type)) {folio_unlock (folio);break ;
@@ -1409,7 +1409,6 @@ static void commit_checkpoint(struct f2fs_sb_info *sbi,* f2fs_sync_meta_pages are combined in this function. */ struct folio *folio =f2fs_grab_meta_folio (sbi, blk_addr); -int err;memcpy (folio_address (folio), src,PAGE_SIZE );
@@ -1418,13 +1417,14 @@ static void commit_checkpoint(struct f2fs_sb_info *sbi,f2fs_bug_on (sbi,1 );/* writeout cp pack 2 page */ - err =__f2fs_write_meta_folio (folio, &wbc,FS_CP_META_IO ); -if (unlikely (err &&f2fs_cp_error (sbi))) { -f2fs_folio_put (folio, true); -return ; +if (unlikely (!__f2fs_write_meta_folio (folio, &wbc,FS_CP_META_IO ))) { +if (f2fs_cp_error (sbi)) { +f2fs_folio_put (folio, true); +return ; + } +f2fs_bug_on (sbi, true); } -f2fs_bug_on (sbi, err);f2fs_folio_put (folio, false);/* submit checkpoint (with barrier if NOBARRIER is not set) */
Signature · 1 line
2.47.2
Re: [PATCH 1/4] f2fs: return bool from __f2fs_write_meta_folio
Quoted 5 lines · Christoph Hellwig
__f2fs_write_meta_foliocan only return 0 orAOP_WRITEPAGE_ACTIVATE. As part of phasing outAOP_WRITEPAGE_ACTIVATE, switch to a bool return instead.Signed-off-by Christoph Hellwig <[email protected]>
Thanks,
Re: [f2fs-dev] [PATCH 1/4] f2fs: return bool from __f2fs_write_meta_folio
In reply to Christoph HellwigThis series was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:
Quoted 8 lines · On Mon, 5 May 2025 11:25:58 +0200 you wrote:
__f2fs_write_meta_foliocan only return 0 orAOP_WRITEPAGE_ACTIVATE. As part of phasing outAOP_WRITEPAGE_ACTIVATE, switch to a bool return instead.Signed-off-by Christoph Hellwig <[email protected]>--- fs/f2fs/checkpoint.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
Here is the summary with links:
- [f2fs-dev,1/4] f2fs: return bool from __f2fs_write_meta_folio
https://git.kernel.org/jaegeuk/f2fs/c/39122e454419
- [f2fs-dev,2/4] f2fs: don't return AOP_WRITEPAGE_ACTIVATE from f2fs_write_single_data_page (no matching commit)
- [f2fs-dev,3/4] f2fs: simplify return value handling in f2fs_fsync_node_pages (no matching commit)
- [f2fs-dev,4/4] f2f2: return bool from __write_node_folio
(no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
PATCH 2/4 f2fs: don't return AOP_WRITEPAGE_ACTIVATE from f2fs_write_single_data_page
In reply to Christoph HellwigInstead unlock the pages locally where that would happen and thus consolidate the code in the callers.
--- fs/f2fs/compress.c | 5 +---- fs/f2fs/data.c | 13 ++++--------- 2 files changed, 5 insertions(+), 13 deletions(-)
fs/f2fs/compress.c +1 -4
@@ -1565,10 +1565,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc,NULL ,NULL , wbc, io_type, compr_blocks, false);if (ret) { -if (ret ==AOP_WRITEPAGE_ACTIVATE ) { -folio_unlock (folio); - ret =0 ; - }else if (ret == -EAGAIN ) { +if (ret == -EAGAIN ) { ret =0 ;/* * for quota file, just redirty left pages to
fs/f2fs/data.c +4 -9
@@ -2930,10 +2930,10 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,* file_write_and_wait_range() will see EIO error, which is critical * to return value of fsync() followed by atomic_write failure to user. */ -if (!err || wbc->for_reclaim) -return AOP_WRITEPAGE_ACTIVATE ;folio_unlock (folio); -return err; +if (err && !wbc->for_reclaim) +return err; +return 0 ; }/*
@@ -3146,8 +3146,6 @@ static int f2fs_write_cache_pages(struct address_space *mapping, ret =f2fs_write_single_data_page (folio, &submitted, &bio, &last_block, wbc, io_type,0 , true); -if (ret ==AOP_WRITEPAGE_ACTIVATE ) -folio_unlock (folio);#ifdef CONFIG_F2FS_FS_COMPRESSION result:#endif
@@ -3159,10 +3157,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping,* keep nr_to_write, since vfs uses this to * get # of written pages. */ -if (ret ==AOP_WRITEPAGE_ACTIVATE ) { - ret =0 ; - goto next; - }else if (ret == -EAGAIN ) { +if (ret == -EAGAIN ) { ret =0 ;if (wbc->sync_mode ==WB_SYNC_ALL ) { f2fs_io_schedule_timeout(
Signature · 1 line
2.47.2
Chao Yu
maintainerRe: [PATCH 2/4] f2fs: don't return AOP_WRITEPAGE_ACTIVATE from f2fs_write_single_data_page
Quoted 14 lines · Christoph Hellwig
Instead unlock the pages locally where that would happen and thus consolidate the code in the callers.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/f2fs/compress.c | 5 +---- fs/f2fs/data.c | 13 ++++--------- 2 files changed, 5 insertions(+), 13 deletions(-)fs/f2fs/compress.c +0
-0
fs/f2fs/compress.c static int f2fs_write_raw_pages(struct compress_ctx *cc, · line 1570
Quoted 6 lines
fs/f2fs/compress.c +0
-3@@ -1565,10 +1565,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc,NULL ,NULL , wbc, io_type, compr_blocks, false);if (ret) { -if (ret ==AOP_WRITEPAGE_ACTIVATE ) { -folio_unlock (folio); - ret =0 ;
Previously, for this case, it will goto out label rather than writing left pages?
Thanks,
Quoted 44 lines
fs/f2fs/compress.c +1
-1- }else if (ret == -EAGAIN ) { +if (ret == -EAGAIN ) { ret =0 ;/* * for quota file, just redirty left pages to fs/f2fs/data.c +4
-9@@ -2930,10 +2930,10 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,* file_write_and_wait_range() will see EIO error, which is critical * to return value of fsync() followed by atomic_write failure to user. */ -if (!err || wbc->for_reclaim) -return AOP_WRITEPAGE_ACTIVATE ;folio_unlock (folio); -return err; +if (err && !wbc->for_reclaim) +return err; +return 0 ; }/* @@ -3146,8 +3146,6 @@ static int f2fs_write_cache_pages(struct address_space *mapping, ret =f2fs_write_single_data_page (folio, &submitted, &bio, &last_block, wbc, io_type,0 , true); -if (ret ==AOP_WRITEPAGE_ACTIVATE ) -folio_unlock (folio);#ifdef CONFIG_F2FS_FS_COMPRESSION result:#endif @@ -3159,10 +3157,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping,* keep nr_to_write, since vfs uses this to * get # of written pages. */ -if (ret ==AOP_WRITEPAGE_ACTIVATE ) { - ret =0 ; - goto next; - }else if (ret == -EAGAIN ) { +if (ret == -EAGAIN ) { ret =0 ;if (wbc->sync_mode ==WB_SYNC_ALL ) { f2fs_io_schedule_timeout(
Re: [PATCH 2/4] f2fs: don't return AOP_WRITEPAGE_ACTIVATE from f2fs_write_single_data_page
Quoted 6 lines · Chao Yu
Quoted 6 lines
fs/f2fs/compress.c +0
-0@@ -1565,10 +1565,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, NULL, NULL, wbc, io_type,
Quoted 8 lines
fs/f2fs/compress.c static int f2fs_write_raw_pages(struct compress_ctx *cc, · line 1570
Quoted 5 lines
fs/f2fs/compress.c +0
-3compr_blocks, false);if (ret) { -if (ret ==AOP_WRITEPAGE_ACTIVATE ) { -folio_unlock (folio); - ret =0 ;Previously, for this case, it will goto out label rather than writing left pages?
Indeed. Is that the right thing to do here?
Chao Yu
maintainerRe: [PATCH 2/4] f2fs: don't return AOP_WRITEPAGE_ACTIVATE from f2fs_write_single_data_page
Quoted 16 lines · Christoph Hellwig
Quoted 6 lines · Chao Yu
Quoted 6 lines
fs/f2fs/compress.c +0
-0@@ -1565,10 +1565,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, NULL, NULL, wbc, io_type,Quoted 8 lines
fs/f2fs/compress.c static int f2fs_write_raw_pages(struct compress_ctx *cc, · line 1570
Quoted 5 lines
fs/f2fs/compress.c +0
-3compr_blocks, false);if (ret) { -if (ret ==AOP_WRITEPAGE_ACTIVATE ) { -folio_unlock (folio); - ret =0 ;Previously, for this case, it will goto out label rather than writing left pages?
Quoted 1 line
Indeed. Is that the right thing to do here?
IIRC, once it failed to write one page, it redirties all left pages, and tries to rewrite them again, it can avoid fragment as much as possible.
So can we keep original implementation here?
Thanks,
PATCH 3/4 f2fs: simplify return value handling in f2fs_fsync_node_pages
In reply to Christoph HellwigAlways assign ret where the error happens, and jump to out instead of multiple loop exit conditions to prepare for changes in the __write_node_folio calling convention.
--- fs/f2fs/node.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
fs/f2fs/node.c +9 -9
@@ -1882,17 +1882,17 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,if (!folio_clear_dirty_for_io (folio)) goto continue_unlock; - ret =__write_node_folio (folio, atomic && +if (__write_node_folio (folio, atomic && folio == last_folio, &submitted, wbc, true, -FS_NODE_IO , seq_id); -if (ret) { +FS_NODE_IO , seq_id)) {folio_unlock (folio);f2fs_folio_put (last_folio, false); -break ; - }else if (submitted) { - nwritten++; + ret = -EIO ; + goto out; } +if (submitted) + nwritten++;if (folio == last_folio) {f2fs_folio_put (folio, false);
@@ -1903,10 +1903,10 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,folio_batch_release (&fbatch);cond_resched (); -if (ret || marked) +if (marked)break ; } -if (!ret && atomic && !marked) { +if (atomic && !marked) {f2fs_debug (sbi,"Retry to write fsync mark: ino=%u, idx=%lx" , ino, last_folio->index);folio_lock (last_folio);
@@ -1918,7 +1918,7 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, out:if (nwritten)f2fs_submit_merged_write_cond (sbi,NULL ,NULL , ino,NODE ); -return ret ? -EIO :0 ; +return ret; }static int f2fs_match_ino (struct inode *inode,unsigned long ino,void *data)
Signature · 1 line
2.47.2
Chao Yu
maintainerRe: [PATCH 3/4] f2fs: simplify return value handling in f2fs_fsync_node_pages
Quoted 21 lines · Christoph Hellwig
Always assign ret where the error happens, and jump to out instead of multiple loop exit conditions to prepare for changes in the
__write_node_foliocalling convention.Signed-off-by Christoph Hellwig <[email protected]>--- fs/f2fs/node.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)fs/f2fs/node.c +1
-1@@ -1882,17 +1882,17 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,if (!folio_clear_dirty_for_io (folio)) goto continue_unlock; - ret = __write_node_folio(folio, atomic && + if (__write_node_folio(folio, atomic && folio == last_folio, &submitted, wbc, true,
fs/f2fs/node.c int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, · line 1892
Quoted 10 lines
fs/f2fs/node.c +3
-5- FS_NODE_IO, seq_id); -if (ret) { + FS_NODE_IO, seq_id)) {folio_unlock (folio);f2fs_folio_put (last_folio, false); -break ; - }else if (submitted) { - nwritten++; + ret = -EIO ; + goto out;
It missed to call folio_batch_release() here?
Thanks,
Quoted 28 lines
fs/f2fs/node.c +5
-3} +if (submitted) + nwritten++;if (folio == last_folio) {f2fs_folio_put (folio, false);@@ -1903,10 +1903,10 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,folio_batch_release (&fbatch);cond_resched (); -if (ret || marked) +if (marked)break ; } -if (!ret && atomic && !marked) { +if (atomic && !marked) {f2fs_debug (sbi,"Retry to write fsync mark: ino=%u, idx=%lx" , ino, last_folio->index);folio_lock (last_folio);@@ -1918,7 +1918,7 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, out:if (nwritten)f2fs_submit_merged_write_cond (sbi,NULL ,NULL , ino,NODE ); -return ret ? -EIO :0 ; +return ret; }static int f2fs_match_ino (struct inode *inode,unsigned long ino,void *data)
PATCH 4/4 f2f2: return bool from __write_node_folio
In reply to Christoph Hellwig__write_node_folio can only return 0 or AOP_WRITEPAGE_ACTIVATE. As part of phasing out AOP_WRITEPAGE_ACTIVATE, switch to a bool return instead.
--- fs/f2fs/node.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)
fs/f2fs/node.c +12 -15
@@ -1651,7 +1651,7 @@ static struct folio *last_fsync_dnode(struct f2fs_sb_info *sbi, nid_t ino)return last_folio; } -static int __write_node_folio (struct folio *folio,bool atomic,bool *submitted, +static bool __write_node_folio (struct folio *folio,bool atomic,bool *submitted,struct writeback_control *wbc,bool do_balance,enum iostat_type io_type,unsigned int *seq_id) {
@@ -1681,7 +1681,7 @@ static int __write_node_folio(struct folio *folio, bool atomic, bool *submitted,folio_clear_uptodate (folio);dec_page_count (sbi,F2FS_DIRTY_NODES );folio_unlock (folio); -return 0 ; +return true; }if (unlikely (is_sbi_flag_set (sbi,SBI_POR_DOING )))
@@ -1712,7 +1712,7 @@ static int __write_node_folio(struct folio *folio, bool atomic, bool *submitted,dec_page_count (sbi,F2FS_DIRTY_NODES );f2fs_up_read (&sbi->node_write);folio_unlock (folio); -return 0 ; +return true; } if (__is_valid_data_blkaddr(ni.blk_addr) &&
@@ -1756,11 +1756,12 @@ static int __write_node_folio(struct folio *folio, bool atomic, bool *submitted,if (do_balance)f2fs_balance_fs (sbi, false); -return 0 ; +return true; redirty_out:folio_redirty_for_writepage (wbc, folio); -return AOP_WRITEPAGE_ACTIVATE ; +folio_unlock (folio); +return false; }int f2fs_move_node_folio (struct folio *node_folio,int gc_type)
@@ -1783,11 +1784,9 @@ int f2fs_move_node_folio(struct folio *node_folio, int gc_type) goto out_page; } -if (__write_node_folio (node_folio, false,NULL , - &wbc, false,FS_GC_NODE_IO ,NULL )) { +if (!__write_node_folio (node_folio, false,NULL , + &wbc, false,FS_GC_NODE_IO ,NULL )) err = -EAGAIN ; -folio_unlock (node_folio); - } goto release_page; }else {/* set page dirty and write it */
@@ -1882,11 +1881,10 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,if (!folio_clear_dirty_for_io (folio)) goto continue_unlock; -if (__write_node_folio (folio, atomic && +if (!__write_node_folio (folio, atomic && folio == last_folio, &submitted, wbc, true,FS_NODE_IO , seq_id)) { -folio_unlock (folio);f2fs_folio_put (last_folio, false); ret = -EIO ; goto out;
@@ -2090,10 +2088,9 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,set_fsync_mark (&folio->page,0 );set_dentry_mark (&folio->page,0 ); - ret =__write_node_folio (folio, false, &submitted, - wbc, do_balance, io_type,NULL ); -if (ret) -folio_unlock (folio); +if (!__write_node_folio (folio, false, &submitted, + wbc, do_balance, io_type,NULL )) + ret =AOP_WRITEPAGE_ACTIVATE ;else if (submitted) nwritten++;
Signature · 1 line
2.47.2
Re: [PATCH 4/4] f2f2: return bool from __write_node_folio
Quoted 5 lines · Christoph Hellwig
__write_node_foliocan only return 0 orAOP_WRITEPAGE_ACTIVATE. As part of phasing outAOP_WRITEPAGE_ACTIVATE, switch to a bool return instead.Signed-off-by Christoph Hellwig <[email protected]>
Thanks,
Chao Yu
maintainerQuoted 7 lines · Christoph Hellwig
Hi all,
this almost entirely cleans up usage of
AOP_WRITEPAGE_ACTIVATEin f2fs.
f2fs_sync_node_pagescan still return it in a way that is not handled by any caller and eventually is propagated to userspace. This does look like a bug and needs attention by someone who actually knows the code.
Oh, I guess this is a bug, thanks for catching this.
Anyway, let me fix this based on your patchset.
Thanks,
Quoted 7 lines
Diffstat:
checkpoint.c | 22 +++++++++++----------- compress.c | 5 +---- data.c | 13 ++++--------- node.c | 43 ++++++++++++++++++++----------------------- 4 files changed, 36 insertions(+), 47 deletions(-)
Quoted 5 lines · Chao Yu
Quoted 4 lines · Christoph Hellwig
Hi all,
this almost entirely cleans up usage of
AOP_WRITEPAGE_ACTIVATEin f2fs.
Quoted 7 lines
Quoted 3 lines
f2fs_sync_node_pagescan still return it in a way that is not handled by any caller and eventually is propagated to userspace. This does look like a bug and needs attention by someone who actually knows the code.Oh, I guess this is a bug, thanks for catching this.
Anyway, let me fix this based on your patchset.
I'll resend a fixed version later today, maybe wait for that.
Chao Yu
maintainerQuoted 10 lines · Christoph Hellwig
Quoted 9 lines · Chao Yu
Quoted 7 lines · Christoph Hellwig
Hi all,
this almost entirely cleans up usage of
AOP_WRITEPAGE_ACTIVATEin f2fs.
f2fs_sync_node_pagescan still return it in a way that is not handled by any caller and eventually is propagated to userspace. This does look like a bug and needs attention by someone who actually knows the code.
Quoted 5 lines
Quoted 3 lines
Oh, I guess this is a bug, thanks for catching this.
Anyway, let me fix this based on your patchset.
I'll resend a fixed version later today, maybe wait for that.
I've submitted a patch, maybe you can rebase new version on it?
https://lore.kernel.org/linux-f2fs-devel/[email protected]
Thanks,