Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/alpha Store the modified / referenced attribute bit...



details:   https://anonhg.NetBSD.org/src/rev/353720775980
branches:  trunk
changeset: 379400:353720775980
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun May 30 06:41:19 2021 +0000

description:
Store the modified / referenced attribute bits in the lower 2 bits of
the PV entry list pointer in struct vm_page_md.  This reduces the size
of that structure from 16 bytes to 8, and will go a fair way to making
up for increasing the size of struct pv_entry in a future commit.

diffstat:

 sys/arch/alpha/alpha/pmap.c   |  41 ++++++++++++++++++++++-------------------
 sys/arch/alpha/include/pmap.h |  21 ++++++++++-----------
 2 files changed, 32 insertions(+), 30 deletions(-)

diffs (177 lines):

diff -r 53015e07c7a7 -r 353720775980 sys/arch/alpha/alpha/pmap.c
--- a/sys/arch/alpha/alpha/pmap.c       Sun May 30 06:05:24 2021 +0000
+++ b/sys/arch/alpha/alpha/pmap.c       Sun May 30 06:41:19 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.286 2021/05/30 05:26:09 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.287 2021/05/30 06:41:19 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008, 2020
@@ -135,7 +135,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.286 2021/05/30 05:26:09 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.287 2021/05/30 06:41:19 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -2233,17 +2233,18 @@ pmap_enter(pmap_t pmap, vaddr_t va, padd
        npte = ((pa >> PGSHIFT) << PG_SHIFT) | pte_prot(pmap, prot) | PG_V;
        if (pg != NULL) {
                struct vm_page_md * const md = VM_PAGE_TO_MD(pg);
-               int attrs;
+               uintptr_t attrs = 0;
 
                KASSERT(((flags & VM_PROT_ALL) & ~prot) == 0);
 
+               if (flags & VM_PROT_WRITE)
+                       attrs |= (PGA_REFERENCED|PGA_MODIFIED);
+               else if (flags & VM_PROT_ALL)
+                       attrs |= PGA_REFERENCED;
+
                lock = pmap_pvh_lock(pg);
                mutex_enter(lock);
-               if (flags & VM_PROT_WRITE)
-                       md->pvh_attrs |= (PGA_REFERENCED|PGA_MODIFIED);
-               else if (flags & VM_PROT_ALL)
-                       md->pvh_attrs |= PGA_REFERENCED;
-               attrs = md->pvh_attrs;
+               md->pvh_listx |= attrs;
                mutex_exit(lock);
 
                /* Set up referenced/modified emulation for new mapping. */
@@ -2779,10 +2780,10 @@ pmap_clear_modify(struct vm_page *pg)
        lock = pmap_pvh_lock(pg);
        mutex_enter(lock);
 
-       if (md->pvh_attrs & PGA_MODIFIED) {
+       if (md->pvh_listx & PGA_MODIFIED) {
                rv = true;
                pmap_changebit(pg, PG_FOW, ~0UL, &tlbctx);
-               md->pvh_attrs &= ~PGA_MODIFIED;
+               md->pvh_listx &= ~PGA_MODIFIED;
        }
 
        mutex_exit(lock);
@@ -2818,10 +2819,10 @@ pmap_clear_reference(struct vm_page *pg)
        lock = pmap_pvh_lock(pg);
        mutex_enter(lock);
 
-       if (md->pvh_attrs & PGA_REFERENCED) {
+       if (md->pvh_listx & PGA_REFERENCED) {
                rv = true;
                pmap_changebit(pg, PG_FOR | PG_FOW | PG_FOE, ~0UL, &tlbctx);
-               md->pvh_attrs &= ~PGA_REFERENCED;
+               md->pvh_listx &= ~PGA_REFERENCED;
        }
 
        mutex_exit(lock);
@@ -3133,10 +3134,10 @@ pmap_emulate_reference(struct lwp *l, va
        mutex_enter(lock);
 
        if (type == ALPHA_MMCSR_FOW) {
-               md->pvh_attrs |= (PGA_REFERENCED|PGA_MODIFIED);
+               md->pvh_listx |= (PGA_REFERENCED|PGA_MODIFIED);
                faultoff = PG_FOR | PG_FOW;
        } else {
-               md->pvh_attrs |= PGA_REFERENCED;
+               md->pvh_listx |= PGA_REFERENCED;
                faultoff = PG_FOR;
                if (exec) {
                        faultoff |= PG_FOE;
@@ -3173,7 +3174,7 @@ pmap_pv_dump(paddr_t pa)
        lock = pmap_pvh_lock(pg);
        mutex_enter(lock);
 
-       printf("pa 0x%lx (attrs = 0x%x):\n", pa, md->pvh_attrs);
+       printf("pa 0x%lx (attrs = 0x%x):\n", pa, md->pvh_listx & PGA_ATTRS);
        for (pv = VM_MDPAGE_PVS(pg); pv != NULL; pv = pv->pv_next)
                printf("     pmap %p, va 0x%lx\n",
                    pv->pv_pmap, pv->pv_va);
@@ -3274,8 +3275,9 @@ pmap_pv_enter(pmap_t pmap, struct vm_pag
        /*
         * ...and put it in the list.
         */
-       newpv->pv_next = md->pvh_list;
-       md->pvh_list = newpv;
+       uintptr_t const attrs = md->pvh_listx & PGA_ATTRS;
+       newpv->pv_next = (struct pv_entry *)(md->pvh_listx & ~PGA_ATTRS);
+       md->pvh_listx = (uintptr_t)newpv | attrs;
 
        if (dolock) {
                mutex_exit(lock);
@@ -3307,14 +3309,15 @@ pmap_pv_remove(pmap_t pmap, struct vm_pa
        /*
         * Find the entry to remove.
         */
-       for (pvp = &md->pvh_list, pv = *pvp;
+       for (pvp = (struct pv_entry **)&md->pvh_listx, pv = VM_MDPAGE_PVS(pg);
             pv != NULL; pvp = &pv->pv_next, pv = *pvp)
                if (pmap == pv->pv_pmap && va == pv->pv_va)
                        break;
 
        KASSERT(pv != NULL);
 
-       *pvp = pv->pv_next;
+       *pvp = (pv_entry_t)((uintptr_t)pv->pv_next |
+                           (((uintptr_t)*pvp) & PGA_ATTRS));
 
        if (dolock) {
                mutex_exit(lock);
diff -r 53015e07c7a7 -r 353720775980 sys/arch/alpha/include/pmap.h
--- a/sys/arch/alpha/include/pmap.h     Sun May 30 06:05:24 2021 +0000
+++ b/sys/arch/alpha/include/pmap.h     Sun May 30 06:41:19 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.92 2021/05/30 05:26:09 thorpej Exp $ */
+/* $NetBSD: pmap.h,v 1.93 2021/05/30 06:41:19 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -177,9 +177,10 @@ typedef struct pv_entry {
        pt_entry_t      *pv_pte;        /* PTE that maps the VA */
 } *pv_entry_t;
 
-/* pvh_attrs */
-#define        PGA_MODIFIED            0x01            /* modified */
-#define        PGA_REFERENCED          0x02            /* referenced */
+/* attrs in pvh_listx */
+#define        PGA_MODIFIED            0x01UL          /* modified */
+#define        PGA_REFERENCED          0x02UL          /* referenced */
+#define        PGA_ATTRS               (PGA_MODIFIED | PGA_REFERENCED)
 
 /* pvh_usage */
 #define        PGU_NORMAL              0               /* free or normal use */
@@ -214,9 +215,9 @@ pmap_remove_all(struct pmap *pmap)
 }
 
 #define        pmap_is_referenced(pg)                                          \
-       (((pg)->mdpage.pvh_attrs & PGA_REFERENCED) != 0)
+       (((pg)->mdpage.pvh_listx & PGA_REFERENCED) != 0)
 #define        pmap_is_modified(pg)                                            \
-       (((pg)->mdpage.pvh_attrs & PGA_MODIFIED) != 0)
+       (((pg)->mdpage.pvh_listx & PGA_MODIFIED) != 0)
 
 #define        PMAP_STEAL_MEMORY               /* enable pmap_steal_memory() */
 #define        PMAP_GROWKERNEL                 /* enable pmap_growkernel() */
@@ -359,17 +360,15 @@ do {                                                                      \
  */
 #define        __HAVE_VM_PAGE_MD
 struct vm_page_md {
-       struct pv_entry *pvh_list;              /* pv_entry list */
-       int pvh_attrs;                          /* page attributes */
+       uintptr_t pvh_listx;                    /* pv_entry list + attrs */
 };
 
 #define        VM_MDPAGE_PVS(pg)                                               \
-       ((pg)->mdpage.pvh_list)
+       ((struct pv_entry *)((pg)->mdpage.pvh_listx & ~3UL))
 
 #define        VM_MDPAGE_INIT(pg)                                              \
 do {                                                                   \
-       (pg)->mdpage.pvh_list = NULL;                                   \
-       (pg)->mdpage.pvh_attrs = 0;                                     \
+       (pg)->mdpage.pvh_listx = 0UL;                                   \
 } while (/*CONSTCOND*/0)
 
 #endif /* _KERNEL */



Home | Main Index | Thread Index | Old Index