| 1 | /*	$OpenBSD: uvmexp.h,v 1.27 2026/03/08 17:06:10 deraadt Exp $	*/ |
| 2 | |
| 3 | #ifndef	_UVM_UVMEXP_ |
| 4 | #define	_UVM_UVMEXP_ |
| 5 | |
| 6 | /* |
| 7 | * CTL_VM identifiers |
| 8 | */ |
| 9 | #define	VM_METER	1		/* struct vmmeter */ |
| 10 | #define	VM_LOADAVG	2		/* struct loadavg */ |
| 11 | #define	VM_PSSTRINGS	3		/* PSSTRINGS */ |
| 12 | #define VM_UVMEXP	4		/* struct uvmexp */ |
| 13 | #define VM_SWAPENCRYPT	5		/* int */ |
| 14 | #define VM_NKMEMPAGES	6		/* int - # kmem_map pages */ |
| 15 | #define	VM_ANONMIN	7 |
| 16 | #define	VM_VTEXTMIN	8 |
| 17 | #define	VM_VNODEMIN	9 |
| 18 | #define	VM_MAXSLP	10 |
| 19 | #define	VM_USPACE	11 |
| 20 | #define	VM_MALLOC_CONF	12		/* config for userland malloc */ |
| 21 | #define	VM_MAXID	13		/* number of valid vm ids */ |
| 22 | |
| 23 | #define	CTL_VM_NAMES { \ |
| 24 | 	{ 0, 0 }, \ |
| 25 | 	{ "vmmeter", CTLTYPE_STRUCT }, \ |
| 26 | 	{ "loadavg", CTLTYPE_STRUCT }, \ |
| 27 | 	{ "psstrings", CTLTYPE_STRUCT }, \ |
| 28 | 	{ "uvmexp", CTLTYPE_STRUCT }, \ |
| 29 | 	{ "swapencrypt", CTLTYPE_NODE }, \ |
| 30 | 	{ "nkmempages", CTLTYPE_INT }, \ |
| 31 | 	{ "anonmin", CTLTYPE_INT }, \ |
| 32 | 	{ "vtextmin", CTLTYPE_INT }, \ |
| 33 | 	{ "vnodemin", CTLTYPE_INT }, \ |
| 34 | 	{ "maxslp", CTLTYPE_INT }, \ |
| 35 | 	{ "uspace", CTLTYPE_INT }, \ |
| 36 | 	{ "malloc_conf", CTLTYPE_STRING }, \ |
| 37 | } |
| 38 | |
| 39 | /* |
| 40 | * uvmexp: global data structures that are exported to parts of the kernel |
| 41 | * other than the vm system. |
| 42 | * |
| 43 | * Locks used to protect struct members in this file: |
| 44 | *	a	atomic operations (signed int, so use atomic_load_sint) |
| 45 | *	I	immutable after creation |
| 46 | *	K	kernel lock |
| 47 | *	F	uvm_lock_fpageq |
| 48 | *	L	uvm_lock_pageq |
| 49 | *	S	uvm_swap_data_lock |
| 50 | *	p	copy of per-CPU counters, used only by userland. |
| 51 | *	o	updated only by the page daemon |
| 52 | */ |
| 53 | struct uvmexp { |
| 54 | 	/* vm_page constants */ |
| 55 | 	int pagesize; /* size of a page (PAGE_SIZE): must be power of 2 */ |
| 56 | 	int pagemask; /* page mask */ |
| 57 | 	int pageshift; /* page shift */ |
| 58 | |
| 59 | 	/* vm_page counters */ |
| 60 | 	int npages; /* [I] number of pages we manage */ |
| 61 | 	int free; /* [aF] number of free pages */ |
| 62 | 	int active; /* [aL] # of active pages */ |
| 63 | 	int inactive; /* [aL] # of pages that we free'd but may want back */ |
| 64 | 	int paging;	/* [a] # number of pages in the process of being paged out */ |
| 65 | 	int wired; /* [a] # number of wired pages */ |
| 66 | |
| 67 | 	int zeropages;		/* [aF] number of zero'd pages */ |
| 68 | 	int reserve_pagedaemon; /* [I] # of pages reserved for pagedaemon */ |
| 69 | 	int reserve_kernel;	/* [I] # of pages reserved for kernel */ |
| 70 | 	int percpucaches;	/* [a] # of pages in per-CPU caches */ |
| 71 | 	int vnodepages;		/* XXX # of pages used by vnode page cache */ |
| 72 | 	int vtextpages;		/* XXX # of pages used by vtext vnodes */ |
| 73 | |
| 74 | 	/* pageout params */ |
| 75 | 	int freemin; /* [I] min number of free pages */ |
| 76 | 	int freetarg; /* [I] target number of free pages */ |
| 77 | 	int inactarg; /* target number of inactive pages */ |
| 78 | 	int wiredmax; /* [I] max number of wired pages */ |
| 79 | 	int anonmin;	/* min threshold for anon pages */ |
| 80 | 	int vtextmin;	/* min threshold for vtext pages */ |
| 81 | 	int vnodemin;	/* min threshold for vnode pages */ |
| 82 | 	int anonminpct;	/* min percent anon pages */ |
| 83 | 	int vtextminpct;/* min percent vtext pages */ |
| 84 | 	int vnodeminpct;/* min percent vnode pages */ |
| 85 | |
| 86 | 	/* swap */ |
| 87 | 	int nswapdev;	/* [aS] number of configured swap devices in system */ |
| 88 | 	int swpages;	/* [aS] number of PAGE_SIZE'ed swap pages */ |
| 89 | 	int swpginuse;	/* [aS] number of swap pages in use */ |
| 90 | 	int swpgonly;	/* [a] number of swap pages in use, not also in RAM */ |
| 91 | 	int nswget;	/* [a] number of swap pages moved from disk to RAM */ |
| 92 | 	int nanon;	/* XXX number total of anon's in system */ |
| 93 | 	int unused05;	/* formerly nanonneeded */ |
| 94 | 	int unused06;	/* formerly nfreeanon */ |
| 95 | |
| 96 | 	/* stat counters */ |
| 97 | 	int faults;		/* [p] page fault count */ |
| 98 | 	int traps;		/* [a] trap count */ |
| 99 | 	int intrs;		/* [a] interrupt count */ |
| 100 | 	int swtch;		/* context switch count */ |
| 101 | 	int softs;		/* [a] software interrupt count */ |
| 102 | 	int syscalls;		/* [a] system calls */ |
| 103 | 	int pageins;		/* [p] pagein operation count */ |
| 104 | 				/* pageouts are in pdpageouts below */ |
| 105 | 	int pcphit;		/* [a] # of pagealloc from per-CPU cache */ |
| 106 | 	int pcpmiss;		/* [a] # of times a per-CPU cache was empty */ |
| 107 | 	int pgswapin;		/* pages swapped in */ |
| 108 | 	int pgswapout;		/* [a] pages swapped out */ |
| 109 | 	int forks; 		/* forks */ |
| 110 | 	int forks_ppwait;	/* forks where parent waits */ |
| 111 | 	int forks_sharevm;	/* forks where vmspace is shared */ |
| 112 | 	int pga_zerohit;	/* [a] pagealloc where zero wanted and zero |
| 113 | 				 was available */ |
| 114 | 	int pga_zeromiss;	/* [a] pagealloc where zero wanted and zero |
| 115 | 				 not available */ |
| 116 | 	int unused09;		/* formerly zeroaborts */ |
| 117 | |
| 118 | 	/* fault subcounters */ |
| 119 | 	int fltnoram;	/* [p] # of times fault was out of ram */ |
| 120 | 	int fltnoanon;	/* [p] # of times fault was out of anons */ |
| 121 | 	int fltnoamap;	/* [p] # of times fault was out of amap chunks */ |
| 122 | 	int fltpgwait;	/* [p] # of times fault had to wait on a page */ |
| 123 | 	int fltpgrele;	/* [p] # of times fault found a released page */ |
| 124 | 	int fltrelck;	/* [p] # of times fault relock is a success */ |
| 125 | 	int fltnorelck;	/* [p] # of times fault relock failed */ |
| 126 | 	int fltanget;	/* [p] # of times fault gets anon page */ |
| 127 | 	int fltanretry;	/* [p] # of times fault retrys an anon get */ |
| 128 | 	int fltamcopy;	/* [p] # of times fault clears "needs copy" */ |
| 129 | 	int fltnamap;	/* [p] # of times fault maps a neighbor anon page */ |
| 130 | 	int fltnomap;	/* [p] # of times fault maps a neighbor obj page */ |
| 131 | 	int fltlget;	/* [p] # of times fault does a locked pgo_get */ |
| 132 | 	int fltget;	/* [p] # of times fault does an unlocked get */ |
| 133 | 	int flt_anon;	/* [p] # of times fault anon (case 1a) */ |
| 134 | 	int flt_acow;	/* [p] # of times fault anon cow (case 1b) */ |
| 135 | 	int flt_obj;	/* [p] # of times fault is on object page (2a) */ |
| 136 | 	int flt_prcopy;	/* [p] # of times fault promotes with copy (2b) */ |
| 137 | 	int flt_przero;	/* [p] # of times fault promotes with zerofill (2b) */ |
| 138 | 	int fltup;	/* [p] # of times fault upgrade is a success */ |
| 139 | 	int fltnoup;	/* [p] # of times fault upgrade failed */ |
| 140 | |
| 141 | 	/* daemon counters */ |
| 142 | 	int pdwoke;	/* [ao] # of times daemon woke up */ |
| 143 | 	int pdrevs;	/* [ao] # of times daemon scanned for free pages */ |
| 144 | 	int pdswout;	/* [o] # of times daemon called for swapout */ |
| 145 | 	int pdfreed;	/* [ao] # of pages daemon freed since boot */ |
| 146 | 	int pdscans;	/* [ao] # of pages daemon scanned since boot */ |
| 147 | 	int pdanscan;	/* [ao] # of anonymous pages scanned by daemon */ |
| 148 | 	int pdobscan;	/* [ao] # of object pages scanned by daemon */ |
| 149 | 	int pdreact;	/* [ao] # of pages daemon reactivated since boot */ |
| 150 | 	int pdbusy;	/* [ao] # of times daemon found a busy page */ |
| 151 | 	int pdpageouts;	/* [ao] # of times daemon started a pageout */ |
| 152 | 	int pdpending;	/* [ao] # of times daemon got a pending pagout */ |
| 153 | 	int pddeact;	/* [ao] # of pages daemon deactivates */ |
| 154 | 	int swpskip;	/* [ao] # of pages delayed because swap crypt busy */ |
| 155 | |
| 156 | 	int fpswtch;	/* [a] FPU context switches */ |
| 157 | 	int kmapent;	/* [a] number of kernel map entries */ |
| 158 | }; |
| 159 | |
| 160 | struct _ps_strings { |
| 161 | 	void	*val; |
| 162 | }; |
| 163 | |
| 164 | #ifdef _KERNEL |
| 165 | |
| 166 | static inline int |
| 167 | atomic_load_sint(volatile const int *p) |
| 168 | { |
| 169 | return *p; |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | * Per-cpu UVM counters. |
| 174 | */ |
| 175 | extern struct cpumem *uvmexp_counters; |
| 176 | |
| 177 | enum uvm_exp_counters { |
| 178 | 	/* stat counters */ |
| 179 | 	faults,		/* page fault count */ |
| 180 | 	pageins,	/* pagein operation count */ |
| 181 | |
| 182 | 	/* fault subcounters */ |
| 183 | 	flt_noram,	/* number of times fault was out of ram */ |
| 184 | 	flt_noanon,	/* number of times fault was out of anons */ |
| 185 | 	flt_noamap,	/* number of times fault was out of amap chunks */ |
| 186 | 	flt_pgwait,	/* number of times fault had to wait on a page */ |
| 187 | 	flt_pgrele,	/* number of times fault found a released page */ |
| 188 | 	flt_relck,	/* number of times fault relock is a success */ |
| 189 | 	flt_norelck,	/* number of times fault relock failed */ |
| 190 | 	flt_anget,	/* number of times fault gets anon page */ |
| 191 | 	flt_anretry,	/* number of times fault retrys an anon get */ |
| 192 | 	flt_amcopy,	/* number of times fault clears "needs copy" */ |
| 193 | 	flt_namap,	/* number of times fault maps a neighbor anon page */ |
| 194 | 	flt_nomap,	/* number of times fault maps a neighbor obj page */ |
| 195 | 	flt_lget,	/* number of times fault does a locked pgo_get */ |
| 196 | 	flt_get,	/* number of times fault does an unlocked get */ |
| 197 | 	flt_anon,	/* number of times fault anon (case 1a) */ |
| 198 | 	flt_acow,	/* number of times fault anon cow (case 1b) */ |
| 199 | 	flt_obj,	/* number of times fault is on object page (2a) */ |
| 200 | 	flt_prcopy,	/* number of times fault promotes with copy (2b) */ |
| 201 | 	flt_przero,	/* number of times fault promotes with zerofill (2b) */ |
| 202 | 	flt_up,		/* number of times fault upgrade is a success */ |
| 203 | 	flt_noup,	/* number of times fault upgrade failed */ |
| 204 | |
| 205 | 	exp_ncounters |
| 206 | }; |
| 207 | |
| 208 | #endif /* _KERNEL */ |
| 209 | #endif /*_UVM_UVMEXP_ */ |