* [PATCH] mm/vmalloc: avoid false sharing with drain_vmap_work
@ 2026-08-25 10:46 JonasZhou-oc
2026-08-25 14:14 ` Uladzislau Rezki
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: JonasZhou-oc @ 2026-08-25 10:46 UTC (permalink / raw)
To: Andrew Morton, Uladzislau Rezki; +Cc: linux-mm, linux-kernel, jianhuizzzzz
free_vmap_area_noflush() queues drain_vmap_work after the number of
lazily freed pages exceeds lazy_max_pages(). Until the worker purges
those pages, concurrent frees keep calling schedule_work(). Even if
the work is already pending, queue_work_on() performs a locked
test_and_set_bit() on the pending bit in the work item.
On the tested x86-64 build, drain_vmap_work and vmap_nodes occupy the
same 64-byte cache line. The work item starts at offset 0 and the
vmap_nodes pointer at offset 32. The latter is read by vmap allocation
and free paths, so updates to the work item invalidate a cache line
read by all CPUs.
Put drain_vmap_work in the cacheline-aligned data section. Tests were
run on Linux 7.2.
On a two-socket Intel Xeon Silver 4208 system using 16 workers, the
runtimes of vmalloc.fix_align, vmalloc.fix_size, and
vmalloc.no_block_alloc decreased by 12.61%, 5.78%, and 6.87%,
respectively. HITM samples for the affected cache line and total HITM
samples decreased by 96.55% and 13.36%, respectively.
Signed-off-by: JonasZhou <jonaszhou-oc@zhaoxin.com>
---
mm/vmalloc.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index f4fa227a8d7f..6b4b287e91f6 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1088,7 +1088,12 @@ RB_DECLARE_CALLBACKS_MAX(static, free_vmap_area_rb_augment_cb,
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);
+/*
+ * Keep the work item, whose pending bit is updated by freeing CPUs,
+ * away from vmap metadata read by allocation and free paths.
+ */
+static __cacheline_aligned_in_smp
+DECLARE_WORK(drain_vmap_work, drain_vmap_area_work);
static __cacheline_aligned_in_smp atomic_long_t vmap_lazy_nr;
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] mm/vmalloc: avoid false sharing with drain_vmap_work
2026-08-25 10:46 [PATCH] mm/vmalloc: avoid false sharing with drain_vmap_work JonasZhou-oc
@ 2026-08-25 14:14 ` Uladzislau Rezki
2026-11-26 2:22 ` JonasZhou-oc
2026-11-26 9:25 ` Anshuman Khandual
2 siblings, 0 replies; 5+ messages in thread
From: Uladzislau Rezki @ 2026-08-25 14:14 UTC (permalink / raw)
To: JonasZhou-oc
Cc: Andrew Morton, Uladzislau Rezki, linux-mm, linux-kernel,
jianhuizzzzz
On Tue, Aug 25, 2026 at 06:46:59PM +0800, JonasZhou-oc wrote:
> free_vmap_area_noflush() queues drain_vmap_work after the number of
> lazily freed pages exceeds lazy_max_pages(). Until the worker purges
> those pages, concurrent frees keep calling schedule_work(). Even if
> the work is already pending, queue_work_on() performs a locked
> test_and_set_bit() on the pending bit in the work item.
>
> On the tested x86-64 build, drain_vmap_work and vmap_nodes occupy the
> same 64-byte cache line. The work item starts at offset 0 and the
> vmap_nodes pointer at offset 32. The latter is read by vmap allocation
> and free paths, so updates to the work item invalidate a cache line
> read by all CPUs.
>
> Put drain_vmap_work in the cacheline-aligned data section. Tests were
> run on Linux 7.2.
>
> On a two-socket Intel Xeon Silver 4208 system using 16 workers, the
> runtimes of vmalloc.fix_align, vmalloc.fix_size, and
> vmalloc.no_block_alloc decreased by 12.61%, 5.78%, and 6.87%,
> respectively. HITM samples for the affected cache line and total HITM
> samples decreased by 96.55% and 13.36%, respectively.
>
> Signed-off-by: JonasZhou <jonaszhou-oc@zhaoxin.com>
> ---
> mm/vmalloc.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index f4fa227a8d7f..6b4b287e91f6 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -1088,7 +1088,12 @@ RB_DECLARE_CALLBACKS_MAX(static, free_vmap_area_rb_augment_cb,
> 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);
> +/*
> + * Keep the work item, whose pending bit is updated by freeing CPUs,
> + * away from vmap metadata read by allocation and free paths.
> + */
> +static __cacheline_aligned_in_smp
> +DECLARE_WORK(drain_vmap_work, drain_vmap_area_work);
>
> static __cacheline_aligned_in_smp atomic_long_t vmap_lazy_nr;
>
> --
> 2.43.0
>
>
Makes sens to me.
Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
--
Uladzislau Rezki
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/vmalloc: avoid false sharing with drain_vmap_work
2026-08-25 10:46 [PATCH] mm/vmalloc: avoid false sharing with drain_vmap_work JonasZhou-oc
2026-08-25 14:14 ` Uladzislau Rezki
@ 2026-11-26 2:22 ` JonasZhou-oc
2026-11-26 9:25 ` Anshuman Khandual
2 siblings, 0 replies; 5+ messages in thread
From: JonasZhou-oc @ 2026-11-26 2:22 UTC (permalink / raw)
To: akpm, Uladzislau Rezki; +Cc: JonasZhou, linux-mm, linux-kernel, jianhuizzzzz
Hi Andrew and Uladzislau,
I see this patch is still in mm-unstable. Is it being considered for
the next merge window, or is there anything you need from me?
Thanks,
Jonas
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/vmalloc: avoid false sharing with drain_vmap_work
2026-08-25 10:46 [PATCH] mm/vmalloc: avoid false sharing with drain_vmap_work JonasZhou-oc
2026-08-25 14:14 ` Uladzislau Rezki
2026-11-26 2:22 ` JonasZhou-oc
@ 2026-11-26 9:25 ` Anshuman Khandual
2026-11-27 2:31 ` JonasZhou-oc
2 siblings, 1 reply; 5+ messages in thread
From: Anshuman Khandual @ 2026-11-26 9:25 UTC (permalink / raw)
To: JonasZhou-oc
Cc: Andrew Morton, Uladzislau Rezki, linux-mm, linux-kernel,
jianhuizzzzz
On Tue, Aug 25, 2026 at 06:46:59PM +0800, JonasZhou-oc wrote:
> free_vmap_area_noflush() queues drain_vmap_work after the number of
> lazily freed pages exceeds lazy_max_pages(). Until the worker purges
> those pages, concurrent frees keep calling schedule_work(). Even if
> the work is already pending, queue_work_on() performs a locked
> test_and_set_bit() on the pending bit in the work item.
>
> On the tested x86-64 build, drain_vmap_work and vmap_nodes occupy the
> same 64-byte cache line. The work item starts at offset 0 and the
> vmap_nodes pointer at offset 32. The latter is read by vmap allocation
> and free paths, so updates to the work item invalidate a cache line
> read by all CPUs.
>
> Put drain_vmap_work in the cacheline-aligned data section. Tests were
> run on Linux 7.2.
Should the test be performed again on latest RC kernel ?
>
> On a two-socket Intel Xeon Silver 4208 system using 16 workers, the
> runtimes of vmalloc.fix_align, vmalloc.fix_size, and
> vmalloc.no_block_alloc decreased by 12.61%, 5.78%, and 6.87%,
> respectively. HITM samples for the affected cache line and total HITM
> samples decreased by 96.55% and 13.36%, respectively.
>
> Signed-off-by: JonasZhou <jonaszhou-oc@zhaoxin.com>
> ---
> mm/vmalloc.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index f4fa227a8d7f..6b4b287e91f6 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -1088,7 +1088,12 @@ RB_DECLARE_CALLBACKS_MAX(static, free_vmap_area_rb_augment_cb,
> 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);
> +/*
> + * Keep the work item, whose pending bit is updated by freeing CPUs,
> + * away from vmap metadata read by allocation and free paths.
s/away/cacheline away/ instead ?
Besides the comment could be re-worded with some more detail perhaps.
> + */
> +static __cacheline_aligned_in_smp
> +DECLARE_WORK(drain_vmap_work, drain_vmap_area_work);
>
> static __cacheline_aligned_in_smp atomic_long_t vmap_lazy_nr;
>
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/vmalloc: avoid false sharing with drain_vmap_work
2026-11-26 9:25 ` Anshuman Khandual
@ 2026-11-27 2:31 ` JonasZhou-oc
0 siblings, 0 replies; 5+ messages in thread
From: JonasZhou-oc @ 2026-11-27 2:31 UTC (permalink / raw)
To: anshuman.khandual
Cc: jonaszhou-oc, akpm, urezki, linux-mm, linux-kernel, jianhuizzzzz
> Should the test be performed again on latest RC kernel ?
Yes. I retested on v7.4-rc4 (b6a9fa34ce41) on the same dual-socket
Xeon Silver 4208. In the unpatched x86-64 builds I tested, GCC placed
the two variables next to each other, with 32-byte alignment for
drain_vmap_work and 8-byte alignment for the vmap_nodes pointer.
Whether they share a 64-byte cache line depends on the kernel config.
After I set CONFIG_RSEQ=n, drain_vmap_work and vmap_nodes shared the
same cache line.
With 16 workers, SMT off and the CPUs fixed at 2.0 GHz, the mean
worker times over 10 runs were:
test unpatched patched reduction
fix_align_alloc_test 6.129 s 5.365 s 12.47%
fix_size_alloc_test 4.836 s 3.850 s 20.39%
no_block_alloc_test 4.840 s 3.882 s 19.79%
> s/away/cacheline away/ instead ?
Agreed. I'd make the cache-line separation and the reason for it
explicit in the comment:
/*
* Keep drain_vmap_work and vmap_nodes on separate cache lines.
* CPUs queuing the work write its pending bit, while CPUs allocating
* or freeing vmap areas read vmap_nodes.
*/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-27 2:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-25 10:46 [PATCH] mm/vmalloc: avoid false sharing with drain_vmap_work JonasZhou-oc
2026-08-25 14:14 ` Uladzislau Rezki
2026-11-26 2:22 ` JonasZhou-oc
2026-11-26 9:25 ` Anshuman Khandual
2026-11-27 2:31 ` JonasZhou-oc
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox