git: ddc09a10eaa6 - main - pmap_growkernel: Use VM_ALLOC_NOFREE when allocating pagetable pages

From: Bojan Novković <bnovkov_at_FreeBSD.org>
Date: Tue, 30 Jul 2024 15:38:49 UTC
The branch main has been updated by bnovkov:

URL: https://cgit.FreeBSD.org/src/commit/?id=ddc09a10eaa66bbebeb691021bb2a9f934d33d58

commit ddc09a10eaa66bbebeb691021bb2a9f934d33d58
Author:     Bojan Novković <bnovkov@FreeBSD.org>
AuthorDate: 2024-07-16 15:12:25 +0000
Commit:     Bojan Novković <bnovkov@FreeBSD.org>
CommitDate: 2024-07-30 15:38:24 +0000

    pmap_growkernel: Use VM_ALLOC_NOFREE when allocating pagetable pages
    
    This patch modifies pmap_growkernel in all pmaps to use VM_ALLOC_NOFREE
    when allocating new pagetable pages. This should help reduce longterm
    fragmentation as these pages are never released after
    they are allocated.
    
    Differential Revision:  https://reviews.freebsd.org/D45998
    Reviewed by:    alc, markj, kib, mhorne
    Tested by:      alc
---
 sys/amd64/amd64/pmap.c      | 7 ++++---
 sys/arm/arm/pmap-v6.c       | 2 +-
 sys/arm64/arm64/pmap.c      | 6 +++---
 sys/i386/i386/pmap.c        | 4 ++--
 sys/powerpc/aim/mmu_radix.c | 6 +++---
 sys/riscv/riscv/pmap.c      | 6 +++---
 6 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c
index 778d07689ff0..cf0fc7184f56 100644
--- a/sys/amd64/amd64/pmap.c
+++ b/sys/amd64/amd64/pmap.c
@@ -5156,8 +5156,8 @@ pmap_growkernel(vm_offset_t addr)
 		pdpe = pmap_pdpe(kernel_pmap, end);
 		if ((*pdpe & X86_PG_V) == 0) {
 			nkpg = pmap_alloc_pt_page(kernel_pmap,
-			    pmap_pdpe_pindex(end), VM_ALLOC_WIRED |
-			    VM_ALLOC_INTERRUPT | VM_ALLOC_ZERO);
+			    pmap_pdpe_pindex(end), VM_ALLOC_INTERRUPT |
+			        VM_ALLOC_NOFREE | VM_ALLOC_WIRED | VM_ALLOC_ZERO);
 			if (nkpg == NULL)
 				panic("pmap_growkernel: no memory to grow kernel");
 			paddr = VM_PAGE_TO_PHYS(nkpg);
@@ -5176,7 +5176,8 @@ pmap_growkernel(vm_offset_t addr)
 		}
 
 		nkpg = pmap_alloc_pt_page(kernel_pmap, pmap_pde_pindex(end),
-		    VM_ALLOC_WIRED | VM_ALLOC_INTERRUPT | VM_ALLOC_ZERO);
+		    VM_ALLOC_INTERRUPT | VM_ALLOC_NOFREE | VM_ALLOC_WIRED |
+			VM_ALLOC_ZERO);
 		if (nkpg == NULL)
 			panic("pmap_growkernel: no memory to grow kernel");
 		paddr = VM_PAGE_TO_PHYS(nkpg);
diff --git a/sys/arm/arm/pmap-v6.c b/sys/arm/arm/pmap-v6.c
index de1082e7ae62..6cc78b187a9a 100644
--- a/sys/arm/arm/pmap-v6.c
+++ b/sys/arm/arm/pmap-v6.c
@@ -2067,7 +2067,7 @@ pmap_growkernel(vm_offset_t addr)
 			 * Install new PT2s page into kernel PT2TAB.
 			 */
 			m = vm_page_alloc_noobj(VM_ALLOC_INTERRUPT |
-			    VM_ALLOC_WIRED | VM_ALLOC_ZERO);
+			    VM_ALLOC_NOFREE | VM_ALLOC_WIRED | VM_ALLOC_ZERO);
 			if (m == NULL)
 				panic("%s: no memory to grow kernel", __func__);
 			m->pindex = pte1_index(kernel_vm_end) & ~PT2PG_MASK;
diff --git a/sys/arm64/arm64/pmap.c b/sys/arm64/arm64/pmap.c
index 59de6ef37f09..58795e25c82e 100644
--- a/sys/arm64/arm64/pmap.c
+++ b/sys/arm64/arm64/pmap.c
@@ -2959,7 +2959,7 @@ pmap_growkernel(vm_offset_t addr)
 		if (pmap_load(l1) == 0) {
 			/* We need a new PDP entry */
 			nkpg = vm_page_alloc_noobj(VM_ALLOC_INTERRUPT |
-			    VM_ALLOC_WIRED | VM_ALLOC_ZERO);
+			    VM_ALLOC_NOFREE | VM_ALLOC_WIRED | VM_ALLOC_ZERO);
 			if (nkpg == NULL)
 				panic("pmap_growkernel: no memory to grow kernel");
 			nkpg->pindex = kernel_vm_end >> L1_SHIFT;
