Module Name:    src
Committed By:   thorpej
Date:           Mon May 31 17:16:05 UTC 2021

Modified Files:
        src/sys/arch/alpha/alpha: pmap.c
        src/sys/arch/alpha/include: pmap.h

Log Message:
After a comment by joerg@, go back to using a dedicated field for the
PT page reference count, but add an XXX comment stating the desire to
find a safely-unused field in the vm_page structure when pages are in-
use as PT pages, so that we can save the 8 bytes per page needed for
this.


To generate a diff of this commit:
cvs rdiff -u -r1.292 -r1.293 src/sys/arch/alpha/alpha/pmap.c
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/alpha/include/pmap.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/alpha/alpha/pmap.c
diff -u src/sys/arch/alpha/alpha/pmap.c:1.292 src/sys/arch/alpha/alpha/pmap.c:1.293
--- src/sys/arch/alpha/alpha/pmap.c:1.292	Sun May 30 19:50:23 2021
+++ src/sys/arch/alpha/alpha/pmap.c	Mon May 31 17:16:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.292 2021/05/30 19:50:23 thorpej Exp $ */
+/* $NetBSD: pmap.c,v 1.293 2021/05/31 17:16:04 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.292 2021/05/30 19:50:23 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.293 2021/05/31 17:16:04 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -507,8 +507,8 @@ pmap_pagelist_free(struct pmap_pagelist 
 
 	while ((pg = LIST_FIRST(list)) != NULL) {
 		LIST_REMOVE(pg, pageq.list);
-		/* Zap any fields we used internally. */
-		atomic_store_relaxed(&pg->loan_count, 0);
+		/* Fix up ref count; it's not always 0 when we get here. */
+		PHYSPAGE_REFCNT_SET(pg, 0);
 		uvm_pagefree(pg);
 	}
 }
@@ -1893,7 +1893,7 @@ pmap_remove_all(pmap_t pmap)
 
 	/* Fix up the reference count on the lev1map page. */
 	pg = PHYS_TO_VM_PAGE(ALPHA_K0SEG_TO_PHYS((vaddr_t)lev1map));
-	atomic_store_relaxed(&pg->loan_count, 0);
+	PHYSPAGE_REFCNT_SET(pg, 0);
 
 	/* Step 3 */
 	while ((pv = LIST_FIRST(&pmap->pm_pvents)) != NULL) {
@@ -3470,15 +3470,6 @@ pmap_pv_page_free(struct pool *pp, void 
 /******************** misc. functions ********************/
 
 /*
- * Pages that are in-use as page table pages should never be part
- * of a UVM loan, so we'll use that field for our PT page reference
- * count.
- */
-#define	PHYSPAGE_REFCNT(pg)	atomic_load_relaxed(&(pg)->loan_count)
-#define	PHYSPAGE_REFCNT_INC(pg)	atomic_inc_uint_nv(&(pg)->loan_count)
-#define	PHYSPAGE_REFCNT_DEC(pg)	atomic_dec_uint_nv(&(pg)->loan_count)
-
-/*
  * pmap_physpage_alloc:
  *
  *	Allocate a single page from the VM system and return the

Index: src/sys/arch/alpha/include/pmap.h
diff -u src/sys/arch/alpha/include/pmap.h:1.96 src/sys/arch/alpha/include/pmap.h:1.97
--- src/sys/arch/alpha/include/pmap.h:1.96	Sun May 30 19:41:59 2021
+++ src/sys/arch/alpha/include/pmap.h	Mon May 31 17:16:05 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.96 2021/05/30 19:41:59 thorpej Exp $ */
+/* $NetBSD: pmap.h,v 1.97 2021/05/31 17:16:05 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -355,9 +355,26 @@ do {									\
  */
 #define	__HAVE_VM_PAGE_MD
 struct vm_page_md {
-	uintptr_t pvh_listx;			/* pv_entry list + attrs */
+	uintptr_t pvh_listx;		/* pv_entry list + attrs */
+	/*
+	 * XXX These fields are only needed for pages that are used
+	 * as PT pages.  It would be nice to find safely-unused fields
+	 * in the vm_page structure that could be used instead.
+	 */
+	unsigned int pvh_physpgrefs;	/* # refs as a PT page */
+	unsigned int pvh_spare0;	/* XXX spare field */
 };
 
+/* Reference counting for page table pages. */
+#define	PHYSPAGE_REFCNT(pg)						\
+	atomic_load_relaxed(&(pg)->mdpage.pvh_physpgrefs)
+#define	PHYSPAGE_REFCNT_SET(pg, v)					\
+	atomic_store_relaxed(&(pg)->mdpage.pvh_physpgrefs, (v))
+#define	PHYSPAGE_REFCNT_INC(pg)						\
+	atomic_inc_uint_nv(&(pg)->mdpage.pvh_physpgrefs)
+#define	PHYSPAGE_REFCNT_DEC(pg)						\
+	atomic_dec_uint_nv(&(pg)->mdpage.pvh_physpgrefs)
+
 #define	VM_MDPAGE_PVS(pg)						\
 	((struct pv_entry *)((pg)->mdpage.pvh_listx & ~3UL))
 

Reply via email to