Subject: None
To: None <deraadt@sun-lamp.cs.berkeley.edu, port-sparc@sun-lamp.cs.berkeley.edu>
From: Charles Hannum <mycroft@NetBSD.ORG>
List: port-sparc
Date: 10/24/1994 00:28:23
The following fixes the highly bogus RSS calculation in the SPARC
pmap.c.  There are numerous other ways to do it, but this has the least
impact on performance, except when the value is actually needed.

Note that the stupid #define is actually needed at the moment, due at
least one misguided `#ifdef pmap_resident_count'.

Also, I removed a completely bogus use of PG_W.  On the SPARC it means
`writeable', not `wired', so it's totally inappropriate to use for
counting wired pages.  To keep an accurate wired count in
pmap_page_protect(), you need to either steal an unused PTE bit, or
save the flag in the pvlist entry.  (In the latter case, you have to
also be careful to only increase the wired count for managed pages, but
that should be fine, maybe even desirable.)

===================================================================
RCS file: /b/source/CVS/src/sys/arch/sparc/include/pmap.h,v
retrieving revision 1.5.2.1
diff -c -2 -r1.5.2.1 pmap.h
*** 1.5.2.1	1994/08/17 06:19:34
--- pmap.h	1994/10/24 05:44:37
***************
*** 171,177 ****
  void	pmap_bootstrap __P((int nmmu, int nctx));
  void	pmap_init __P((vm_offset_t phys_start, vm_offset_t phys_end));
! #endif /* KERNEL */
  
! #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
  
  #endif /* _SPARC_PMAP_H_ */
--- 171,179 ----
  void	pmap_bootstrap __P((int nmmu, int nctx));
  void	pmap_init __P((vm_offset_t phys_start, vm_offset_t phys_end));
! int	pmap_count_ptes __P((struct pmap *));
! 
! #define	pmap_resident_count(pmap)	pmap_count_ptes(pmap)
  
! #endif /* KERNEL */
  
  #endif /* _SPARC_PMAP_H_ */
===================================================================
RCS file: /b/source/CVS/src/sys/arch/sparc/sparc/pmap.c,v
retrieving revision 1.13.2.2
diff -c -2 -r1.13.2.2 pmap.c
*** 1.13.2.2	1994/10/24 04:22:06
--- pmap.c	1994/10/24 06:21:42
***************
*** 1820,1829 ****
  			if ((tpte & PG_TYPE) == PG_OBMEM) {
  				i = ptoa(HWTOSW(tpte & PG_PFNUM));
! 				if (managed(i)) {
! 					if (tpte & PG_W)
! 						pm->pm_stats.wired_count--;
! 					pm->pm_stats.resident_count--;
  					pv_unlink(pvhead(i), pm, va);
- 				}
  			}
  			nleft--;
--- 1820,1825 ----
  			if ((tpte & PG_TYPE) == PG_OBMEM) {
  				i = ptoa(HWTOSW(tpte & PG_PFNUM));
! 				if (managed(i))
  					pv_unlink(pvhead(i), pm, va);
  			}
  			nleft--;
***************
*** 2485,2489 ****
  			 * Increment counters
  			 */
- 			pm->pm_stats.resident_count++;
  			if (wired)
  				pm->pm_stats.wired_count++;
--- 2481,2484 ----
***************
*** 2859,2861 ****
--- 2854,2872 ----
  	pmap_enter(pm, va, pa, prot, wired);
  	return (0);
+ }
+ 
+ int
+ pmap_count_ptes(pm)
+ 	register struct pmap *pm;
+ {
+ 	register int idx, total;
+ 
+ 	if (pm == kernel_pmap)
+ 		idx = NKSEG;
+ 	else
+ 		idx = NUSEG;
+ 	for (total = 0; idx;)
+ 		total += pm->pm_npte[--idx];
+ 	pm->pm_stats.resident_count = total;
+ 	return (total);
  }