[PATCH v6 1/2] f2fs: complete dropbehind write bios in task context

From: Wenjie Qi

Date: Fri Nov 27 2026 - 03:49:54 EST


Mark dropbehind write bios BIO_COMPLETE_IN_TASK so the block layer can
defer their completion to task context before folio invalidation.

Allow normal and dropbehind folios to share IPU and OPU bios. Set the
flag after a dropbehind folio is successfully added, checking the original
page-cache folio rather than an encrypted or compressed replacement.

Exclude metadata-cache I/O, which may not have a file-data folio. Leave
the existing large-ATC completion path unchanged.

Signed-off-by: Wenjie Qi <qiwenjie@xxxxxxxxxx>
---
Changes since v5:

- Rebase onto dev, preserving the updated bio_len/bio_offset merge paths.
- Skip metadata-cache I/O before testing the original folio's hint.

fs/f2fs/data.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index cdc9e6e8633c..37d74afc8b26 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -624,6 +624,9 @@ static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages)
bio = bio_alloc_bioset(bdev, npages,
fio->op | fio->op_flags | f2fs_io_flags(fio),
GFP_NOIO, &f2fs_bioset);
+ if (!is_read_io(fio->op) && !fio->is_cache &&
+ folio_test_dropbehind(fio->folio))
+ bio_set_flag(bio, BIO_COMPLETE_IN_TASK);
bio->bi_iter.bi_sector = sector;
F2FS_BIO(bio)->entry = NULL;
bio->bi_private = NULL;
@@ -1077,6 +1080,8 @@ static int add_ipu_page(struct f2fs_io_info *fio, struct bio **bio,
fio_folio->mapping->host,
fio_lblk, fio) &&
bio_add_folio(*bio, folio, bio_len, bio_offset)) {
+ if (folio_test_dropbehind(fio->folio))
+ bio_set_flag(*bio, BIO_COMPLETE_IN_TASK);
ret = 0;
break;
}
@@ -1359,6 +1364,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
__submit_merged_bio(io);
goto alloc_new;
}
+ if (folio_test_dropbehind(fio->folio))
+ bio_set_flag(io->bio, BIO_COMPLETE_IN_TASK);

F2FS_BIO(io->bio)->entry_cnt++;

--
2.43.0