git: 0a13f4d7934f - stable/14 - riscv: Port improvements from arm64/amd64 pmaps, part 3

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Sat, 02 Dec 2023 21:55:59 UTC
The branch stable/14 has been updated by markj:

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

commit 0a13f4d7934fe1af776f5ec60d5159a59a1a5575
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-11-02 18:34:07 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-12-02 21:54:35 +0000

    riscv: Port improvements from arm64/amd64 pmaps, part 3
    
    - Let pmap_enter_quick_locked() trigger superpage promotions.
    
    Reviewed by:    kib
    MFC after:      1 month
    Differential Revision:  https://reviews.freebsd.org/D42290
    
    (cherry picked from commit 0b8372b707a50c2deeaf66d4c55fec51007cec44)
---
 sys/riscv/riscv/pmap.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c
index 376027c8be8e..79248c4c1fcd 100644
--- a/sys/riscv/riscv/pmap.c
+++ b/sys/riscv/riscv/pmap.c
@@ -3399,6 +3399,7 @@ pmap_enter_quick_locked(pmap_t pmap, vm_offset_t va, vm_page_t m,
 	    ("pmap_enter_quick_locked: managed mapping within the clean submap"));
 	rw_assert(&pvh_global_lock, RA_LOCKED);
 	PMAP_LOCK_ASSERT(pmap, MA_OWNED);
+	l2 = NULL;
 
 	CTR2(KTR_PMAP, "pmap_enter_quick_locked: %p %lx", pmap, va);
 	/*
@@ -3497,6 +3498,26 @@ pmap_enter_quick_locked(pmap_t pmap, vm_offset_t va, vm_page_t m,
 
 	pmap_store(l3, newl3);
 
+#if VM_NRESERVLEVEL > 0
+	/*
+	 * If both the PTP and the reservation are fully populated, then attempt
+	 * promotion.
+	 */
+	if ((mpte == NULL || mpte->ref_count == Ln_ENTRIES) &&
+	    (m->flags & PG_FICTITIOUS) == 0 &&
+	    vm_reserv_level_iffullpop(m) == 0) {
+		if (l2 == NULL)
+			l2 = pmap_l2(pmap, va);
+
+		/*
+		 * If promotion succeeds, then the next call to this function
+		 * should not be given the unmapped PTP as a hint.
+		 */
+		if (pmap_promote_l2(pmap, l2, va, mpte, lockp))
+			mpte = NULL;
+	}
+#endif
+
 	pmap_invalidate_page(pmap, va);
 	return (mpte);
 }