From ca9c73b22ec4ee19100446d9f898c58690fa5974 Mon Sep 17 00:00:00 2001 From: miod Date: Mon, 12 Sep 2022 19:33:34 +0000 Subject: [PATCH] Store mod/ref flags using md pg_flags values rather than a specific field in vm_page_md, which allows this struct to shrink a bit. --- sys/arch/sh/include/pmap.h | 8 +++----- sys/arch/sh/sh/pmap.c | 34 +++++++++++++++------------------- sys/arch/sh/sh/trap.c | 8 ++++---- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/sys/arch/sh/include/pmap.h b/sys/arch/sh/include/pmap.h index dff64bce05c..3314586c3a2 100644 --- a/sys/arch/sh/include/pmap.h +++ b/sys/arch/sh/include/pmap.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap.h,v 1.15 2022/09/10 20:35:29 miod Exp $ */ +/* $OpenBSD: pmap.h,v 1.16 2022/09/12 19:33:34 miod Exp $ */ /* $NetBSD: pmap.h,v 1.28 2006/04/10 23:12:11 uwe Exp $ */ /*- @@ -101,21 +101,19 @@ boolean_t __pmap_pte_load(pmap_t, vaddr_t, int); #endif /* !_KERNEL */ -#define PVH_REFERENCED 1 -#define PVH_MODIFIED 2 +#define PG_PMAP_REF PG_PMAP0 +#define PG_PMAP_MOD PG_PMAP1 #ifndef _LOCORE struct pv_entry; struct vm_page_md { SLIST_HEAD(, pv_entry) pvh_head; - int pvh_flags; }; #define VM_MDPAGE_INIT(pg) \ do { \ struct vm_page_md *pvh = &(pg)->mdpage; \ SLIST_INIT(&pvh->pvh_head); \ - pvh->pvh_flags = 0; \ } while (/*CONSTCOND*/0) #endif /* _LOCORE */ diff --git a/sys/arch/sh/sh/pmap.c b/sys/arch/sh/sh/pmap.c index ccb17ec6b3e..fa55f6ccfd2 100644 --- a/sys/arch/sh/sh/pmap.c +++ b/sys/arch/sh/sh/pmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap.c,v 1.28 2016/10/19 08:28:20 guenther Exp $ */ +/* $OpenBSD: pmap.c,v 1.29 2022/09/12 19:33:34 miod Exp $ */ /* $NetBSD: pmap.c,v 1.55 2006/08/07 23:19:36 tsutsui Exp $ */ /*- @@ -291,7 +291,6 @@ int pmap_enter(pmap_t pmap, vaddr_t va, paddr_t pa, vm_prot_t prot, int flags) { struct vm_page *pg; - struct vm_page_md *pvh; pt_entry_t entry, *pte; boolean_t kva = (pmap == pmap_kernel()); @@ -304,20 +303,20 @@ pmap_enter(pmap_t pmap, vaddr_t va, paddr_t pa, vm_prot_t prot, int flags) entry |= _PG_WIRED; if (pg != NULL) { /* memory-space */ - pvh = &pg->mdpage; entry |= PG_C; /* always cached */ /* Modified/reference tracking */ if (flags & PROT_WRITE) { entry |= PG_V | PG_D; - pvh->pvh_flags |= PVH_MODIFIED | PVH_REFERENCED; + atomic_setbits_int(&pg->pg_flags, + PG_PMAP_MOD | PG_PMAP_REF); } else if (flags & PROT_MASK) { entry |= PG_V; - pvh->pvh_flags |= PVH_REFERENCED; + atomic_setbits_int(&pg->pg_flags, PG_PMAP_REF); } /* Protection */ - if ((prot & PROT_WRITE) && (pvh->pvh_flags & PVH_MODIFIED)) { + if ((prot & PROT_WRITE) && (pg->pg_flags & PG_PMAP_MOD)) { if (kva) entry |= PG_PR_KRW | PG_SH; else @@ -526,7 +525,7 @@ __pmap_pv_remove(pmap_t pmap, struct vm_page *pg, vaddr_t vaddr) if (pv->pv_pmap == pmap && pv->pv_va == vaddr) { if (SH_HAS_VIRTUAL_ALIAS || (SH_HAS_WRITEBACK_CACHE && - (pg->mdpage.pvh_flags & PVH_MODIFIED))) { + (pg->pg_flags & PG_PMAP_MOD))) { /* * Always use index ops. since I don't want to * worry about address space. @@ -798,7 +797,7 @@ pmap_copy_page(vm_page_t srcpg, vm_page_t dstpg) boolean_t pmap_is_referenced(struct vm_page *pg) { - return ((pg->mdpage.pvh_flags & PVH_REFERENCED) ? TRUE : FALSE); + return ((pg->pg_flags & PG_PMAP_REF) ? TRUE : FALSE); } boolean_t @@ -811,10 +810,10 @@ pmap_clear_reference(struct vm_page *pg) vaddr_t va; int s; - if ((pg->mdpage.pvh_flags & PVH_REFERENCED) == 0) + if ((pg->pg_flags & PG_PMAP_REF) == 0) return (FALSE); - pg->mdpage.pvh_flags &= ~PVH_REFERENCED; + atomic_clearbits_int(&pg->pg_flags, PG_PMAP_REF); s = splvm(); /* Restart reference bit emulation */ @@ -839,7 +838,7 @@ pmap_clear_reference(struct vm_page *pg) boolean_t pmap_is_modified(struct vm_page *pg) { - return ((pg->mdpage.pvh_flags & PVH_MODIFIED) ? TRUE : FALSE); + return ((pg->pg_flags & PG_PMAP_MOD) ? TRUE : FALSE); } boolean_t @@ -853,11 +852,11 @@ pmap_clear_modify(struct vm_page *pg) vaddr_t va; int s; - modified = pvh->pvh_flags & PVH_MODIFIED; + modified = pg->pg_flags & PG_PMAP_MOD; if (!modified) return (FALSE); - pvh->pvh_flags &= ~PVH_MODIFIED; + atomic_clearbits_int(&pg->pg_flags, PG_PMAP_MOD); s = splvm(); if (SLIST_EMPTY(&pvh->pvh_head)) {/* no map on this page */ @@ -1041,14 +1040,11 @@ __pmap_pte_load(pmap_t pmap, vaddr_t va, int flags) /* Emulate reference/modified tracking for managed page. */ if (flags != 0 && (pg = PHYS_TO_VM_PAGE(entry & PG_PPN)) != NULL) { - if (flags & PVH_REFERENCED) { - pg->mdpage.pvh_flags |= PVH_REFERENCED; + if (flags & PG_PMAP_REF) entry |= PG_V; - } - if (flags & PVH_MODIFIED) { - pg->mdpage.pvh_flags |= PVH_MODIFIED; + if (flags & PG_PMAP_MOD) entry |= PG_D; - } + atomic_setbits_int(&pg->pg_flags, flags); *pte = entry; } diff --git a/sys/arch/sh/sh/trap.c b/sys/arch/sh/sh/trap.c index ce345d3fc9f..7284e6a9155 100644 --- a/sys/arch/sh/sh/trap.c +++ b/sys/arch/sh/sh/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.50 2021/12/23 18:50:32 guenther Exp $ */ +/* $OpenBSD: trap.c,v 1.51 2022/09/12 19:33:34 miod Exp $ */ /* $NetBSD: exception.c,v 1.32 2006/09/04 23:57:52 uwe Exp $ */ /* $NetBSD: syscall.c,v 1.6 2006/03/07 07:21:50 thorpej Exp $ */ @@ -347,15 +347,15 @@ tlb_exception(struct proc *p, struct trapframe *tf, uint32_t va) switch (tf->tf_expevt) { case EXPEVT_TLB_MISS_LD: - track = PVH_REFERENCED; + track = PG_PMAP_REF; access_type = PROT_READ; break; case EXPEVT_TLB_MISS_ST: - track = PVH_REFERENCED; + track = PG_PMAP_REF; access_type = PROT_WRITE; break; case EXPEVT_TLB_MOD: - track = PVH_REFERENCED | PVH_MODIFIED; + track = PG_PMAP_REF | PG_PMAP_MOD; access_type = PROT_WRITE; break; case EXPEVT_TLB_PROT_LD: -- 2.20.1