mm/vmalloc: Use dedicated unbound workqueues for vmap drain
Subsystems (3)
Uladzislau Rezki (Sony)
maintainerPATCH RESEND 1/1 mm/vmalloc: Use dedicated unbound workqueues for vmap drain
drain_vmap_area_work() function can take >10ms to complete when there are many accumulated vmap areas in a system with high CPU count, causing workqueue watchdog warnings when run via schedule_work():
workqueue: drain_vmap_area_work hogged CPU for >10000us
Move the top-level drain work to a dedicated WQ_UNBOUND workqueue so the scheduler can run this background work on any available CPU, improving responsiveness. Use the WQ_MEM_RECLAIM to ensure forward progress under memory pressure.
Move purge helpers to separate WQ_UNBOUND | WQ_MEM_RECLAIM workqueue. This allows drain_vmap_work to wait for helpers completion without creating dependency on the same rescuer thread and avoid a potential parent/child deadlock.
Simplify purge helper scheduling by removing cpumask-based iteration to iterating directly over vmap nodes checking work_queued state.
--- mm/vmalloc.c | 79 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 27 deletions(-)
mm/vmalloc.c +52 -27
@@ -972,6 +972,7 @@ static struct vmap_node {struct list_head purge_list;struct work_struct purge_work;unsigned long nr_purged; +bool work_queued; } single;/*
@@ -1090,6 +1091,8 @@ 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 vmap_lazy_nr;
@@ -2351,6 +2354,16 @@ static void purge_vmap_node(struct work_struct *work)reclaim_list_global (&local_list); } +static bool +schedule_drain_vmap_work (struct workqueue_struct *wq, +struct work_struct *work) +{ +if (wq) +return queue_work (wq, work); + +return false; +} +/* * Purges all lazily-freed vmap areas. */
@@ -2358,19 +2371,12 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end, bool full_pool_decay) {unsigned long nr_purged_areas =0 ; +unsigned int nr_purge_nodes =0 ;unsigned int nr_purge_helpers; -static cpumask_t purge_nodes; -unsigned int nr_purge_nodes;struct vmap_node *vn; -int i;lockdep_assert_held (&vmap_purge_lock); -/* -* Use cpumask to mark which node has to be processed. -*/ - purge_nodes =CPU_MASK_NONE ; -for_each_vmap_node (vn) {INIT_LIST_HEAD (&vn->purge_list); vn->skip_populate = full_pool_decay;
@@ -2390,10 +2396,9 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end, end =max (end,list_last_entry (&vn->purge_list, struct vmap_area, list)->va_end); -cpumask_set_cpu (node_to_id (vn), &purge_nodes); + nr_purge_nodes++; } - nr_purge_nodes =cpumask_weight (&purge_nodes);if (nr_purge_nodes >0 ) {flush_tlb_kernel_range (start, end);
@@ -2401,29 +2406,31 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end, nr_purge_helpers =atomic_long_read (&vmap_lazy_nr) /lazy_max_pages (); nr_purge_helpers =clamp (nr_purge_helpers,1U , nr_purge_nodes) -1 ; -for_each_cpu (i, &purge_nodes) { - vn = &vmap_nodes[i]; +for_each_vmap_node (vn) { + vn->work_queued = false; + +if (list_empty (&vn->purge_list)) +continue ;if (nr_purge_helpers >0 ) {INIT_WORK (&vn->purge_work, purge_vmap_node); + vn->work_queued =schedule_drain_vmap_work ( +READ_ONCE (drain_vmap_helpers_wq), &vn->purge_work); -if (cpumask_test_cpu (i, cpu_online_mask)) -schedule_work_on (i, &vn->purge_work); -else -schedule_work (&vn->purge_work); - - nr_purge_helpers--; - }else { - vn->purge_work.func =NULL ; -purge_vmap_node (&vn->purge_work); - nr_purged_areas += vn->nr_purged; +if (vn->work_queued) { + nr_purge_helpers--; +continue ; + } } - } -for_each_cpu (i, &purge_nodes) { - vn = &vmap_nodes[i]; +/* Sync path. Process locally. */ +purge_vmap_node (&vn->purge_work); + nr_purged_areas += vn->nr_purged; + } -if (vn->purge_work.func) { +/* Wait for completion if queued any. */ +for_each_vmap_node (vn) { +if (vn->work_queued) {flush_work (&vn->purge_work); nr_purged_areas += vn->nr_purged; }
@@ -2487,7 +2494,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_work (&drain_vmap_work); +schedule_drain_vmap_work (READ_ONCE (drain_vmap_wq), + &drain_vmap_work); }/*
@@ -5587,3 +5595,20 @@ void __init vmalloc_init(void) vmap_node_shrinker->scan_objects = vmap_node_shrink_scan;shrinker_register (vmap_node_shrinker); } + +static int __init vmalloc_init_workqueue (void ) +{ +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); + + 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 ; +} +early_initcall (vmalloc_init_workqueue);
Signature · 1 line
2.47.3
Andrew Morton
maintainerQuoted 13 lines · On Sat, 5 Sep 2026 17:27:17 +0200 "Uladzislau Rezki (Sony)"…
drain_vmap_area_work()function can take >10ms to complete when there are many accumulated vmap areas in a system with high CPU count, causing workqueue watchdog warnings when run viaschedule_work():workqueue:
drain_vmap_area_workhogged CPU for >10000usMove the top-level drain work to a dedicated
WQ_UNBOUNDworkqueue so the scheduler can run this background work on any available CPU, improving responsiveness. Use theWQ_MEM_RECLAIMto ensure forward progress under memory pressure.
Quoted 8 lines
Move purge helpers to separate
WQ_UNBOUND|WQ_MEM_RECLAIMworkqueue. This allowsdrain_vmap_workto wait for helpers completion without creating dependency on the same rescuer thread and avoid a potential parent/child deadlock.Simplify purge helper scheduling by removing cpumask-based iteration to iterating directly over vmap nodes checking
work_queuedstate.
Thanks.
Quoted 8 lines
Cc Dev Jain <[email protected]>Cc Ye Liu <[email protected]>Cc lirongqing <[email protected]>Fixes 72210662c5a2 ("mm: vmalloc: offload free_vmap_area_lock lock")Reviewed-by Baoquan He <[email protected]>Signed-off-by Uladzislau Rezki (Sony) <[email protected]>
I think what we wanted here was
so I made that change.
Uladzislau Rezki
maintainerQuoted 35 lines · Andrew Morton
Quoted 13 lines · On Sat, 5 Sep 2026 17:27:17 +0200 "Uladzislau Rezki (Sony)"…
drain_vmap_area_work()function can take >10ms to complete when there are many accumulated vmap areas in a system with high CPU count, causing workqueue watchdog warnings when run viaschedule_work():workqueue:
drain_vmap_area_workhogged CPU for >10000usMove the top-level drain work to a dedicated
WQ_UNBOUNDworkqueue so the scheduler can run this background work on any available CPU, improving responsiveness. Use theWQ_MEM_RECLAIMto ensure forward progress under memory pressure.Quoted 8 lines
Move purge helpers to separate
WQ_UNBOUND|WQ_MEM_RECLAIMworkqueue. This allowsdrain_vmap_workto wait for helpers completion without creating dependency on the same rescuer thread and avoid a potential parent/child deadlock.Simplify purge helper scheduling by removing cpumask-based iteration to iterating directly over vmap nodes checking
work_queuedstate.Thanks.
Quoted 8 lines
Cc Dev Jain <[email protected]>Cc Ye Liu <[email protected]>Cc lirongqing <[email protected]>Fixes 72210662c5a2 ("mm: vmalloc: offload free_vmap_area_lock lock")Reviewed-by Baoquan He <[email protected]>Signed-off-by Uladzislau Rezki (Sony) <[email protected]>
Quoted 7 lines
I think what we wanted here was
Reported-by Li RongQing <[email protected]>so I made that change.
Yep :) Thank you!
--
Uladzislau Rezki
Quoted 5 lines · On Sat, 5 Sep 2026 17:27:17 +0200 "Uladzislau Rezki (Sony)" wrote:
drain_vmap_area_work()function can take >10ms to complete when there are many accumulated vmap areas in a system with high CPU count, causing workqueue watchdog warnings when run viaschedule_work():
Quoted 8 lines
workqueue:
drain_vmap_area_workhogged CPU for >10000usMove the top-level drain work to a dedicated
WQ_UNBOUNDworkqueue so the scheduler can run this background work on any available CPU, improving responsiveness. Use theWQ_MEM_RECLAIMto ensure forward progress under memory pressure.
If the dedicated worker will run for 4ms on CPU2 before the tick irq kicks it off cpu, the system event worker on CPU2 has to wait at least for 4ms to handle 200 events for example in 1ms, the net effect is the same as the current scenario where 200 events wait for the drain_vmap_area_work to complete on CPU1.
Different workers does not help to dramatically decrement the micro seconds the drain_vmap_area_work takes.
Uladzislau Rezki
maintainerQuoted 14 lines · Hillf Danton
Quoted 5 lines · On Sat, 5 Sep 2026 17:27:17 +0200 "Uladzislau Rezki (Sony)" wrote:
drain_vmap_area_work()function can take >10ms to complete when there are many accumulated vmap areas in a system with high CPU count, causing workqueue watchdog warnings when run viaschedule_work():Quoted 8 lines
workqueue:
drain_vmap_area_workhogged CPU for >10000usMove the top-level drain work to a dedicated
WQ_UNBOUNDworkqueue so the scheduler can run this background work on any available CPU, improving responsiveness. Use theWQ_MEM_RECLAIMto ensure forward progress under memory pressure.
Quoted 5 lines
If the dedicated worker will run for 4ms on CPU2 before the tick irq kicks it off cpu, the system event worker on CPU2 has to wait at least for 4ms to handle 200 events for example in 1ms, the net effect is the same as the current scenario where 200 events wait for the
drain_vmap_area_workto complete on CPU1.
It is scheduling decision. We do not want to tune any prio here.
Quoted 3 lines
Different workers does not help to dramatically decrement the micro seconds the
drain_vmap_area_worktakes.
The problem of current approach consists from at least two problems:
- doing progress under memory pressure;
- do not schedule all workers on current CPU and let schedule to find the most attractive CPU from its point of view. For example: less busy RQ, less energy consuming CPU and so on
--
Uladzislau Rezki
Quoted 15 lines · On Tue, 8 Sep 2026 16:21:20 +0200 "Uladzislau Rezki (Sony)" wrote:
Quoted 14 lines · Hillf Danton
Quoted 13 lines · On Sat, 5 Sep 2026 17:27:17 +0200 "Uladzislau Rezki (Sony)" wrote:
drain_vmap_area_work()function can take >10ms to complete when there are many accumulated vmap areas in a system with high CPU count, causing workqueue watchdog warnings when run viaschedule_work():workqueue:
drain_vmap_area_workhogged CPU for >10000usMove the top-level drain work to a dedicated
WQ_UNBOUNDworkqueue so the scheduler can run this background work on any available CPU, improving responsiveness. Use theWQ_MEM_RECLAIMto ensure forward progress under memory pressure.
Quoted 7 lines
Quoted 5 lines
If the dedicated worker will run for 4ms on CPU2 before the tick irq kicks it off cpu, the system event worker on CPU2 has to wait at least for 4ms to handle 200 events for example in 1ms, the net effect is the same as the current scenario where 200 events wait for the
drain_vmap_area_workto complete on CPU1.It is scheduling decision. We do not want to tune any prio here.
The difference your patch makes was checked without prio cared.
Quoted 6 lines
Quoted 3 lines
Different workers does not help to dramatically decrement the micro seconds the
drain_vmap_area_worktakes.The problem of current approach consists from at least two problems:
- doing progress under memory pressure;
Though in general a long running workqueue work is a wart, exceptions exist when mm is tight. Just like kswapd that becomes a cpu hog, it is the right thing to do for drain_vmap_area_work to take more than 20ms.
Quoted 4 lines
- do not schedule all workers on current CPU and let schedule to find the most attractive CPU from its point of view. For example: less busy RQ, less energy consuming CPU and so on
Nope as UNBOUND has nothing to do with cutting the micro seconds the drain_vmap_area_work could take.
Uladzislau Rezki
maintainerQuoted 36 lines · Hillf Danton
Quoted 15 lines · On Tue, 8 Sep 2026 16:21:20 +0200 "Uladzislau Rezki (Sony)" wrote:
Quoted 14 lines · Hillf Danton
Quoted 13 lines · On Sat, 5 Sep 2026 17:27:17 +0200 "Uladzislau Rezki (Sony)" wrote:
drain_vmap_area_work()function can take >10ms to complete when there are many accumulated vmap areas in a system with high CPU count, causing workqueue watchdog warnings when run viaschedule_work():workqueue:
drain_vmap_area_workhogged CPU for >10000usMove the top-level drain work to a dedicated
WQ_UNBOUNDworkqueue so the scheduler can run this background work on any available CPU, improving responsiveness. Use theWQ_MEM_RECLAIMto ensure forward progress under memory pressure.Quoted 7 lines
Quoted 5 lines
If the dedicated worker will run for 4ms on CPU2 before the tick irq kicks it off cpu, the system event worker on CPU2 has to wait at least for 4ms to handle 200 events for example in 1ms, the net effect is the same as the current scenario where 200 events wait for the
drain_vmap_area_workto complete on CPU1.It is scheduling decision. We do not want to tune any prio here.
The difference your patch makes was checked without prio cared.
Quoted 6 lines
Quoted 3 lines
Different workers does not help to dramatically decrement the micro seconds the
drain_vmap_area_worktakes.The problem of current approach consists from at least two problems:
- doing progress under memory pressure;
Though in general a long running workqueue work is a wart, exceptions exist when mm is tight. Just like kswapd that becomes a cpu hog, it is the right thing to do for
drain_vmap_area_workto take more than 20ms.
Quoted 7 lines
Quoted 4 lines
- do not schedule all workers on current CPU and let schedule to find the most attractive CPU from its point of view. For example: less busy RQ, less energy consuming CPU and so on
Nope as UNBOUND has nothing to do with cutting the micro seconds the
drain_vmap_area_workcould take.
This patch does not use queue_work_on() semantic thus i do not want to queue all helpers on current CPU. Instead scheduler does balancing and that is it.
Or you prefer to tight all helpers on local CPUs? What is you concern?
--
Uladzislau Rezki
Quoted 4 lines · On Mon, 14 Sep 2026 18:56:26 +0200 "Uladzislau Rezki (Sony)" wrote:
This patch does not use
queue_work_on()semantic thus i do not want to queue all helpers on current CPU. Instead scheduler does balancing and that is it.
[Fair queue in the Eric Dumazet accent]
+static bool
+schedule_drain_vmap_work(struct workqueue_struct *wq,
+ struct work_struct *work)
+{
+ if (wq)
+ return queue_work(wq, work);
+
+ return false;
+}
+
static inline bool queue_work(struct workqueue_struct *wq,
struct work_struct *work)
{
return queue_work_on(WORK_CPU_UNBOUND, wq, work);
}queue_work_on
__queue_work
if (req_cpu == WORK_CPU_UNBOUND) {
if (wq->flags & WQ_UNBOUND)
cpu = wq_select_unbound_cpu(raw_smp_processor_id());
else
cpu = raw_smp_processor_id();
}/*
* When queueing an unbound work item to a wq, prefer local CPU if allowed
* by wq_unbound_cpumask. Otherwise, round robin among the allowed ones to
* avoid perturbing sensitive tasks.
*/
static int wq_select_unbound_cpu(int cpu)
{
pr_warn_once("workqueue: round-robin CPU selection forced, expect performance impact\n");
}
Quoted 1 line
Or you prefer to tight all helpers on local CPUs? What is you concern?
Who blamed kswapd when it became a cpu hog, given it behaves the same way as a UNBOUND workqueue worker, regarding cpu affinity? Given kswapd is acceptable, why is vmap work blamed? Unfair.
Uladzislau Rezki
maintainerQuoted 34 lines · Hillf Danton
Quoted 4 lines · On Mon, 14 Sep 2026 18:56:26 +0200 "Uladzislau Rezki (Sony)" wrote:
This patch does not use
queue_work_on()semantic thus i do not want to queue all helpers on current CPU. Instead scheduler does balancing and that is it.[Fair queue in the Eric Dumazet accent]
mm/vmalloc.c +10
-0+static bool +schedule_drain_vmap_work (struct workqueue_struct *wq, +struct work_struct *work) +{ +if (wq) +return queue_work (wq, work); + +return false; +} +static inline bool queue_work(struct
workqueue_struct*wq,
structwork_struct*work){ return queue_work_on(WORK_CPU_UNBOUND, wq, work); }
queue_work_on
__queue_workif (req_cpu == WORK_CPU_UNBOUND) { if (wq->flags & WQ_UNBOUND) cpu = wq_select_unbound_cpu(raw_smp_processor_id()); else cpu = raw_smp_processor_id(); }
Quoted 10 lines
/*
* When queueing an unbound work item to a wq, prefer local CPU if allowed
* bywq_unbound_cpumask. Otherwise, round robin among the allowed ones to
* avoid perturbing sensitive tasks.
*/
static intwq_select_unbound_cpu(int cpu)
{
pr_warn_once("workqueue: round-robin CPU selection forced, expect performance impact\n");
}
/**
* worker_attach_to_pool() - attach a worker to a pool
* @worker: worker to be attached
* @pool: the target pool
*
* Attach @worker to @pool. Once attached, the %WORKER_UNBOUND flag and
* cpu-binding of @worker are kept coordinated with the pool across
* cpu-[un]hotplugs.
*/
static void worker_attach_to_pool(struct worker *worker,
struct worker_pool *pool)
{
mutex_lock(&wq_pool_attach_mutex);
/*
* The wq_pool_attach_mutex ensures %POOL_DISASSOCIATED remains stable
* across this function. See the comments above the flag definition for
* details. BH workers are, while per-CPU, always DISASSOCIATED.
*/
if (pool->flags & POOL_DISASSOCIATED) {
worker->flags |= WORKER_UNBOUND;
} else {
WARN_ON_ONCE(pool->flags & POOL_BH);
kthread_set_per_cpu(worker->task, pool->cpu);
}...
}
A local CPU preference for WQ_UNBOUND is not the same as executing on the __bound__ per-CPU system kworker.
--
Uladzislau Rezki
Quoted 70 lines · On Wed, 16 Sep 2026 18:00:20 +0200 "Uladzislau Rezki (Sony)" wrote:
Quoted 34 lines · Hillf Danton
Quoted 4 lines · On Mon, 14 Sep 2026 18:56:26 +0200 "Uladzislau Rezki (Sony)" wrote:
This patch does not use
queue_work_on()semantic thus i do not want to queue all helpers on current CPU. Instead scheduler does balancing and that is it.[Fair queue in the Eric Dumazet accent]
(quoted diff) +10
-0+static bool +schedule_drain_vmap_work(struct workqueue_struct *wq, + struct work_struct *work) +{ + if (wq) + return queue_work(wq, work); + + return false; +} +static inline bool queue_work(struct
workqueue_struct*wq,
structwork_struct*work){ return queue_work_on(WORK_CPU_UNBOUND, wq, work); }
queue_work_on
__queue_workif (req_cpu == WORK_CPU_UNBOUND) { if (wq->flags & WQ_UNBOUND) cpu = wq_select_unbound_cpu(raw_smp_processor_id()); else cpu = raw_smp_processor_id(); }Quoted 10 lines
/*
* When queueing an unbound work item to a wq, prefer local CPU if allowed
* bywq_unbound_cpumask. Otherwise, round robin among the allowed ones to
* avoid perturbing sensitive tasks.
*/
static intwq_select_unbound_cpu(int cpu)
{
pr_warn_once("workqueue: round-robin CPU selection forced, expect performance impact\n");
}/**
*worker_attach_to_pool()- attach a worker to a pool
* @worker: worker to be attached
* @pool: the target pool
*
* Attach @worker to @pool. Once attached, the %WORKER_UNBOUND flag and
* cpu-binding of @worker are kept coordinated with the pool across
* cpu-[un]hotplugs.
*/
static void worker_attach_to_pool(struct worker *worker,
structworker_pool*pool){ mutex_lock(&wq_pool_attach_mutex); /* * The wq_pool_attach_mutex ensures %POOL_DISASSOCIATED remains stable * across this function. See the comments above the flag definition for * details. BH workers are, while per-CPU, always DISASSOCIATED. */ if (pool->flags & POOL_DISASSOCIATED) { worker->flags |= WORKER_UNBOUND; } else { WARN_ON_ONCE(pool->flags & POOL_BH); kthread_set_per_cpu(worker->task, pool->cpu); }
Quoted 6 lines
...
}A local CPU preference for
WQ_UNBOUNDis not the same as executing on the__bound__per-CPU system kworker.
As Ulad, like Yu Zhao, is one of the couple black horses I saw in mm the past a couple years, lad, I make the difference between BOUND and UNBOUND workers as clear as it is.
Given numa node1 including cpu8-15 without cpu hotplug cared, a bound worker for cpu9 can not migrate to any other cpu, while a unbound worker can run on any cpu of node1, that is all.
Important UN/BOUND have nothing to do with eevdf (and balancing cpus) because of different layers.
And at best I suspect what you missed is the difference between drain_vmap_work and lru_add_drain_work, but I do not like the latter as it annoyed the RT/full nohz apps more than thought [11].
static DECLARE_WORK(drain_vmap_work, drain_vmap_area_work); static DEFINE_PER_CPU(struct work_struct, lru_add_drain_work);
[11] Subject: [PATCH v4 3/4] swap: apply new pw_queue_on() interface
https://lore.kernel.org/lkml/[email protected]/
Uladzislau Rezki
maintainerQuoted 74 lines · Hillf Danton
Quoted 73 lines · On Wed, 16 Sep 2026 18:00:20 +0200 "Uladzislau Rezki (Sony)" wrote:
Quoted 34 lines · Hillf Danton
Quoted 4 lines · On Mon, 14 Sep 2026 18:56:26 +0200 "Uladzislau Rezki (Sony)" wrote:
This patch does not use
queue_work_on()semantic thus i do not want to queue all helpers on current CPU. Instead scheduler does balancing and that is it.[Fair queue in the Eric Dumazet accent]
(quoted diff) +10
-0+static bool +schedule_drain_vmap_work(struct workqueue_struct *wq, + struct work_struct *work) +{ + if (wq) + return queue_work(wq, work); + + return false; +} +static inline bool queue_work(struct
workqueue_struct*wq,
structwork_struct*work){ return queue_work_on(WORK_CPU_UNBOUND, wq, work); }
queue_work_on
__queue_workif (req_cpu == WORK_CPU_UNBOUND) { if (wq->flags & WQ_UNBOUND) cpu = wq_select_unbound_cpu(raw_smp_processor_id()); else cpu = raw_smp_processor_id(); }Quoted 10 lines
/*
* When queueing an unbound work item to a wq, prefer local CPU if allowed
* bywq_unbound_cpumask. Otherwise, round robin among the allowed ones to
* avoid perturbing sensitive tasks.
*/
static intwq_select_unbound_cpu(int cpu)
{
pr_warn_once("workqueue: round-robin CPU selection forced, expect performance impact\n");
}/**
*worker_attach_to_pool()- attach a worker to a pool
* @worker: worker to be attached
* @pool: the target pool
*
* Attach @worker to @pool. Once attached, the %WORKER_UNBOUND flag and
* cpu-binding of @worker are kept coordinated with the pool across
* cpu-[un]hotplugs.
*/
static void worker_attach_to_pool(struct worker *worker,
structworker_pool*pool){ mutex_lock(&wq_pool_attach_mutex); /* * The wq_pool_attach_mutex ensures %POOL_DISASSOCIATED remains stable * across this function. See the comments above the flag definition for * details. BH workers are, while per-CPU, always DISASSOCIATED. */ if (pool->flags & POOL_DISASSOCIATED) { worker->flags |= WORKER_UNBOUND; } else { WARN_ON_ONCE(pool->flags & POOL_BH); kthread_set_per_cpu(worker->task, pool->cpu); }...
}
Quoted 7 lines
Quoted 3 lines
A local CPU preference for
WQ_UNBOUNDis not the same as executing on the__bound__per-CPU system kworker.As Ulad, like Yu Zhao, is one of the couple black horses I saw in mm the past a couple years, lad, I make the difference between BOUND and UNBOUND workers as clear as it is.
This is very good :)
Quoted 5 lines
Given numa node1 including cpu8-15 without cpu hotplug cared, a bound worker for cpu9 can not migrate to any other cpu, while a unbound worker can run on any cpu of node1, that is all.
Right.
<snip>
if (list_empty(&pwq->inactive_works) && pwq_tryinc_nr_active(pwq, false)) {
if (list_empty(&pool->worklist))
pool->last_progress_ts = jiffies;
trace_workqueue_activate_work(work);
insert_work(pwq, work, &pool->worklist, work_flags);
kick_pool_pick(pool, &wake_task);
} else {
work_flags |= WORK_STRUCT_INACTIVE;
insert_work(pwq, work, &pwq->inactive_works, work_flags);
}out:
raw_spin_unlock(&pool->lock); if (wake_task) wake_up_process(wake_task);
<snip>
wake_up_process(wake_task) - this guy takes care about task placement. For us it is TASK_FAIR thus select_task_rq_fair() decides the fate of unbound kworker.
Quoted 7 lines
Important UN/BOUND have nothing to do with eevdf (and balancing cpus) because of different layers.
And at best I suspect what you missed is the difference between
drain_vmap_workandlru_add_drain_work, but I do not like the latter as it annoyed the RT/full nohz apps more than thought [11].
Quoted 6 lines
static
DECLARE_WORK(drain_vmap_work, drain_vmap_area_work); staticDEFINE_PER_CPU(struct work_struct, lru_add_drain_work);[11] Subject: [PATCH v4 3/4] swap: apply new
pw_queue_on()interface
https://lore.kernel.org/lkml/[email protected]/
I am not sure a drain_vmap_work should be per-cpu, IMO.
Thanks!
--
Uladzislau Rezki
Quoted 22 lines · On Thu, 17 Sep 2026 19:03:47 +0200 "Uladzislau Rezki (Sony)" wrote:
Quoted 5 lines · Hillf Danton
Given numa node1 including cpu8-15 without cpu hotplug cared, a bound worker for cpu9 can not migrate to any other cpu, while a unbound worker can run on any cpu of node1, that is all.
Right.
<snip>
if (list_empty(&pwq->inactive_works) && pwq_tryinc_nr_active(pwq, false)) { if (list_empty(&pool->worklist)) pool->last_progress_ts = jiffies; trace_workqueue_activate_work(work); insert_work(pwq, work, &pool->worklist, work_flags); kick_pool_pick(pool, &wake_task); } else { work_flags |= WORK_STRUCT_INACTIVE; insert_work(pwq, work, &pwq->inactive_works, work_flags); }out:
Quoted 9 lines
raw_spin_unlock(&pool->lock); if (wake_task) wake_up_process(wake_task);<snip>
wake_up_process(wake_task)- this guy takes care about task placement. For us it isTASK_FAIRthusselect_task_rq_fair()decides the fate of unbound kworker.
At best an idle cpu is selected for the unbound worker, but it may be preempted the next micro second. Maybe you disagree, eevdf means uncertain.
Even given an idle cpu without preempt, it fails to prevent the vmap work from becoming a wart, no?
Quoted 22 lines · Uladzislau Rezki (Sony)
drain_vmap_area_work()function can take >10ms to complete when there are many accumulated vmap areas in a system with high CPU count, causing workqueue watchdog warnings when run viaschedule_work():workqueue:
drain_vmap_area_workhogged CPU for >10000usMove the top-level drain work to a dedicated
WQ_UNBOUNDworkqueue so the scheduler can run this background work on any available CPU, improving responsiveness. Use theWQ_MEM_RECLAIMto ensure forward progress under memory pressure.Move purge helpers to separate
WQ_UNBOUND|WQ_MEM_RECLAIMworkqueue. This allowsdrain_vmap_workto wait for helpers completion without creating dependency on the same rescuer thread and avoid a potential parent/child deadlock.Simplify purge helper scheduling by removing cpumask-based iteration to iterating directly over vmap nodes checking
work_queuedstate.
Quoted 8 lines
Cc Dev Jain <[email protected]>Cc Ye Liu <[email protected]>Cc lirongqing <[email protected]>Fixes 72210662c5a2 ("mm: vmalloc: offload free_vmap_area_lock lock")Reviewed-by Baoquan He <[email protected]>Signed-off-by Uladzislau Rezki (Sony) <[email protected]>
Signature · 2 lines
Thanks, Ye Liu
[merged mm-hotfixes-stable] mm-vmalloc-use-dedicated-unbound-workqueues-for-vmap-drain.patch removed from -mm tree
In reply to Uladzislau Rezki (Sony)The quilt patch titled Subject: mm/vmalloc: use dedicated unbound workqueues for vmap drain has been removed from the -mm tree. Its filename was…
The quilt patch titled
Subject: mm/vmalloc: use dedicated unbound workqueues for vmap drain
has been removed from the -mm tree. Its filename was
mm-vmalloc-use-dedicated-unbound-workqueues-for-vmap-drain.patch
This patch was dropped because it was merged into the mm-hotfixes-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: "Uladzislau Rezki (Sony)" <[email protected]>
Subject: mm/vmalloc: use dedicated unbound workqueues for vmap drain
Date: Sat, 5 Sep 2026 17:27:17 +0200
drain_vmap_area_work() function can take >10ms to complete when there are many accumulated vmap areas in a system with high CPU count, causing workqueue watchdog warnings when run via schedule_work():
workqueue: drain_vmap_area_work hogged CPU for >10000us
Move the top-level drain work to a dedicated WQ_UNBOUND workqueue so the scheduler can run this background work on any available CPU, improving responsiveness. Use the WQ_MEM_RECLAIM to ensure forward progress under memory pressure.
Move purge helpers to separate WQ_UNBOUND | WQ_MEM_RECLAIM workqueue. This allows drain_vmap_work to wait for helpers completion without creating dependency on the same rescuer thread and avoid a potential parent/child deadlock.
Simplify purge helper scheduling by removing cpumask-based iteration to iterating directly over vmap nodes checking work_queued state.
mm/vmalloc.c | 79 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 27 deletions(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-use-dedicated-unbound-workqueues-for-vmap-drain +52 -27
@@ -978,6 +978,7 @@ static struct vmap_node {struct list_head purge_list;struct work_struct purge_work;unsigned long nr_purged; +bool work_queued; } single;/*
@@ -1096,6 +1097,8 @@ static void reclaim_and_purge_vmap_areasstatic 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 vmap_lazy_nr;
@@ -2357,6 +2360,16 @@ static void purge_vmap_node(struct work_reclaim_list_global (&local_list); } +static bool +schedule_drain_vmap_work (struct workqueue_struct *wq, +struct work_struct *work) +{ +if (wq) +return queue_work (wq, work); + +return false; +} +/* * Purges all lazily-freed vmap areas. */
@@ -2364,19 +2377,12 @@ static bool __purge_vmap_area_lazy(unsig bool full_pool_decay) {unsigned long nr_purged_areas =0 ; +unsigned int nr_purge_nodes =0 ;unsigned int nr_purge_helpers; -static cpumask_t purge_nodes; -unsigned int nr_purge_nodes;struct vmap_node *vn; -int i;lockdep_assert_held (&vmap_purge_lock); -/* -* Use cpumask to mark which node has to be processed. -*/ - purge_nodes =CPU_MASK_NONE ; -for_each_vmap_node (vn) {INIT_LIST_HEAD (&vn->purge_list); vn->skip_populate = full_pool_decay;
@@ -2396,10 +2402,9 @@ static bool __purge_vmap_area_lazy(unsig end =max (end,list_last_entry (&vn->purge_list, struct vmap_area, list)->va_end); -cpumask_set_cpu (node_to_id (vn), &purge_nodes); + nr_purge_nodes++; } - nr_purge_nodes =cpumask_weight (&purge_nodes);if (nr_purge_nodes >0 ) {flush_tlb_kernel_range (start, end);
@@ -2407,29 +2412,31 @@ static bool __purge_vmap_area_lazy(unsig nr_purge_helpers =atomic_long_read (&vmap_lazy_nr) /lazy_max_pages (); nr_purge_helpers =clamp (nr_purge_helpers,1U , nr_purge_nodes) -1 ; -for_each_cpu (i, &purge_nodes) { - vn = &vmap_nodes[i]; +for_each_vmap_node (vn) { + vn->work_queued = false; + +if (list_empty (&vn->purge_list)) +continue ;if (nr_purge_helpers >0 ) {INIT_WORK (&vn->purge_work, purge_vmap_node); + vn->work_queued =schedule_drain_vmap_work ( +READ_ONCE (drain_vmap_helpers_wq), &vn->purge_work); -if (cpumask_test_cpu (i, cpu_online_mask)) -schedule_work_on (i, &vn->purge_work); -else -schedule_work (&vn->purge_work); - - nr_purge_helpers--; - }else { - vn->purge_work.func =NULL ; -purge_vmap_node (&vn->purge_work); - nr_purged_areas += vn->nr_purged; +if (vn->work_queued) { + nr_purge_helpers--; +continue ; + } } - } -for_each_cpu (i, &purge_nodes) { - vn = &vmap_nodes[i]; +/* Sync path. Process locally. */ +purge_vmap_node (&vn->purge_work); + nr_purged_areas += vn->nr_purged; + } -if (vn->purge_work.func) { +/* Wait for completion if queued any. */ +for_each_vmap_node (vn) { +if (vn->work_queued) {flush_work (&vn->purge_work); nr_purged_areas += vn->nr_purged; }
@@ -2493,7 +2500,8 @@ static void free_vmap_area_noflush(struc/* After this point, we may free va at any time */ if (unlikely (nr_lazy > nr_lazy_max)) -schedule_work (&drain_vmap_work); +schedule_drain_vmap_work (READ_ONCE (drain_vmap_wq), + &drain_vmap_work); }/*
@@ -5639,3 +5647,20 @@ void __init vmalloc_init(void) vmap_node_shrinker->scan_objects = vmap_node_shrink_scan;shrinker_register (vmap_node_shrinker); } + +static int __init vmalloc_init_workqueue (void ) +{ +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); + + 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 ; +} +early_initcall (vmalloc_init_workqueue);
_
Patches currently in -mm which might be from [email protected] are
mm-vmalloc-bail-out-if-in-softirq-context.patch