[PATCH] arm: make the size of vmalloc in cmdline and meminfo uniform

Yanfei Xu
2021-05-18T11:13:19Z

The value of "vmalloc=" set in cmdline is always 8M more than the value
of "VmallocTotal" in meminfo. When use the "vmalloc=" parameter, user
expect to get the size what they input, and no need to consider the 8M
"hole" hided in codes. This commit make real vmalloc size equal to value
of "vmalloc=" in cmdline.

Also, the commit will reduce the size of vmalloc printed in boot message
by 8M when the size set in cmdline is irrational.

Signed-off-by: Yanfei Xu <yanfei.xu@windriver.com>
---
arch/arm/mm/mmu.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index c1e12aab67b8..287c5115af4d 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -1133,19 +1133,20 @@ static int __init early_vmalloc(char *arg)
{
unsigned long vmalloc_reserve = memparse(arg, NULL);

- if (vmalloc_reserve < SZ_16M) {
- vmalloc_reserve = SZ_16M;
+ vmalloc_reserve = ALIGN_DOWN(vmalloc_reserve, SZ_8M);
+ if (vmalloc_reserve < SZ_8M) {
+ vmalloc_reserve = SZ_8M;
pr_warn("vmalloc area too small, limiting to %luMB\n",
vmalloc_reserve >> 20);
}

if (vmalloc_reserve > VMALLOC_END - (PAGE_OFFSET + SZ_32M)) {
- vmalloc_reserve = VMALLOC_END - (PAGE_OFFSET + SZ_32M);
+ vmalloc_reserve = VMALLOC_END - (PAGE_OFFSET + SZ_32M + VMALLOC_OFFSET);
pr_warn("vmalloc area is too big, limiting to %luMB\n",
vmalloc_reserve >> 20);
}

- vmalloc_min = (void *)(VMALLOC_END - vmalloc_reserve);
+ vmalloc_min = (void *)(VMALLOC_END - vmalloc_reserve - VMALLOC_OFFSET);
return 0;
}
early_param("vmalloc", early_vmalloc);
--
2.27.0