mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
mm/vmalloc: extract vmap_insert_free_area helper
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. Link: https://lore.kernel.org/20260915-vmalloc_study-v2-2-cc4dfe635e22@linux.dev Signed-off-by: Ye Liu <liuye@kylinos.cn> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com> Reviewed-by: Dev Jain <dev.jain@arm.com>
This commit is contained in:
parent
ebb07f8a8b
commit
c10ed0f231
41
mm/vmalloc.c
41
mm/vmalloc.c
|
|
@ -5419,11 +5419,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;
|
||||
|
||||
/*
|
||||
|
|
@ -5433,32 +5445,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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user