Re: [PATCH 1/2] mm/percpu: Preserve NOFS/NOIO scope during chunk create and populate

From: Michal Hocko

Date: Tue Jun 02 2026 - 04:13:53 EST


On Tue 02-06-26 09:16:24, Vlastimil Babka (SUSE) wrote:
> On 6/2/26 05:03, Kaitao Cheng wrote:
> >
> >
> > 在 2026/6/1 23:45, Michal Hocko 写道:
> >> On Mon 01-06-26 10:27:53, Kaitao Cheng wrote:
> >>> However, if we revert 9a5b183941b, it seems that all of these issues would
> >>> be resolved. The only downside is that the failure rate of pcpu_alloc_noprof()
> >>> allocations may increase, which might be acceptable.
> >>
> >> That has practical impact on some versions of iscsid which do not have
> >> PR_SET_IO_FLUSHER. And maybe some more so I would rather not revert
> >> based on a theoretical concerns which I believe is the case here.
> >>
> >
> > Based on the previous discussion, I think we have a way to address most
> > of the concurrency issues around percpu allocation.
> >
> > However, there still seems to be one remaining case that I do not yet
> > have a good way to solve. For example:
> >
> > Thread A calls pcpu_alloc_noprof() with GFP_KERNEL and takes
> > pcpu_alloc_mutex. Since the internal allocation is not constrained by
> > NOFS, it may enter FS reclaim while still holding pcpu_alloc_mutex,
> > creating a dependency like:
> >
> > pcpu_alloc_mutex -> fs_reclaim -> FS lock
> > At the same time, Thread B may already hold an FS lock and then call
> > pcpu_alloc_noprof() with GFP_NOFS. It will try to acquire
> > pcpu_alloc_mutex and block, creating the reverse dependency:
> >
> > FS lock -> pcpu_alloc_mutex
> > This can still form a potential deadlock cycle.
> >
> > Does anyone have a good suggestion for how to handle this remaining case?
> > Or should we simply treat all GFP_KERNEL/GFP_NOFS allocation behavior in
> > pcpu_alloc_noprof() as GFP_NOIO?
> >
> > If there is no clear solution for now, would it be acceptable to first
> > fix some of the issues introduced by commit 9a5b183941b, and leave this
> > remaining case as a pre-existing historical issue to be handled separately
> > later?
>
> We don't need to solve any issues that are only theoretical and based on
> scenarios that nobody sane should be doing, i.e. Pedro already pointed out
> "As in no reclaim path should be insane^W daring enough to do pcpu allocations?"

Yes, but you do not need to do a pcp allocation from the reclaim path to
hit the deadlock. All you need is a NOFS pcp allocation - e.g. one done
from NOFS scope. Then you have fs lock <-> pcpu_alloc_mutex dependency
and a potential deadlock. It is hard to know whether we have any of
those in the kernel but I know for a fact (9a5b183941b) that there are
scoped NOIO allocations so I wouldn't be suprised if the same was the
case for NOFS. Not only that having NOIO is a weaker reclaim context.

> Elsewhere Pedro said "The proper way of fixing this would probably be to
> release pcpu_alloc_mutex (or not have it in the first place!) while you're
> allocating memory."

I do agree with this. Back then when I was dealing with the NOIO issue
I've tried to look at the lock and drop it but it was not really
straightforward. Maybe my lack of close understanding of the pcp
allocator was an obstacle there. So if there is a path forward like that
then it would certainly be the best.

--
Michal Hocko
SUSE Labs