Re: [PATCH 2/2] mm/slab: don't queue the page cache work under krcp->lock
From: Vlastimil Babka (SUSE)
Date: Wed Nov 04 2026 - 03:19:28 EST
On 11/2/26 15:35, Harry Yoo wrote:
> Here I added bit more context and adjusted comment. End result:
>
> mm/slab: don't queue the page cache work under krcp->lock
>
> Commit 56292e8609e3 ("rcu/tree: Defer kvfree_rcu() allocation to a
> clean context") deferred page allocations to a workqueue. To avoid
> deadlocks with the scheduler, it used hrtimer to queue the work instead
> of queueing it directly.
>
> Commit d0bfa8b3c411 ("kvfree_rcu: Release a page cache under memory
> pressure") later added a backoff mechanism under memory pressure, but
> did not consider that queue_delayed_work() with delay = 0 immediately
> queues the work and introduced the deadlock commit 56292e8609e3 tried to
> avoid.
>
> run_page_cache_worker() runs under krcp->lock, from kvfree_call_rcu()
> callers that may hold more, such as set_cpus_allowed_force() under
> pi_lock, so it kicks the refill work from an hrtimer. Under memory
> pressure it instead queues the work with a delay of
> rcutree.rcu_delay_page_cache_fill_msec, which may be 0, and a zero delay
> queues it at once, taking pool->lock under krcp->lock.
>
> With the delay set to 0, calling kvfree_rcu() on vmalloc memory under
> pi_lock after a drop_caches makes lockdep report:
>
> Chain exists of:
> &pool->lock --> &p->pi_lock --> krc.lock
>
> Use the hrtimer when the delay is 0.
>
> Fixes: d0bfa8b3c411 ("kvfree_rcu: Release a page cache under memory pressure")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Zhan Xusheng <zhanxusheng@xxxxxxxxxx>
> Link: https://patch.msgid.link/20261028134647.3176080-2-zhanxusheng1024@xxxxxxxxx
> [ harry@xxxxxxxxxx: add more context to changelog and adjust comment ]
> Signed-off-by: Harry Yoo (Meta) <harry@xxxxxxxxxx>
Reviewed-by: Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx>
> ---
> mm/slab_common.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/mm/slab_common.c b/mm/slab_common.c
> index 41dea01a8c1f..051ca63c0b67 100644
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -1987,7 +1987,15 @@ run_page_cache_worker(struct kfree_rcu_cpu *krcp)
>
> if (rcu_scheduler_active == RCU_SCHEDULER_RUNNING &&
> !atomic_xchg(&krcp->work_in_progress, 1)) {
> - if (atomic_read(&krcp->backoff_page_cache_fill)) {
> + /*
> + * Use the hrtimer to avoid a deadlock with the scheduler
> + * by waking up the worker directly. queue_delayed_work()
> + * uses a timer to queue the work, so it's fine.
> + * But with delay = 0 it queues the work immediately.
> + * Fall back to the hrtimer in that case.
> + */
> + if (atomic_read(&krcp->backoff_page_cache_fill) &&
> + rcu_delay_page_cache_fill_msec) {
> queue_delayed_work(rcu_reclaim_wq,
> &krcp->page_cache_work,
> msecs_to_jiffies(rcu_delay_page_cache_fill_msec));