Skip to content

Commit b2129a3

Browse files
committed
memblock: make free_reserved_area() update memblock if ARCH_KEEP_MEMBLOCK=y
On architectures that keep memblock after boot, freeing of reserved memory with free_reserved_area() is paired with an update of memblock arrays, usually by a call to memblock_free(). Make free_reserved_area() directly update memblock.reserved when ARCH_KEEP_MEMBLOCK is enabled. Remove the now-redundant explicit memblock_free() call from arm64::free_initmem() and the #ifdef CONFIG_ARCH_KEEP_MEMBLOCK block from the generic free_initrd_mem(). Link: https://patch.msgid.link/20260323074836.3653702-8-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
1 parent 7fbc5e2 commit b2129a3

3 files changed

Lines changed: 6 additions & 10 deletions

File tree

arch/arm64/mm/init.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,6 @@ void free_initmem(void)
385385
WARN_ON(!IS_ALIGNED((unsigned long)lm_init_begin, PAGE_SIZE));
386386
WARN_ON(!IS_ALIGNED((unsigned long)lm_init_end, PAGE_SIZE));
387387

388-
/* Delete __init region from memblock.reserved. */
389-
memblock_free(lm_init_begin, lm_init_end - lm_init_begin);
390-
391388
free_reserved_area(lm_init_begin, lm_init_end,
392389
POISON_FREE_INITMEM, "unused kernel");
393390
/*

init/initramfs.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -652,13 +652,6 @@ void __init reserve_initrd_mem(void)
652652

653653
void __weak __init free_initrd_mem(unsigned long start, unsigned long end)
654654
{
655-
#ifdef CONFIG_ARCH_KEEP_MEMBLOCK
656-
unsigned long aligned_start = ALIGN_DOWN(start, PAGE_SIZE);
657-
unsigned long aligned_end = ALIGN(end, PAGE_SIZE);
658-
659-
memblock_free((void *)aligned_start, aligned_end - aligned_start);
660-
#endif
661-
662655
free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
663656
"initrd");
664657
}

mm/memblock.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,12 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char
943943
end_pa = __pa(end - 1) + 1;
944944
}
945945

946+
if (IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK)) {
947+
if (start_pa < end_pa)
948+
memblock_remove_range(&memblock.reserved,
949+
start_pa, end_pa - start_pa);
950+
}
951+
946952
pages = __free_reserved_area(start_pa, end_pa, poison);
947953
if (pages && s)
948954
pr_info("Freeing %s memory: %ldK\n", s, K(pages));

0 commit comments

Comments
 (0)