Re: [f2fs-dev] [PATCH v2 04/14] f2fs: support atomic file large folios buffered write
From: Nanzhe Zhao
Date: Tue Sep 22 2026 - 23:22:40 EST
Hi Chao,
Thanks for the review.
I think I can extract the duplicate logic in a helper and the full change
may be like this?
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -4721,6 +4721,31 @@
return 0;
}
+static bool f2fs_try_balance_folio(struct folio *folio,
+ struct address_space *mapping, bool node_changed)
+{
+ struct inode *inode = folio->mapping->host;
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ unsigned int orig_order;
+
+ if (!node_changed || IS_NOQUOTA(inode) ||
+ !has_not_enough_free_secs(sbi, 0, 0))
+ return false;
+
+ orig_order = folio_order(folio);
+ folio_unlock(folio);
+ f2fs_balance_fs(sbi, true);
+ folio_lock(folio);
+
+ if (folio->mapping != mapping)
+ return true;
+
+ if (folio_order(folio) != orig_order)
+ return true;
+
+ return false;
+}
+
static int prepare_large_folio_atomic_write_begin(struct inode *inode,
struct address_space *mapping, struct folio *folio, loff_t pos,
unsigned int len)
@@ -4728,7 +4753,6 @@
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
size_t ori_off = offset_in_folio(folio, pos);
pgoff_t start, end, index;
- unsigned int orig_order;
int err = 0;
len = min_t(unsigned int, len, folio_size(folio) - ori_off);
@@ -4774,16 +4798,8 @@
* Expand the 4K-page balance decision per subpage: check
* right after each preallocated block.
*/
- if (node_changed && !IS_NOQUOTA(inode) &&
- has_not_enough_free_secs(sbi, 0, 0)) {
- orig_order = folio_order(folio);
- folio_unlock(folio);
- f2fs_balance_fs(sbi, true);
- folio_lock(folio);
- if (unlikely(folio->mapping != mapping ||
- folio_order(folio) != orig_order))
- return -EAGAIN;
- }
+ if (f2fs_try_balance_folio(folio, mapping, node_changed))
+ return -EAGAIN;
}
return 0;
@@ -4876,17 +4892,10 @@
if (err)
goto put_folio;
- if (need_balance && !IS_NOQUOTA(inode) &&
- has_not_enough_free_secs(sbi, 0, 0)) {
+ if (f2fs_try_balance_folio(folio, mapping, need_balance)) {
folio_unlock(folio);
- f2fs_balance_fs(sbi, true);
- folio_lock(folio);
- if (folio->mapping != mapping) {
- /* The folio got truncated from under us */
- folio_unlock(folio);
- folio_put(folio);
- goto repeat;
- }
+ folio_put(folio);
+ goto repeat;
}
f2fs_folio_wait_writeback(folio, DATA, false, true);
--
Nanzhe Zhao