Add (minimal) accounting for wired pages in userland pmaps.
authorkettenis <kettenis@openbsd.org>
Tue, 12 Oct 2021 18:06:15 +0000 (18:06 +0000)
committerkettenis <kettenis@openbsd.org>
Tue, 12 Oct 2021 18:06:15 +0000 (18:06 +0000)
This enables enforcing of RLIMIT_MEMLOCK on powerpc64.

ok mpi@

sys/arch/powerpc64/include/pmap.h
sys/arch/powerpc64/powerpc64/pmap.c

index bb6c29d..c7f4c9e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pmap.h,v 1.17 2021/05/30 15:08:08 visa Exp $  */
+/*     $OpenBSD: pmap.h,v 1.18 2021/10/12 18:06:15 kettenis Exp $      */
 
 /*
  * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
@@ -62,6 +62,7 @@ extern struct pmap kernel_pmap_store;
 
 #define pmap_kernel()  (&kernel_pmap_store)
 #define pmap_resident_count(pm) ((pm)->pm_stats.resident_count)
+#define pmap_wired_count(pm)   ((pm)->pm_stats.wired_count)
 
 #define pmap_unuse_final(p)
 #define pmap_remove_holes(vm)
index f18c919..9d19c54 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pmap.c,v 1.56 2021/05/11 18:21:12 kettenis Exp $ */
+/*     $OpenBSD: pmap.c,v 1.57 2021/10/12 18:06:15 kettenis Exp $ */
 
 /*
  * Copyright (c) 2015 Martin Pieuchot
@@ -217,6 +217,12 @@ PTED_MANAGED(struct pte_desc *pted)
        return !!(pted->pted_va & PTED_VA_MANAGED_M);
 }
 
+static inline int
+PTED_WIRED(struct pte_desc *pted)
+{
+       return !!(pted->pted_va & PTED_VA_WIRED_M);
+}
+
 static inline int
 PTED_VALID(struct pte_desc *pted)
 {
@@ -858,6 +864,11 @@ pmap_remove_pted(pmap_t pm, struct pte_desc *pted)
 
        pm->pm_stats.resident_count--;
 
+       if (PTED_WIRED(pted)) {
+               pm->pm_stats.wired_count--;
+               pted->pted_va &= ~PTED_VA_WIRED_M;
+       }
+
        PMAP_HASH_LOCK(s);
        if ((pte = pmap_ptedinhash(pted)) != NULL)
                pte_zap(pte, pted);
@@ -1085,6 +1096,10 @@ pmap_enter(pmap_t pm, vaddr_t va, paddr_t pa, vm_prot_t prot, int flags)
                prot &= ~PROT_WRITE;
 
        pmap_fill_pte(pm, va, pa, pted, prot, cache);
+       if (flags & PMAP_WIRED) {
+               pted->pted_va |= PTED_VA_WIRED_M;
+               pm->pm_stats.wired_count++;
+       }
 
        if (pg != NULL) {
                pmap_enter_pv(pted, pg); /* only managed mem */
@@ -1438,6 +1453,15 @@ pmap_deactivate(struct proc *p)
 void
 pmap_unwire(pmap_t pm, vaddr_t va)
 {
+       struct pte_desc *pted;
+
+       PMAP_VP_LOCK(pm);
+       pted = pmap_vp_lookup(pm, va);
+       if (pted && PTED_WIRED(pted)) {
+               pm->pm_stats.wired_count--;
+               pted->pted_va &= ~PTED_VA_WIRED_M;
+       }
+       PMAP_VP_UNLOCK(pm);
 }
 
 void