Re: [PATCH v2] mm/vmalloc: Use dedicated unbound workqueue for vmap purge/drain

From: Uladzislau Rezki

Date: Tue Mar 31 2026 - 10:14:22 EST


On Tue, Mar 31, 2026 at 11:39:06AM +0200, Uladzislau Rezki wrote:
> On Mon, Mar 30, 2026 at 12:16:25PM -0700, Andrew Morton wrote:
> > On Mon, 30 Mar 2026 19:58:24 +0200 "Uladzislau Rezki (Sony)" <urezki@xxxxxxxxx> wrote:
> >
> > > The drain_vmap_area_work() function can take >10ms to complete
> > > when there are many accumulated vmap areas in a system with a
> > > high CPU count, causing workqueue watchdog warnings when run
> > > via schedule_work():
> > >
> > > [ 2069.796205] workqueue: drain_vmap_area_work hogged CPU for >10000us 4 times, consider switching to WQ_UNBOUND
> > > [ 2192.823225] workqueue: drain_vmap_area_work hogged CPU for >10000us 5 times, consider switching to WQ_UNBOUND
> > >
> > > Switch to a dedicated WQ_UNBOUND workqueue to allow the scheduler to
> > > run this background task on any available CPU, improving responsiveness.
> > > Use WQ_MEM_RECLAIM to ensure forward progress under memory pressure.
> > >
> > > If queuing work to the dedicated workqueue is not possible(during
> > > early boot), fall back to processing locally to avoid losing progress.
> > >
> > > Also simplify purge helper scheduling by removing cpumask-based
> > > iteration in favour to iterating directly over vmap nodes with
> > > pending work.
> >
> > Thanks. AI review flagged a couple of possible issues. Do they look
> > real to you?
> > https://sashiko.dev/#/patchset/20260330175824.2777270-1-urezki@xxxxxxxxx
> >
> I think the problem about itself locking if running by rescue thread is
> a valid concern. I will address this. I think the easiest is to use two
> UNBOUND queues one for master/main thread and second for helpers which
> reclaim if there are too many objects so the help is needed.
>
> I will work on v3.
>
> Thank you for review!
>
> --
> Uladzislau Rezki
>
I will fix the AI concern by maintaining two queues. One is parent
second one is for child helpers. That way both will not block each
other and both have a rescue context to move progress forward:

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 6bc2523bf75b..2c1ed76cffe8 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1068,6 +1068,7 @@ static void reclaim_and_purge_vmap_areas(void);
static BLOCKING_NOTIFIER_HEAD(vmap_notify_list);
static void drain_vmap_area_work(struct work_struct *work);
static DECLARE_WORK(drain_vmap_work, drain_vmap_area_work);
+static struct workqueue_struct *drain_vmap_helpers_wq;
static struct workqueue_struct *drain_vmap_wq;

static __cacheline_aligned_in_smp atomic_long_t nr_vmalloc_pages;
@@ -2338,10 +2339,9 @@ static void purge_vmap_node(struct work_struct *work)
}

static bool
-schedule_drain_vmap_work(struct work_struct *work)
+schedule_drain_vmap_work(struct workqueue_struct *wq,
+ struct work_struct *work)
{
- struct workqueue_struct *wq = READ_ONCE(drain_vmap_wq);
-
if (wq) {
queue_work(wq, work);
return true;
@@ -2400,7 +2400,8 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end,

if (nr_purge_helpers > 0) {
INIT_WORK(&vn->purge_work, purge_vmap_node);
- vn->work_queued = schedule_drain_vmap_work(&vn->purge_work);
+ vn->work_queued = schedule_drain_vmap_work(
+ READ_ONCE(drain_vmap_helpers_wq), &vn->purge_work);

if (vn->work_queued) {
nr_purge_helpers--;
@@ -2479,7 +2480,8 @@ static void free_vmap_area_noflush(struct vmap_area *va)

/* After this point, we may free va at any time */
if (unlikely(nr_lazy > nr_lazy_max))
- schedule_drain_vmap_work(&drain_vmap_work);
+ schedule_drain_vmap_work(READ_ONCE(drain_vmap_wq),
+ &drain_vmap_work);
}

/*
@@ -5494,11 +5496,16 @@ void __init vmalloc_init(void)

static int __init vmalloc_init_workqueue(void)
{
- struct workqueue_struct *wq;
+ struct workqueue_struct *drain_wq, *helpers_wq;
+ unsigned int flags = WQ_UNBOUND | WQ_MEM_RECLAIM;
+
+ drain_wq = alloc_workqueue("vmap_drain", flags, 0);
+ WARN_ON_ONCE(drain_wq == NULL);
+ WRITE_ONCE(drain_vmap_wq, drain_wq);

- wq = alloc_workqueue("vmap_drain", WQ_UNBOUND | WQ_MEM_RECLAIM, 0);
- WARN_ON(wq == NULL);
- WRITE_ONCE(drain_vmap_wq, wq);
+ helpers_wq = alloc_workqueue("vmap_drain_helpers", flags, 0);
+ WARN_ON_ONCE(helpers_wq == NULL);
+ WRITE_ONCE(drain_vmap_helpers_wq, helpers_wq);

return 0;
}


if no complains, i will send out v3 soon.

--
Uladzislau Rezki