[PATCH] f2fs: use submitted bio size for completion offload

From: Wenjie Qi

Date: Thu Oct 08 2026 - 05:39:39 EST


blk_update_request() advances bio->bi_iter before completing a bio.
As a result, f2fs_write_end_io() may see bi_size == 0 and fail to
offload large write bios according to max_atc_write_bio_size.

Save the submitted bio size and use it for the completion offload check.

Fixes: 3de6b8094115 ("f2fs: Run f2fs_write_end_io() asynchronously")
Signed-off-by: Wenjie Qi <qiwenjie@xxxxxxxxxx>
---
Based on f2fs/dev-test at ce439a2b0690. This includes the entry-count
threshold change; its condition is preserved by this patch.

fs/f2fs/data.c | 7 +++++--
fs/f2fs/f2fs.h | 1 +
2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 2613e8821af6d..a5c11cbfda813 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -398,8 +398,9 @@ static void f2fs_write_end_io(struct bio *bio)

sbi = bio->bi_private;

- if (in_atomic() && (bio->bi_iter.bi_size > sbi->max_atc_write_bio_size ||
- F2FS_BIO(bio)->entry_cnt > sbi->max_atc_write_bio_entry_cnt)) {
+ if (in_atomic() &&
+ (F2FS_BIO(bio)->submitted_size > sbi->max_atc_write_bio_size ||
+ F2FS_BIO(bio)->entry_cnt > sbi->max_atc_write_bio_entry_cnt)) {
struct work_struct *w;

w = &container_of(bio, struct f2fs_bio, bio)->work;
@@ -614,6 +615,8 @@ static void f2fs_submit_write_bio(struct f2fs_sb_info *sbi, struct bio *bio,
{
WARN_ON_ONCE(is_read_io(bio_op(bio)));
trace_f2fs_submit_write_bio(sbi->sb, type, bio);
+ /* bi_iter may be advanced by the block layer before end_io. */
+ F2FS_BIO(bio)->submitted_size = bio->bi_iter.bi_size;
iostat_update_submit_ctx(bio, type);
blk_crypto_submit_bio(bio);
}
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 0acbc4d299af1..1b2390f39a68e 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1779,6 +1779,7 @@ struct f2fs_bio {
struct work_struct work;
struct f2fs_cached_block *entry;
unsigned int entry_cnt;
+ unsigned int submitted_size;
struct bio bio;
};

--
2.43.0