Re: [PATCH v2] mm, oom: add rcu_barrier before hiding victim from the oom killer

From: Michal Hocko

Date: Thu Dec 03 2026 - 13:11:46 EST


On Thu 03-12-26 09:39:53, Paul E. McKenney wrote:
[...]
> > And this is a super sensitive point - will this always result in forward
> > progress? Could it be significantly delayed?
>
> Normal grace period latencies tend to be in the tens or hundreds of
> milliseconds. And RCU CPU stall warnings happen when a given grace period
> extends for more than 21 *seconds*, so long RCU grace periods can happen.
> On the other hand, grace periods this long are (and should be) treated
> as bugs.

Yes, I guess it is expected that this can take a long time. And this
particular patch adds it to two places:
- exit_mmap for an oom_victim
- oom_reaper

The former is dying and if that takes longer while it is guaranteed to
release its own memory from page tables which are freed through RCU then
this is good. We do not even need a guarantee of a fwd progress here.

The latter is more sensitive as it needs the guarantee of fwd progress.
Although it doesn't hold any locks explicitly it ensures that the
currently selected oom victims will be torn down - either through them
exiting or remotely through the reaper. In either case they are declared
MMF_OOM_SKIP in the end.
If that takes longer then still not anything really earth shattering as
long as this cannot block for unbound amount of time.

> > Are there any lock dependencies that could be problematic?
>
> Given that you are asking this, I am assuming that if this rcu_barrier()
> gets stuck, reclaim also gets stuck.
>
> You are not allowed to acquire sleeplocks in RCU callback functions,
> and you are not allowed to hold spinlocks across an rcu_barrier(), so
> at a high level, no.

Thanks for the confirmation. That was my understanding.

> One theoretical problem would be if RCU allocated
> memory while doing a grace period, and the call to rcu_barrier() blocked
> the grace period that its callback functions were in turn waiting on.
> And there might be something like this that could happen when a CPU
> was coming online for the very first time, especially if that CPU was
> a rcu_nocbs CPU, which needs kthreads to be created.
>
> No locks involved, but self-deadlock nevertheless.

Could you clarify a bit please? So this would be possible only during
early boot while hitting OOM because RCU internals would be blocked on
the memory allocation which cannot be resolved?

> So maybe make that rcu_barrier() execute asynchronously?

Well the thing is that we need to use it to order MMF_OOM_SKIP setting
in the oom_reaper case.

> And/or do a
> synchronize_rcu_expedited(), also asynchronously?

As this is mostly a best effort to ensure a lot of memory is not sitting
to be freed in rcu callbacks then I would much rather just drop the
rcu_barrier from oom_reap_task.

--
Michal Hocko
SUSE Labs