* [PATCH 0/8] mm/vmalloc: assorted cleanups and minor fixes
@ 2026-12-03 1:22 Ye Liu
2026-12-03 1:22 ` [PATCH 1/8] mm/vmalloc: use ALIGN_DOWN for vmalloc end alignment Ye Liu
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Ye Liu @ 2026-12-03 1:22 UTC (permalink / raw)
To: Andrew Morton, Uladzislau Rezki; +Cc: linux-mm, Ye Liu, Ye Liu
This series collects a set of small cleanups and minor fixes to
mm/vmalloc.c, mostly around the vmap area pool management and the
free-space initialization paths:
1. use ALIGN_DOWN() instead of masking with ~(align - 1)
2. extract a pcpu_release_va() helper to avoid duplicated KASAN
release code
3. fix a misleading pr_warn() in alloc_vmap_area()
4. simplify the is_vn_id_valid() predicate
5. move the pool length update under pool_lock in decay_va_pool_node()
6. report the node count when vmap_init_nodes() falls back to a
single node
7. drop the double negation in vmap_insert_free_area()
8. compare addresses directly in vmap_init_free_space()
No functional changes intended.
Signed-off-by: Ye Liu <ye.liu@linux.dev>
---
Ye Liu (8):
mm/vmalloc: use ALIGN_DOWN for vmalloc end alignment
mm/vmalloc: extract pcpu_release_va helper
mm/vmalloc: fix misleading pr_warn in alloc_vmap_area
mm/vmalloc: simplify is_vn_id_valid predicate
mm/vmalloc: move pool length update under pool_lock in decay_va_pool_node()
mm/vmalloc: report node count when falling back to a single node
mm/vmalloc: drop the double negation in vmap_insert_free_area()
mm/vmalloc: compare addresses directly in vmap_init_free_space()
mm/vmalloc.c | 84 +++++++++++++++++++++++++++++++-----------------------------
1 file changed, 43 insertions(+), 41 deletions(-)
---
base-commit: d138596e9f822033490b2e577ec2ea64f2aa246c
change-id: 20261202-vmalloc_cleanup_1-b9fcdf978658
Best regards,
--
Ye Liu <ye.liu@linux.dev>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/8] mm/vmalloc: use ALIGN_DOWN for vmalloc end alignment
2026-12-03 1:22 [PATCH 0/8] mm/vmalloc: assorted cleanups and minor fixes Ye Liu
@ 2026-12-03 1:22 ` Ye Liu
2026-12-03 1:22 ` [PATCH 2/8] mm/vmalloc: extract pcpu_release_va helper Ye Liu
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Ye Liu @ 2026-12-03 1:22 UTC (permalink / raw)
To: Andrew Morton, Uladzislau Rezki; +Cc: linux-mm, Ye Liu, Ye Liu
From: Ye Liu <liuye@kylinos.cn>
Replace open-coded & ~(align - 1) with the standard ALIGN_DOWN()
macro, matching the existing ALIGN() usage on the adjacent
vmalloc_start line. No functional change.
Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
mm/vmalloc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index ee722162da7c..56f0bfc3147c 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -5166,13 +5166,13 @@ pvm_find_va_enclose_addr(unsigned long addr)
static unsigned long
pvm_determine_end_from_reverse(struct vmap_area **va, unsigned long align)
{
- unsigned long vmalloc_end = VMALLOC_END & ~(align - 1);
+ unsigned long vmalloc_end = ALIGN_DOWN(VMALLOC_END, align);
unsigned long addr;
if (likely(*va)) {
list_for_each_entry_from_reverse((*va),
&free_vmap_area_list, list) {
- addr = min((*va)->va_end & ~(align - 1), vmalloc_end);
+ addr = min(ALIGN_DOWN((*va)->va_end, align), vmalloc_end);
if ((*va)->va_start < addr)
return addr;
}
@@ -5211,7 +5211,7 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
size_t align, gfp_t gfp)
{
const unsigned long vmalloc_start = ALIGN(VMALLOC_START, align);
- const unsigned long vmalloc_end = VMALLOC_END & ~(align - 1);
+ const unsigned long vmalloc_end = ALIGN_DOWN(VMALLOC_END, align);
struct vmap_area **vas, *va;
struct vm_struct **vms;
int area, area2, last_area, term_area;
--
2.25.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/8] mm/vmalloc: extract pcpu_release_va helper
2026-12-03 1:22 [PATCH 0/8] mm/vmalloc: assorted cleanups and minor fixes Ye Liu
2026-12-03 1:22 ` [PATCH 1/8] mm/vmalloc: use ALIGN_DOWN for vmalloc end alignment Ye Liu
@ 2026-12-03 1:22 ` Ye Liu
2026-12-03 1:22 ` [PATCH 3/8] mm/vmalloc: fix misleading pr_warn in alloc_vmap_area Ye Liu
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Ye Liu @ 2026-12-03 1:22 UTC (permalink / raw)
To: Andrew Morton, Uladzislau Rezki; +Cc: linux-mm, Ye Liu, Ye Liu
From: Ye Liu <liuye@kylinos.cn>
Extract the repeated pattern of returning a vmap_area to the free
tree with KASAN shadow release into a pcpu_release_va() helper,
used by both the recovery and err_free_shadow error paths in
pcpu_get_vm_areas(). No functional change.
Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
mm/vmalloc.c | 38 +++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 56f0bfc3147c..1f6ef2530e9e 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -5181,6 +5181,24 @@ pvm_determine_end_from_reverse(struct vmap_area **va, unsigned long align)
return 0;
}
+/*
+ * Return a vmap_area to the free tree and release its KASAN shadow.
+ * Must be called with free_vmap_area_lock held.
+ */
+static void pcpu_release_va(struct vmap_area *va)
+{
+ unsigned long orig_start = va->va_start;
+ unsigned long orig_end = va->va_end;
+ struct vmap_area *merged;
+
+ merged = merge_or_add_vmap_area_augment(va, &free_vmap_area_root,
+ &free_vmap_area_list);
+ if (merged)
+ kasan_release_vmalloc(orig_start, orig_end,
+ merged->va_start, merged->va_end,
+ KASAN_VMALLOC_PAGE_RANGE | KASAN_VMALLOC_TLB_FLUSH);
+}
+
/**
* pcpu_get_vm_areas - allocate vmalloc areas for percpu allocator
* @offsets: array containing offset of each area
@@ -5215,7 +5233,7 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
struct vmap_area **vas, *va;
struct vm_struct **vms;
int area, area2, last_area, term_area;
- unsigned long base, start, size, end, last_end, orig_start, orig_end;
+ unsigned long base, start, size, end, last_end;
bool purged = false;
/* verify parameters and allocate data structures */
@@ -5382,14 +5400,7 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
* and when pcpu_get_vm_areas() is success.
*/
while (area--) {
- orig_start = vas[area]->va_start;
- orig_end = vas[area]->va_end;
- va = merge_or_add_vmap_area_augment(vas[area], &free_vmap_area_root,
- &free_vmap_area_list);
- if (va)
- kasan_release_vmalloc(orig_start, orig_end,
- va->va_start, va->va_end,
- KASAN_VMALLOC_PAGE_RANGE | KASAN_VMALLOC_TLB_FLUSH);
+ pcpu_release_va(vas[area]);
vas[area] = NULL;
}
@@ -5433,14 +5444,7 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
* being able to tolerate this case.
*/
for (area = 0; area < nr_vms; area++) {
- orig_start = vas[area]->va_start;
- orig_end = vas[area]->va_end;
- va = merge_or_add_vmap_area_augment(vas[area], &free_vmap_area_root,
- &free_vmap_area_list);
- if (va)
- kasan_release_vmalloc(orig_start, orig_end,
- va->va_start, va->va_end,
- KASAN_VMALLOC_PAGE_RANGE | KASAN_VMALLOC_TLB_FLUSH);
+ pcpu_release_va(vas[area]);
vas[area] = NULL;
kfree(vms[area]);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/8] mm/vmalloc: fix misleading pr_warn in alloc_vmap_area
2026-12-03 1:22 [PATCH 0/8] mm/vmalloc: assorted cleanups and minor fixes Ye Liu
2026-12-03 1:22 ` [PATCH 1/8] mm/vmalloc: use ALIGN_DOWN for vmalloc end alignment Ye Liu
2026-12-03 1:22 ` [PATCH 2/8] mm/vmalloc: extract pcpu_release_va helper Ye Liu
@ 2026-12-03 1:22 ` Ye Liu
2026-12-03 1:22 ` [PATCH 4/8] mm/vmalloc: simplify is_vn_id_valid predicate Ye Liu
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Ye Liu @ 2026-12-03 1:22 UTC (permalink / raw)
To: Andrew Morton, Uladzislau Rezki; +Cc: linux-mm, Ye Liu, Ye Liu
From: Ye Liu <liuye@kylinos.cn>
The warning message referenced vmalloc_node_range but alloc_vmap_area
is a generic allocator called from multiple paths, not just
__vmalloc_node_range. Use __func__ and drop the inaccurate "Address
range restricted" phrasing.
Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
mm/vmalloc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 1f6ef2530e9e..ed4c4f7054c3 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2211,8 +2211,8 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
}
if (!(gfp_mask & __GFP_NOWARN) && printk_ratelimit())
- pr_warn("vmalloc_node_range for size %lu failed: Address range restricted to %#lx - %#lx\n",
- size, vstart, vend);
+ pr_warn("%s: size %lu failed, range %#lx - %#lx\n",
+ __func__, size, vstart, vend);
out_free_va:
kmem_cache_free(vmap_area_cachep, va);
--
2.25.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/8] mm/vmalloc: simplify is_vn_id_valid predicate
2026-12-03 1:22 [PATCH 0/8] mm/vmalloc: assorted cleanups and minor fixes Ye Liu
` (2 preceding siblings ...)
2026-12-03 1:22 ` [PATCH 3/8] mm/vmalloc: fix misleading pr_warn in alloc_vmap_area Ye Liu
@ 2026-12-03 1:22 ` Ye Liu
2026-12-03 1:22 ` [PATCH 5/8] mm/vmalloc: move pool length update under pool_lock in decay_va_pool_node() Ye Liu
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Ye Liu @ 2026-12-03 1:22 UTC (permalink / raw)
To: Andrew Morton, Uladzislau Rezki; +Cc: linux-mm, Ye Liu, Ye Liu
From: Ye Liu <liuye@kylinos.cn>
Collapse the if/return pattern into a direct boolean expression.
No functional change.
Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
mm/vmalloc.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index ed4c4f7054c3..d076ef22b84a 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1100,10 +1100,7 @@ decode_vn_id(unsigned int val)
static bool
is_vn_id_valid(unsigned int node_id)
{
- if (node_id < nr_vmap_nodes)
- return true;
-
- return false;
+ return node_id < nr_vmap_nodes;
}
static __always_inline unsigned long
--
2.25.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/8] mm/vmalloc: move pool length update under pool_lock in decay_va_pool_node()
2026-12-03 1:22 [PATCH 0/8] mm/vmalloc: assorted cleanups and minor fixes Ye Liu
` (3 preceding siblings ...)
2026-12-03 1:22 ` [PATCH 4/8] mm/vmalloc: simplify is_vn_id_valid predicate Ye Liu
@ 2026-12-03 1:22 ` Ye Liu
2026-12-03 1:22 ` [PATCH 6/8] mm/vmalloc: report node count when falling back to a single node Ye Liu
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Ye Liu @ 2026-12-03 1:22 UTC (permalink / raw)
To: Andrew Morton, Uladzislau Rezki; +Cc: linux-mm, Ye Liu, Ye Liu
From: Ye Liu <liuye@kylinos.cn>
vmap_pool->len is protected by pool_lock, as done in node_pool_add_va()
and node_pool_del_va(). decay_va_pool_node() reads and clears len
outside of the lock, which can leave it inconsistent with the pool list
under concurrent access. Move both into the same critical section that
detaches the pool list.
Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
mm/vmalloc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index d076ef22b84a..e24d04d2f4a0 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2296,10 +2296,9 @@ decay_va_pool_node(struct vmap_node *vn, bool full_decay)
/* Detach the pool, so no-one can access it. */
spin_lock(&vn->pool_lock);
list_replace_init(&vn->pool[i].head, &tmp_list);
- spin_unlock(&vn->pool_lock);
-
pool_len = n_decay = vn->pool[i].len;
WRITE_ONCE(vn->pool[i].len, 0);
+ spin_unlock(&vn->pool_lock);
/* Decay a pool by ~25% out of left objects. */
if (!full_decay)
--
2.25.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 6/8] mm/vmalloc: report node count when falling back to a single node
2026-12-03 1:22 [PATCH 0/8] mm/vmalloc: assorted cleanups and minor fixes Ye Liu
` (4 preceding siblings ...)
2026-12-03 1:22 ` [PATCH 5/8] mm/vmalloc: move pool length update under pool_lock in decay_va_pool_node() Ye Liu
@ 2026-12-03 1:22 ` Ye Liu
2026-12-03 1:22 ` [PATCH 7/8] mm/vmalloc: drop the double negation in vmap_insert_free_area() Ye Liu
2026-12-03 1:22 ` [PATCH 8/8] mm/vmalloc: compare addresses directly in vmap_init_free_space() Ye Liu
7 siblings, 0 replies; 9+ messages in thread
From: Ye Liu @ 2026-12-03 1:22 UTC (permalink / raw)
To: Andrew Morton, Uladzislau Rezki; +Cc: linux-mm, Ye Liu, Ye Liu
From: Ye Liu <liuye@kylinos.cn>
When the multi-node array allocation fails, vmap_init_nodes() falls back
to a single vmap node. Report the requested node count and the fallback,
and downgrade the message from error to warning since the kernel
continues to function normally.
Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
mm/vmalloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index e24d04d2f4a0..03cce37466d1 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -5701,7 +5701,7 @@ static void vmap_init_nodes(void)
nr_vmap_nodes = n;
vmap_nodes = vn;
} else {
- pr_err("Failed to allocate an array. Disable a node layer\n");
+ pr_warn("Failed to allocate %d vmap nodes, falling back to one node\n", n);
}
}
#endif
--
2.25.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 7/8] mm/vmalloc: drop the double negation in vmap_insert_free_area()
2026-12-03 1:22 [PATCH 0/8] mm/vmalloc: assorted cleanups and minor fixes Ye Liu
` (5 preceding siblings ...)
2026-12-03 1:22 ` [PATCH 6/8] mm/vmalloc: report node count when falling back to a single node Ye Liu
@ 2026-12-03 1:22 ` Ye Liu
2026-12-03 1:22 ` [PATCH 8/8] mm/vmalloc: compare addresses directly in vmap_init_free_space() Ye Liu
7 siblings, 0 replies; 9+ messages in thread
From: Ye Liu @ 2026-12-03 1:22 UTC (permalink / raw)
To: Andrew Morton, Uladzislau Rezki; +Cc: linux-mm, Ye Liu, Ye Liu
From: Ye Liu <liuye@kylinos.cn>
Invert the WARN_ON_ONCE() check and return early to avoid the double
negation. No functional change.
Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
mm/vmalloc.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 03cce37466d1..66206de44267 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -5638,13 +5638,14 @@ static void __init vmap_insert_free_area(unsigned long start, unsigned long end)
{
struct vmap_area *free = kmem_cache_zalloc(vmap_area_cachep, GFP_NOWAIT);
- if (!WARN_ON_ONCE(!free)) {
- free->va_start = start;
- free->va_end = end;
- insert_vmap_area_augment(free, NULL,
- &free_vmap_area_root,
- &free_vmap_area_list);
- }
+ if (WARN_ON_ONCE(!free))
+ return;
+
+ free->va_start = start;
+ free->va_end = end;
+ insert_vmap_area_augment(free, NULL,
+ &free_vmap_area_root,
+ &free_vmap_area_list);
}
static void __init vmap_init_free_space(void)
--
2.25.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 8/8] mm/vmalloc: compare addresses directly in vmap_init_free_space()
2026-12-03 1:22 [PATCH 0/8] mm/vmalloc: assorted cleanups and minor fixes Ye Liu
` (6 preceding siblings ...)
2026-12-03 1:22 ` [PATCH 7/8] mm/vmalloc: drop the double negation in vmap_insert_free_area() Ye Liu
@ 2026-12-03 1:22 ` Ye Liu
7 siblings, 0 replies; 9+ messages in thread
From: Ye Liu @ 2026-12-03 1:22 UTC (permalink / raw)
To: Andrew Morton, Uladzislau Rezki; +Cc: linux-mm, Ye Liu, Ye Liu
From: Ye Liu <liuye@kylinos.cn>
Use a local variable to avoid the repeated casts and compare the
addresses directly instead of relying on unsigned subtraction, which can
underflow. No functional change.
Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
mm/vmalloc.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 66206de44267..7eec038b8990 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -5661,14 +5661,15 @@ static void __init vmap_init_free_space(void)
* |<--------------------------------->|
*/
for (busy = vmlist; busy; busy = busy->next) {
- if ((unsigned long) busy->addr - vmap_start > 0)
- vmap_insert_free_area(vmap_start,
- (unsigned long) busy->addr);
+ unsigned long addr = (unsigned long) busy->addr;
- vmap_start = (unsigned long) busy->addr + busy->size;
+ if (addr > vmap_start)
+ vmap_insert_free_area(vmap_start, addr);
+
+ vmap_start = addr + busy->size;
}
- if (vmap_end - vmap_start > 0)
+ if (vmap_start < vmap_end)
vmap_insert_free_area(vmap_start, vmap_end);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-12-03 1:23 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 1:22 [PATCH 0/8] mm/vmalloc: assorted cleanups and minor fixes Ye Liu
2026-12-03 1:22 ` [PATCH 1/8] mm/vmalloc: use ALIGN_DOWN for vmalloc end alignment Ye Liu
2026-12-03 1:22 ` [PATCH 2/8] mm/vmalloc: extract pcpu_release_va helper Ye Liu
2026-12-03 1:22 ` [PATCH 3/8] mm/vmalloc: fix misleading pr_warn in alloc_vmap_area Ye Liu
2026-12-03 1:22 ` [PATCH 4/8] mm/vmalloc: simplify is_vn_id_valid predicate Ye Liu
2026-12-03 1:22 ` [PATCH 5/8] mm/vmalloc: move pool length update under pool_lock in decay_va_pool_node() Ye Liu
2026-12-03 1:22 ` [PATCH 6/8] mm/vmalloc: report node count when falling back to a single node Ye Liu
2026-12-03 1:22 ` [PATCH 7/8] mm/vmalloc: drop the double negation in vmap_insert_free_area() Ye Liu
2026-12-03 1:22 ` [PATCH 8/8] mm/vmalloc: compare addresses directly in vmap_init_free_space() Ye Liu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.