Re: [PATCH v7 2/5] block: add task-context bio completion infrastructure
From: Tal Zussman
Date: Sat Aug 29 2026 - 11:38:27 EST
On 8/16/26 7:11 AM, Barry Song wrote:
> Hi Tal,
>
> Thanks very much for the patch. I’m just a bit confused that
> folio_end_dropbehind() only requires in_task(), and nothing more.
>
> void folio_end_dropbehind(struct folio *folio)
> {
> if (!folio_test_dropbehind(folio))
> return;
>
> /*
> * Hitting !in_task() should not happen off RWF_DONTCACHE writeback,
> * but can happen if normal writeback just happens to find dirty folios
> * that were created as part of uncached writeback, and that writeback
> * would otherwise not need non-IRQ handling. Just skip the
> * invalidation in that case.
> */
> if (in_task() && folio_trylock(folio)) {
> filemap_end_dropbehind(folio);
> folio_unlock(folio);
> }
> }
>
> But we’re applying a much stricter check with bio_in_atomic():
>
> +static inline bool bio_in_atomic(void)
> +{
> + if (IS_ENABLED(CONFIG_PREEMPTION) && rcu_preempt_depth())
> + return true;
> + if (!IS_ENABLED(CONFIG_PREEMPT_COUNT))
> + return true;
> + return !preemptible();
> +}
>
> I feel like something may be missing either in
> folio_end_dropbehind() itself or somewhere in the
> filesystem/block-device path.
>
> Do you know why they don’t match each other?
>
> Best Regards
> Barry
>
Hi Barry,
Apologies for the delay.
As far as I can tell, the in_task() in folio_end_dropbehind() wasn't meant
to be a generic test for if it's safe to sleep, but rather filtered out the
known unsafe case of buffer_head writeback completing from IRQ context.
In contrast, the bio_in_atomic() check needs to be stricter since the bi_end_io()
callbacks could sleep or the callers could be holding locks, RCU, etc.
I see there's some more discussion about this at [1], but I suspect there are
other instances that are (incorrectly) using in_task() as a proxy for being able
to sleep (like f2fs_read_end_io(), but I haven't looked too closely at it).
Additionally, it probably only makes sense to use bio_in_atomic() when there's
some deferral path, since with CONFIG_PREEMPT_COUNT=n, it'll always return true.
Thanks,
Tal
[1]: https://lore.kernel.org/linux-fsdevel/20260829121335.3491374-1-qwjhust@xxxxxxxxx/T/