Re: [PATCH] mm: filemap: tighten dropbehind completion context check
From: Barry Song
Date: Sun Aug 30 2026 - 04:45:40 EST
On Sat, Aug 29, 2026 at 8:13 PM Wenjie Qi <qwjhust@xxxxxxxxx> wrote:
>
> I kept the helper private to avoid an MM dependency on <linux/bio.h>.
>
> After looking further at the mapped-folio case Matthew raised, I think the
> better fix is to retain a dropbehind folio once it is mapped. A mapping
> represents a competing cached user, and retaining it avoids the sleeping
> unmap path, so filemap no longer needs a stricter context helper; the
> existing in_task() guard remains. I will respin the patch on that basis.
But we still have `bio_in_atomic()` in `include/linux/bio.h`:
/**
* bio_in_atomic - check if the current context is unsafe for bio completion
*
* Return: %true in atomic contexts (e.g. hard/soft IRQ, preempt-disabled);
* %false when a bio can be safely completed in the current context.
*/
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();
}
Right now, it's used in three places, and I expect we'll see more users
over time.
1 1925 block/bio.c <<bio_endio>>
if (bio_flagged(bio, BIO_COMPLETE_IN_TASK) && bio_in_atomic())
2 1451 fs/erofs/zdata.c <<z_erofs_decompress_kickoff>>
if (bio_in_atomic()) {
3 403 include/linux/bio.h <<bio_complete_in_task>>
if (!bio_in_atomic())
Yet it really has nothing to do with `bio` at all; it's purely a
scheduler thing!
So I fully agree with Andrew that we should move it to `sched` and
continue the discussion there. Maybe the current `in_atomic()` helpers
aren't really good enough?
Best Regards
Barry