mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RESEND] mm/vmalloc: Use dedicated unbound workqueues for vmap drain
@ 2026-09-05 15:27 Uladzislau Rezki (Sony)
  2026-09-05 22:37 ` Andrew Morton
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Uladzislau Rezki (Sony) @ 2026-09-05 15:27 UTC (permalink / raw)
  To: linux-mm, Andrew Morton
  Cc: Baoquan He, LKML, Uladzislau Rezki, stable, Dev Jain, Ye Liu, lirongqing

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.

Cc: stable@vger.kernel.org
Cc: Dev Jain <dev.jain@arm.com>
Cc: Ye Liu <ye.liu@linux.dev>
Cc: lirongqing <lirongqing@baidu.com>
Fixes: 72210662c5a2 ("mm: vmalloc: offload free_vmap_area_lock lock")
Link: https://lore.kernel.org/all/20260319074307.2325-1-lirongqing@baidu.com/
Reviewed-by: Baoquan He <bhe@redhat.com>
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
---
 mm/vmalloc.c | 79 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 52 insertions(+), 27 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index bea9f76ed7e7..89c327a6ce7d 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -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);
-- 
2.47.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND] mm/vmalloc: Use dedicated unbound workqueues for vmap drain
  2026-09-05 15:27 [PATCH RESEND] mm/vmalloc: Use dedicated unbound workqueues for vmap drain Uladzislau Rezki (Sony)
@ 2026-09-05 22:37 ` Andrew Morton
  2026-09-08 14:23   ` Uladzislau Rezki
  2026-09-06  3:50 ` Hillf Danton
  2026-09-10  8:33 ` Ye Liu
  2 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2026-09-05 22:37 UTC (permalink / raw)
  To: Uladzislau Rezki (Sony)
  Cc: linux-mm, Baoquan He, LKML, stable, Dev Jain, Ye Liu, lirongqing

On Sat,  5 Sep 2026 17:27:17 +0200 "Uladzislau Rezki (Sony)" <urezki@gmail.com> 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
> 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.

Thanks.

> Cc: stable@vger.kernel.org
> Cc: Dev Jain <dev.jain@arm.com>
> Cc: Ye Liu <ye.liu@linux.dev>
> Cc: lirongqing <lirongqing@baidu.com>
> Fixes: 72210662c5a2 ("mm: vmalloc: offload free_vmap_area_lock lock")
> Link: https://lore.kernel.org/all/20260319074307.2325-1-lirongqing@baidu.com/
> Reviewed-by: Baoquan He <bhe@redhat.com>
> Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>

I think what we wanted here was

Reported-by: Li RongQing <lirongqing@baidu.com>
Closes: https://lore.kernel.org/all/20260319074307.2325-1-lirongqing@baidu.com/

so I made that change.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND] mm/vmalloc: Use dedicated unbound workqueues for vmap drain
  2026-09-05 15:27 [PATCH RESEND] mm/vmalloc: Use dedicated unbound workqueues for vmap drain Uladzislau Rezki (Sony)
  2026-09-05 22:37 ` Andrew Morton
@ 2026-09-06  3:50 ` Hillf Danton
  2026-09-08 14:21   ` Uladzislau Rezki
  2026-09-10  8:33 ` Ye Liu
  2 siblings, 1 reply; 7+ messages in thread
From: Hillf Danton @ 2026-09-06  3:50 UTC (permalink / raw)
  To: Uladzislau Rezki (Sony)
  Cc: linux-mm, Baoquan He, LKML, stable, Dev Jain, Ye Liu, lirongqing,
	Andrew Morton

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
> 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.
>
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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND] mm/vmalloc: Use dedicated unbound workqueues for vmap drain
  2026-09-06  3:50 ` Hillf Danton
@ 2026-09-08 14:21   ` Uladzislau Rezki
  2026-09-09  1:08     ` Hillf Danton
  0 siblings, 1 reply; 7+ messages in thread
From: Uladzislau Rezki @ 2026-09-08 14:21 UTC (permalink / raw)
  To: Hillf Danton
  Cc: Uladzislau Rezki (Sony),
	linux-mm, Baoquan He, LKML, stable, Dev Jain, Ye Liu, lirongqing,
	Andrew Morton

On Sun, Sep 06, 2026 at 11:50:24AM +0800, Hillf Danton wrote:
> 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
> > 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.
> >
> 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.
>
It is scheduling decision. We do not want to tune any prio here.