@@ -2978,8 +2978,8 @@ pmap_growkernel(vm_offset_t addr)
 			continue;
 		}
 
-		nkpg = vm_page_alloc_noobj(VM_ALLOC_INTERRUPT | VM_ALLOC_WIRED |
-		    VM_ALLOC_ZERO);
+		nkpg = vm_page_alloc_noobj(VM_ALLOC_INTERRUPT |
+		    VM_ALLOC_NOFREE | VM_ALLOC_WIRED | VM_ALLOC_ZERO);
 		if (nkpg == NULL)
 			panic("pmap_growkernel: no memory to grow kernel");
 		nkpg->pindex = kernel_vm_end >> L2_SHIFT;
diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c
index 5808c31a99af..57ba48d399c3 100644
--- a/sys/i386/i386/pmap.c
+++ b/sys/i386/i386/pmap.c
@@ -2264,8 +2264,8 @@ __CONCAT(PMTYPE, growkernel)(vm_offset_t addr)
 			continue;
 		}
 
-		nkpg = vm_page_alloc_noobj(VM_ALLOC_INTERRUPT | VM_ALLOC_WIRED |
-		    VM_ALLOC_ZERO);
+		nkpg = vm_page_alloc_noobj(VM_ALLOC_INTERRUPT |
+		    VM_ALLOC_NOFREE | VM_ALLOC_WIRED | VM_ALLOC_ZERO);
 		if (nkpg == NULL)
 			panic("pmap_growkernel: no memory to grow kernel");
 		nkpg->pindex = kernel_vm_end >> PDRSHIFT;
diff --git a/sys/powerpc/aim/mmu_radix.c b/sys/powerpc/aim/mmu_radix.c
index ae6e4d116e87..0a38ad97ad91 100644
--- a/sys/powerpc/aim/mmu_radix.c
+++ b/sys/powerpc/aim/mmu_radix.c
@@ -3580,7 +3580,7 @@ mmu_radix_growkernel(vm_offset_t addr)
 		if ((be64toh(*l2e) & PG_V) == 0) {
 			/* We need a new PDP entry */
 			nkpg = vm_page_alloc_noobj(VM_ALLOC_INTERRUPT |
-			    VM_ALLOC_WIRED | VM_ALLOC_ZERO);
+			    VM_ALLOC_NOFREE | VM_ALLOC_WIRED | VM_ALLOC_ZERO);
 			if (nkpg == NULL)
 				panic("pmap_growkernel: no memory to grow kernel");
 			nkpg->pindex = kernel_vm_end >> L2_PAGE_SIZE_SHIFT;
@@ -3598,8 +3598,8 @@ mmu_radix_growkernel(vm_offset_t addr)
 			continue;
 		}
 
-		nkpg = vm_page_alloc_noobj(VM_ALLOC_INTERRUPT | VM_ALLOC_WIRED |
-		    VM_ALLOC_ZERO);
+		nkpg = vm_page_alloc_noobj(VM_ALLOC_INTERRUPT |
+		    VM_ALLOC_NOFREE | VM_ALLOC_WIRED | VM_ALLOC_ZERO);
 		if (nkpg == NULL)
 			panic("pmap_growkernel: no memory to grow kernel");
 		nkpg->pindex = pmap_l3e_pindex(kernel_vm_end);
diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c
index bcf2ada887fb..34922b0f511e 100644
--- a/sys/riscv/riscv/pmap.c
+++ b/sys/riscv/riscv/pmap.c
@@ -1832,7 +1832,7 @@ pmap_growkernel(vm_offset_t addr)
 		if (pmap_load(l1) == 0) {
 			/* We need a new PDP entry */
 			nkpg = vm_page_alloc_noobj(VM_ALLOC_INTERRUPT |
-			    VM_ALLOC_WIRED | VM_ALLOC_ZERO);
+			    VM_ALLOC_NOFREE | VM_ALLOC_WIRED | VM_ALLOC_ZERO);
 			if (nkpg == NULL)
 				panic("pmap_growkernel: no memory to grow kernel");
 			nkpg->pindex = kernel_vm_end >> L1_SHIFT;
@@ -1857,8 +1857,8 @@ pmap_growkernel(vm_offset_t addr)
 			continue;
 		}
 
-		nkpg = vm_page_alloc_noobj(VM_ALLOC_INTERRUPT | VM_ALLOC_WIRED |
-		    VM_ALLOC_ZERO);
+		nkpg = vm_page_alloc_noobj(VM_ALLOC_INTERRUPT |
+		    VM_ALLOC_NOFREE | VM_ALLOC_WIRED | VM_ALLOC_ZERO);
 		if (nkpg == NULL)
 			panic("pmap_growkernel: no memory to grow kernel");
 		nkpg->pindex = kernel_vm_end >> L2_SHIFT;