mm/vmalloc: minor cleanups
Subsystems (2)
cover mm/vmalloc: minor cleanups
Small cleanup series for mm/vmalloc.c, no functional changes:
- Group xa_init() with the other vmap_block_queue field initializations in vmalloc_init(), instead of after the unrelated vfree_deferred setup.
- Extract vmap_insert_free_area() helper to deduplicate the allocate- and-insert pattern that appeared both inside the loop body and after the loop in vmap_init_free_space().
- Extract show_busy_info() from vmalloc_info_show(), mirroring the existing show_purge_info() pattern, so the top-level show function only orchestrates the two data sources.
---
Ye Liu (3):
mm/vmalloc: group xa_init with vbq field initializations mm/vmalloc: extract vmap_insert_free_area helper mm/vmalloc: extract show_busy_info from vmalloc_info_show
mm/vmalloc.c | 58 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 28 deletions(-)
---
base-commit: 68142f986ff04b2b70b31db00f719bf690f64a9a
change-id: 20260914-vmalloc_study-b3fe7c738f2a
Best regards,
Signature · 1 line
Ye Liu <[email protected]>
PATCH 1/3 mm/vmalloc: group xa_init with vbq field initializations
From: Ye Liu <[email protected]>
Move xa_init() next to the other vbq field initializations instead of after the unrelated vfree_deferred setup.
--- mm/vmalloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/vmalloc.c +2 -1
@@ -5585,10 +5585,11 @@ void __init vmalloc_init(void) vbq = &per_cpu (vmap_block_queue, i);spin_lock_init (&vbq->lock);INIT_LIST_HEAD (&vbq->free); +xa_init (&vbq->vmap_blocks); + p = &per_cpu (vfree_deferred, i);init_llist_head (&p->list);INIT_WORK (&p->wq, delayed_vfree_work); -xa_init (&vbq->vmap_blocks); }/*
Signature · 1 line
2.25.1
Re: [PATCH 1/3] mm/vmalloc: group xa_init with vbq field initializations
Quoted 31 lines · Ye Liu
From: Ye Liu <[email protected]>
Move
xa_init()next to the other vbq field initializations instead of after the unrelatedvfree_deferredsetup.Signed-off-by Ye Liu <[email protected]>--- mm/vmalloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/vmalloc.c +2
-1@@ -5585,10 +5585,11 @@ void __init vmalloc_init(void) vbq = &per_cpu (vmap_block_queue, i);spin_lock_init (&vbq->lock);INIT_LIST_HEAD (&vbq->free); +xa_init (&vbq->vmap_blocks); + p = &per_cpu (vfree_deferred, i);init_llist_head (&p->list);INIT_WORK (&p->wq, delayed_vfree_work); -xa_init (&vbq->vmap_blocks); }/* Signature · 2 lines
-- 2.25.1
LGTM:
--
Uladzislau Rezki
Re: [PATCH 1/3] mm/vmalloc: group xa_init with vbq field initializations
In reply to Ye LiuQuoted 7 lines · Ye Liu
From: Ye Liu <[email protected]>
Move
xa_init()next to the other vbq field initializations instead of after the unrelatedvfree_deferredsetup.Signed-off-by Ye Liu <[email protected]>---
LGTM
Quoted 21 lines
mm/vmalloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/vmalloc.c +2
-1@@ -5585,10 +5585,11 @@ void __init vmalloc_init(void) vbq = &per_cpu (vmap_block_queue, i);spin_lock_init (&vbq->lock);INIT_LIST_HEAD (&vbq->free); +xa_init (&vbq->vmap_blocks); + p = &per_cpu (vfree_deferred, i);init_llist_head (&p->list);INIT_WORK (&p->wq, delayed_vfree_work); -xa_init (&vbq->vmap_blocks); }/*
PATCH 2/3 mm/vmalloc: extract vmap_insert_free_area helper
In reply to Ye LiuFrom: Ye Liu <[email protected]>
The allocation and insertion of a free vmap_area is duplicated between the loop body and the tail of vmap_init_free_space. Factor it into a small helper so the main function only deals with computing the free gaps between busy regions.
--- mm/vmalloc.c | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-)
mm/vmalloc.c +18 -23
@@ -5433,11 +5433,23 @@ module_init(proc_vmalloc_init);#endif +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); + } +} +static void __init vmap_init_free_space (void ) {unsigned long vmap_start =1 ;const unsigned long vmap_end =ULONG_MAX ; -struct vmap_area *free;struct vm_struct *busy;/*
@@ -5447,32 +5459,15 @@ static void __init vmap_init_free_space(void)* |<--------------------------------->| */ for (busy = vmlist; busy; busy = busy->next) { -if ((unsigned long ) busy->addr - vmap_start >0 ) { - free =kmem_cache_zalloc (vmap_area_cachep,GFP_NOWAIT ); -if (!WARN_ON_ONCE (!free)) { - free->va_start = vmap_start; - free->va_end = (unsigned long ) busy->addr; - -insert_vmap_area_augment (free,NULL , - &free_vmap_area_root, - &free_vmap_area_list); - } - } +if ((unsigned long )busy->addr - vmap_start >0 ) +vmap_insert_free_area (vmap_start, + (unsigned long )busy->addr); vmap_start = (unsigned long ) busy->addr + busy->size; } -if (vmap_end - vmap_start >0 ) { - free =kmem_cache_zalloc (vmap_area_cachep,GFP_NOWAIT ); -if (!WARN_ON_ONCE (!free)) { - free->va_start = vmap_start; - free->va_end = vmap_end; - -insert_vmap_area_augment (free,NULL , - &free_vmap_area_root, - &free_vmap_area_list); - } - } +if (vmap_end - vmap_start >0 ) +vmap_insert_free_area (vmap_start, vmap_end); }static void vmap_init_nodes (void )
Signature · 1 line
2.25.1
Re: [PATCH 2/3] mm/vmalloc: extract vmap_insert_free_area helper
Quoted 42 lines · Ye Liu
From: Ye Liu <[email protected]>
The allocation and insertion of a free
vmap_areais duplicated between the loop body and the tail ofvmap_init_free_space. Factor it into a small helper so the main function only deals with computing the free gaps between busy regions.Signed-off-by Ye Liu <[email protected]>--- mm/vmalloc.c | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-)mm/vmalloc.c +13
-1@@ -5433,11 +5433,23 @@ module_init(proc_vmalloc_init);#endif +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); + } +} +static void __init vmap_init_free_space (void ) {unsigned long vmap_start =1 ;const unsigned long vmap_end =ULONG_MAX ; -struct vmap_area *free;struct vm_struct *busy;/*
mm/vmalloc.c static void __init vmap_init_free_space(void) · line 5462
Quoted 5 lines
mm/vmalloc.c +0
-1@@ -5447,32 +5459,15 @@ static void __init vmap_init_free_space(void)* |<--------------------------------->| */ for (busy = vmlist; busy; busy = busy->next) { -if ((unsigned long ) busy->addr - vmap_start >0 ) {
This line gets removed and then re-added below because of removing space after (unsigned long). Maybe it is better to keep that space.
Quoted 32 lines
mm/vmalloc.c +5
-21- free =kmem_cache_zalloc (vmap_area_cachep,GFP_NOWAIT ); -if (!WARN_ON_ONCE (!free)) { - free->va_start = vmap_start; - free->va_end = (unsigned long ) busy->addr; - -insert_vmap_area_augment (free,NULL , - &free_vmap_area_root, - &free_vmap_area_list); - } - } +if ((unsigned long )busy->addr - vmap_start >0 ) +vmap_insert_free_area (vmap_start, + (unsigned long )busy->addr); vmap_start = (unsigned long ) busy->addr + busy->size; } -if (vmap_end - vmap_start >0 ) { - free =kmem_cache_zalloc (vmap_area_cachep,GFP_NOWAIT ); -if (!WARN_ON_ONCE (!free)) { - free->va_start = vmap_start; - free->va_end = vmap_end; - -insert_vmap_area_augment (free,NULL , - &free_vmap_area_root, - &free_vmap_area_list); - } - } +if (vmap_end - vmap_start >0 ) +vmap_insert_free_area (vmap_start, vmap_end); }
Quoted 5 lines
static void
vmap_init_nodes(void)Signature · 1 line
2.25.1
LGTM:
--
Uladzislau Rezki
Re: [PATCH 2/3] mm/vmalloc: extract vmap_insert_free_area helper
Quoted 41 lines · Uladzislau Rezki
Quoted 40 lines · Ye Liu
From: Ye Liu <[email protected]>
The allocation and insertion of a free
vmap_areais duplicated between the loop body and the tail ofvmap_init_free_space. Factor it into a small helper so the main function only deals with computing the free gaps between busy regions.Signed-off-by Ye Liu <[email protected]>--- mm/vmalloc.c | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-)mm/vmalloc.c +13
-1@@ -5433,11 +5433,23 @@ module_init(proc_vmalloc_init);#endif +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); + } +} +static void __init vmap_init_free_space (void ) {unsigned long vmap_start =1 ;const unsigned long vmap_end =ULONG_MAX ; -struct vmap_area *free;struct vm_struct *busy;
Quoted 9 lines
mm/vmalloc.c static void __init vmap_init_free_space(void) · line 5462
Quoted 7 lines
mm/vmalloc.c +0
-1/* @@ -5447,32 +5459,15 @@ static void __init vmap_init_free_space(void)* |<--------------------------------->| */ for (busy = vmlist; busy; busy = busy->next) { -if ((unsigned long ) busy->addr - vmap_start >0 ) {This line gets removed and then re-added below because of removing space after (unsigned long). Maybe it is better to keep that space.
However, the '{' is still there, but I'll add a space anyway.
Quoted 44 lines
Quoted 33 lines
mm/vmalloc.c +5
-21- free =kmem_cache_zalloc (vmap_area_cachep,GFP_NOWAIT ); -if (!WARN_ON_ONCE (!free)) { - free->va_start = vmap_start; - free->va_end = (unsigned long ) busy->addr; - -insert_vmap_area_augment (free,NULL , - &free_vmap_area_root, - &free_vmap_area_list); - } - } +if ((unsigned long )busy->addr - vmap_start >0 ) +vmap_insert_free_area (vmap_start, + (unsigned long )busy->addr); vmap_start = (unsigned long ) busy->addr + busy->size; } -if (vmap_end - vmap_start >0 ) { - free =kmem_cache_zalloc (vmap_area_cachep,GFP_NOWAIT ); -if (!WARN_ON_ONCE (!free)) { - free->va_start = vmap_start; - free->va_end = vmap_end; - -insert_vmap_area_augment (free,NULL , - &free_vmap_area_root, - &free_vmap_area_list); - } - } +if (vmap_end - vmap_start >0 ) +vmap_insert_free_area (vmap_start, vmap_end); }Quoted 5 lines
static void
vmap_init_nodes(void)Signature · 1 line
2.25.1LGTM:
Reviewed-by Uladzislau Rezki (Sony) <[email protected]>--
Uladzislau Rezki
Signature · 2 lines
Thanks, Ye Liu
Dev Jain
Reviewed-byRe: [PATCH 2/3] mm/vmalloc: extract vmap_insert_free_area helper
Quoted 53 lines · Ye Liu
Quoted 41 lines · Uladzislau Rezki
Quoted 40 lines · Ye Liu
From: Ye Liu <[email protected]>
The allocation and insertion of a free
vmap_areais duplicated between the loop body and the tail ofvmap_init_free_space. Factor it into a small helper so the main function only deals with computing the free gaps between busy regions.Signed-off-by Ye Liu <[email protected]>--- mm/vmalloc.c | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-)mm/vmalloc.c +13
-1@@ -5433,11 +5433,23 @@ module_init(proc_vmalloc_init);#endif +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); + } +} +static void __init vmap_init_free_space (void ) {unsigned long vmap_start =1 ;const unsigned long vmap_end =ULONG_MAX ; -struct vmap_area *free;struct vm_struct *busy;Quoted 9 lines
mm/vmalloc.c static void __init vmap_init_free_space(void) · line 5462
Quoted 7 lines
mm/vmalloc.c +0
-1/* @@ -5447,32 +5459,15 @@ static void __init vmap_init_free_space(void)* |<--------------------------------->| */ for (busy = vmlist; busy; busy = busy->next) { -if ((unsigned long ) busy->addr - vmap_start >0 ) {This line gets removed and then re-added below because of removing space after (unsigned long). Maybe it is better to keep that space.
Quoted 1 line
However, the '{' is still there, but I'll add a space anyway.
Just mentioning in the commit message "while at it, drop redundant whitespace in "(unsigned long) busy->addr" should suffice.
PATCH 3/3 mm/vmalloc: extract show_busy_info from vmalloc_info_show
In reply to Ye LiuFrom: Ye Liu <[email protected]>
Extract the busy vmap area iteration into show_busy_info, mirroring the existing show_purge_info pattern.
--- mm/vmalloc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
mm/vmalloc.c +10 -4
@@ -5345,12 +5345,12 @@ static void show_purge_info(struct seq_file *m) } } -static int vmalloc_info_show (struct seq_file *m,void *p) +static void show_busy_info (struct seq_file *m) {struct vmap_node *vn;struct vmap_area *va;struct vm_struct *v; -unsigned int *counters; +unsigned int *counters =NULL ;if (IS_ENABLED (CONFIG_NUMA )) counters =kmalloc_array (nr_node_ids,sizeof (unsigned int ),GFP_KERNEL );
@@ -5415,12 +5415,18 @@ static int vmalloc_info_show(struct seq_file *m, void *p)spin_unlock (&vn->busy.lock); } +if (IS_ENABLED (CONFIG_NUMA )) +kfree (counters); +} + +static int vmalloc_info_show (struct seq_file *m,void *p) +{ +show_busy_info (m); +/* * As a final step, dump "unpurged" areas. */ show_purge_info (m); -if (IS_ENABLED (CONFIG_NUMA )) -kfree (counters);return 0 ; }
Signature · 1 line
2.25.1
Re: [PATCH 3/3] mm/vmalloc: extract show_busy_info from vmalloc_info_show
Quoted 17 lines · Ye Liu
From: Ye Liu <[email protected]>
Extract the busy vmap area iteration into
show_busy_info, mirroring the existingshow_purge_infopattern.Signed-off-by Ye Liu <[email protected]>--- mm/vmalloc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)mm/vmalloc.c +0
-0@@ -5345,12 +5345,12 @@ static void show_purge_info(struct seq_file *m) } }
mm/vmalloc.c static void show_purge_info(struct seq_file *m) · line 5354
Quoted 10 lines
mm/vmalloc.c +2
-2-static int vmalloc_info_show (struct seq_file *m,void *p) +static void show_busy_info (struct seq_file *m) {struct vmap_node *vn;struct vmap_area *va;struct vm_struct *v; -unsigned int *counters; +unsigned int *counters =NULL ;
Is setting counters setting to NULL odd here?
Other than that, LGTM:
--
Uladzislau Rezki
Re: [PATCH 3/3] mm/vmalloc: extract show_busy_info from vmalloc_info_show
Quoted 19 lines · Uladzislau Rezki
Quoted 18 lines · Ye Liu
From: Ye Liu <[email protected]>
Extract the busy vmap area iteration into
show_busy_info, mirroring the existingshow_purge_infopattern.Signed-off-by Ye Liu <[email protected]>--- mm/vmalloc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)mm/vmalloc.c +0
-0@@ -5345,12 +5345,12 @@ static void show_purge_info(struct seq_file *m) } }
Quoted 11 lines
mm/vmalloc.c static void show_purge_info(struct seq_file *m) · line 5354
Quoted 9 lines
mm/vmalloc.c +2
-2-static int vmalloc_info_show (struct seq_file *m,void *p) +static void show_busy_info (struct seq_file *m) {struct vmap_node *vn;struct vmap_area *va;struct vm_struct *v; -unsigned int *counters; +unsigned int *counters =NULL ;Is setting counters setting to NULL odd here?
I would remove '= NULL'.
Quoted 6 lines
Other than that, LGTM:
Reviewed-by Uladzislau Rezki (Sony) <[email protected]>--
Uladzislau Rezki
Signature · 2 lines
Thanks, Ye Liu
Andrew Morton
maintainerRe: [PATCH 3/3] mm/vmalloc: extract show_busy_info from vmalloc_info_show
In reply to Uladzislau RezkiQuoted 19 lines · On Mon, 14 Sep 2026 19:10:37 +0200 Uladzislau Rezki <[email protected]> wrote:
Quoted 18 lines · Ye Liu
From: Ye Liu <[email protected]>
Extract the busy vmap area iteration into
show_busy_info, mirroring the existingshow_purge_infopattern.Signed-off-by Ye Liu <[email protected]>--- mm/vmalloc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)mm/vmalloc.c +0
-0@@ -5345,12 +5345,12 @@ static void show_purge_info(struct seq_file *m) } }
Quoted 10 lines
mm/vmalloc.c static void show_purge_info(struct seq_file *m) · line 5354
Quoted 9 lines
mm/vmalloc.c +2
-2-static int vmalloc_info_show (struct seq_file *m,void *p) +static void show_busy_info (struct seq_file *m) {struct vmap_node *vn;struct vmap_area *va;struct vm_struct *v; -unsigned int *counters; +unsigned int *counters =NULL ;Is setting counters setting to NULL odd here?
static void show_busy_info(struct seq_file *m)
{
...
unsigned int *counters = NULL;
if (IS_ENABLED(CONFIG_NUMA))
counters = ...
...
if (IS_ENABLED(CONFIG_NUMA))
kfree(counters);
...
}Presumably some dumb compiler or checker warned about kfree(uninitialized-val).
Uladzislau Rezki
maintainerRe: [PATCH 3/3] mm/vmalloc: extract show_busy_info from vmalloc_info_show
Quoted 47 lines · Andrew Morton
Quoted 19 lines · On Mon, 14 Sep 2026 19:10:37 +0200 Uladzislau Rezki <[email protected]> wrote:
Quoted 18 lines · Ye Liu
From: Ye Liu <[email protected]>
Extract the busy vmap area iteration into
show_busy_info, mirroring the existingshow_purge_infopattern.Signed-off-by Ye Liu <[email protected]>--- mm/vmalloc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)mm/vmalloc.c +0
-0@@ -5345,12 +5345,12 @@ static void show_purge_info(struct seq_file *m) } }Quoted 10 lines
mm/vmalloc.c static void show_purge_info(struct seq_file *m) · line 5354
Quoted 9 lines
mm/vmalloc.c +2
-2-static int vmalloc_info_show (struct seq_file *m,void *p) +static void show_busy_info (struct seq_file *m) {struct vmap_node *vn;struct vmap_area *va;struct vm_struct *v; -unsigned int *counters; +unsigned int *counters =NULL ;Is setting counters setting to NULL odd here?
static void
show_busy_info(struct seq_file *m){ ... unsigned int *counters = NULL; if (IS_ENABLED(CONFIG_NUMA)) counters = ... ... if (IS_ENABLED(CONFIG_NUMA)) kfree(counters); ... }
Quoted 3 lines
Presumably some dumb compiler or checker warned about kfree(uninitialized-val).
Probably.
--
Uladzislau Rezki
Re: [PATCH 3/3] mm/vmalloc: extract show_busy_info from vmalloc_info_show
In reply to Ye LiuQuoted 16 lines · Ye Liu
From: Ye Liu <[email protected]>
Extract the busy vmap area iteration into
show_busy_info, mirroring the existingshow_purge_infopattern.Signed-off-by Ye Liu <[email protected]>--- mm/vmalloc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)mm/vmalloc.c +0
-0@@ -5345,12 +5345,12 @@ static void show_purge_info(struct seq_file *m) }
mm/vmalloc.c static void show_purge_info(struct seq_file *m) · line 5353
Quoted 10 lines
mm/vmalloc.c +2
-2} -static int vmalloc_info_show (struct seq_file *m,void *p) +static void show_busy_info (struct seq_file *m) {struct vmap_node *vn;struct vmap_area *va;struct vm_struct *v; -unsigned int *counters; +unsigned int *counters =NULL ;
As pointed out by Uladzislau, setting to NULL is redundant.
Apart from that LGTM
Quoted 25 lines
mm/vmalloc.c +8
-2if (IS_ENABLED (CONFIG_NUMA )) counters =kmalloc_array (nr_node_ids,sizeof (unsigned int ),GFP_KERNEL );@@ -5415,12 +5415,18 @@ static int vmalloc_info_show(struct seq_file *m, void *p)spin_unlock (&vn->busy.lock); } +if (IS_ENABLED (CONFIG_NUMA )) +kfree (counters); +} + +static int vmalloc_info_show (struct seq_file *m,void *p) +{ +show_busy_info (m); +/* * As a final step, dump "unpurged" areas. */ show_purge_info (m); -if (IS_ENABLED (CONFIG_NUMA )) -kfree (counters);return 0 ; }