> 
> Different workers does not help to dramatically decrement the micro seconds
> the drain_vmap_area_work takes.
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND] mm/vmalloc: Use dedicated unbound workqueues for vmap drain
  2026-09-05 22:37 ` Andrew Morton
@ 2026-09-08 14:23   ` Uladzislau Rezki
  0 siblings, 0 replies; 7+ messages in thread
From: Uladzislau Rezki @ 2026-09-08 14:23 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Uladzislau Rezki (Sony),
	linux-mm, Baoquan He, LKML, stable, Dev Jain, Ye Liu, lirongqing

On Sat, Sep 05, 2026 at 03:37:04PM -0700, Andrew Morton wrote:
> On Sat,  5 Sep 2026 17:27:17 +0200 "Uladzislau Rezki (Sony)" <urezki@gmail.com> 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
> > 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.
> 
> Thanks.
> 
> > Cc: stable@vger.kernel.org
> > Cc: Dev Jain <dev.jain@arm.com>
> > Cc: Ye Liu <ye.liu@linux.dev>
> > Cc: lirongqing <lirongqing@baidu.com>
> > Fixes: 72210662c5a2 ("mm: vmalloc: offload free_vmap_area_lock lock")
> > Link: https://lore.kernel.org/all/20260319074307.2325-1-lirongqing@baidu.com/
> > Reviewed-by: Baoquan He <bhe@redhat.com>
> > Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> 
> I think what we wanted here was
> 
> Reported-by: Li RongQing <lirongqing@baidu.com>
> Closes: https://lore.kernel.org/all/20260319074307.2325-1-lirongqing@baidu.com/
> 
> so I made that change.
> 
Yep :) Thank you!

--
Uladzislau Rezki

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND] mm/vmalloc: Use dedicated unbound workqueues for vmap drain
  2026-09-08 14:21   ` Uladzislau Rezki
@ 2026-09-09  1:08     ` Hillf Danton
  0 siblings, 0 replies; 7+ messages in thread
From: Hillf Danton @ 2026-09-09  1:08 UTC (permalink / raw)
  To: Uladzislau Rezki
  Cc: linux-mm, Baoquan He, LKML, Dev Jain, lirongqing, Andrew Morton

On Tue, 8 Sep 2026 16:21:20 +0200 "Uladzislau Rezki (Sony)" wrote:
>On Sun, Sep 06, 2026 at 11:50:24AM +0800, Hillf Danton wrote:
>> 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
>> > 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.
>> >
>> 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.
>>
> It is scheduling decision. We do not want to tune any prio here.
>
The difference your patch makes was checked without prio cared.

>> 
>> Different workers does not help to dramatically decrement the micro seconds
>> the drain_vmap_area_work takes.
>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.

>- 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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND] mm/vmalloc: Use dedicated unbound workqueues for vmap drain
  2026-09-05 15:27 [PATCH RESEND] mm/vmalloc: Use dedicated unbound workqueues for vmap drain Uladzislau Rezki (Sony)
  2026-09-05 22:37 ` Andrew Morton
  2026-09-06  3:50 ` Hillf Danton
@ 2026-09-10  8:33 ` Ye Liu
  2 siblings, 0 replies; 7+ messages in thread
From: Ye Liu @ 2026-09-10  8:33 UTC (permalink / raw)
  To: Uladzislau Rezki (Sony), linux-mm, Andrew Morton
  Cc: Baoquan He, LKML, stable, Dev Jain, lirongqing



在 2026/9/5 23:27, 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
> 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.
> 
> Cc: stable@vger.kernel.org
> Cc: Dev Jain <dev.jain@arm.com>
> Cc: Ye Liu <ye.liu@linux.dev>
> Cc: lirongqing <lirongqing@baidu.com>
> Fixes: 72210662c5a2 ("mm: vmalloc: offload free_vmap_area_lock lock")
> Link: https://lore.kernel.org/all/20260319074307.2325-1-lirongqing@baidu.com/
> Reviewed-by: Baoquan He <bhe@redhat.com>
> Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>

Reviewed-by: Ye Liu <liuye@kylinos.cn>

-- 
Thanks,
Ye Liu


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-09-10  8:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-05 15:27 [PATCH RESEND] mm/vmalloc: Use dedicated unbound workqueues for vmap drain Uladzislau Rezki (Sony)
2026-09-05 22:37 ` Andrew Morton
2026-09-08 14:23   ` Uladzislau Rezki
2026-09-06  3:50 ` Hillf Danton
2026-09-08 14:21   ` Uladzislau Rezki
2026-09-09  1:08     ` Hillf Danton
2026-09-10  8:33 ` Ye Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®