Re: [PATCH RFC v4 2/3] iomap: use BIO_COMPLETE_IN_TASK for dropbehind writeback
From: Tal Zussman
Date: Wed Apr 08 2026 - 16:16:07 EST
On 4/8/26 4:01 PM, Matthew Wilcox wrote:
> On Wed, Apr 08, 2026 at 03:44:37PM -0400, Tal Zussman wrote:
>> On 3/25/26 4:21 PM, Matthew Wilcox wrote:
>> > On Wed, Mar 25, 2026 at 02:43:01PM -0400, Tal Zussman wrote:
>> >> Set BIO_COMPLETE_IN_TASK on iomap writeback bios when
>> >> IOMAP_IOEND_DONTCACHE is set. This ensures that bi_end_io runs in task
>> >> context, where folio_end_dropbehind() can safely invalidate folios.
>> >>
>> >> With the bio layer now handling task-context deferral generically, XFS
>> >> no longer needs to route DONTCACHE ioends through its completion
>> >> workqueue for page cache invalidation. Remove the DONTCACHE check from
>> >> xfs_ioend_needs_wq_completion().
>> >>
>> >> Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
>> >> ---
>> >> fs/iomap/ioend.c | 2 ++
>> >> fs/xfs/xfs_aops.c | 4 ----
>> >> 2 files changed, 2 insertions(+), 4 deletions(-)
>> >>
>> >> diff --git a/fs/iomap/ioend.c b/fs/iomap/ioend.c
>> >> index e4d57cb969f1..6b8375d11cc0 100644
>> >> --- a/fs/iomap/ioend.c
>> >> +++ b/fs/iomap/ioend.c
>> >> @@ -113,6 +113,8 @@ static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,
>> >> GFP_NOFS, &iomap_ioend_bioset);
>> >> bio->bi_iter.bi_sector = iomap_sector(&wpc->iomap, pos);
>> >> bio->bi_write_hint = wpc->inode->i_write_hint;
>> >> + if (ioend_flags & IOMAP_IOEND_DONTCACHE)
>> >> + bio_set_flag(bio, BIO_COMPLETE_IN_TASK);
>> >> wbc_init_bio(wpc->wbc, bio);
>> >> wpc->nr_folios = 0;
>> >> return iomap_init_ioend(wpc->inode, bio, pos, ioend_flags);
>> >
>> > Can't we delete IOMAP_IOEND_DONTCACHE, and just do:
>> >
>> > if (folio_test_dropbehind(folio))
>> > bio_set_flag(&ioend->io_bio, BIO_COMPLETE_IN_TASK);
>> >
>> > It'd need to move down a few lines in iomap_add_to_ioend() to after
>> > bio_add_folio() succeeds.
>> >
>>
>> Actually, looking into it more, IOMAP_IOEND_DONTCACHE is used as part of
>> IOMAP_IOEND_NOMERGE_FLAGS. I think deleting it while maintaining the
>> no-merge behavior would be uglier than leaving it in.
>
> But why was it added to NOMERGE in the first place? I don't think it's
> harmful to merge writeback I/Os which are COMPLETE_IN_TASK and I/Os
> which are not, as long as the final I/O is completed in a task.
>
Looks like it was added in commit 34ecde3c5606 to ensure XFS DONTCACHE
completions were actually punted to task context... which we now ensure
elsewhere. Will delete and mention the side effect on regular I/Os in the
commit message.