11541Srgrimes/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 2914506Shsu * @(#)vmmeter.h 8.2 (Berkeley) 7/10/94 3050477Speter * $FreeBSD: stable/10/sys/sys/vmmeter.h 330047 2018-02-27 01:28:19Z jhb $ 311541Srgrimes */ 321541Srgrimes 332165Spaul#ifndef _SYS_VMMETER_H_ 342165Spaul#define _SYS_VMMETER_H_ 352165Spaul 361541Srgrimes/* 37217192Skib * This value is used by ps(1) to change sleep state flag from 'S' to 38217192Skib * 'I' and by the sched process to set the alarm clock. 39217192Skib */ 40217192Skib#define MAXSLP 20 41217192Skib 42217192Skib/* 431541Srgrimes * System wide statistics counters. 44170517Sattilio * Locking: 45170517Sattilio * a - locked by atomic operations 46170517Sattilio * c - constant after initialization 47170517Sattilio * f - locked by vm_page_queue_free_mtx 48170517Sattilio * p - locked by being in the PCPU and atomicity respect to interrupts 49242941Salc * q - changes are synchronized by the corresponding vm_pagequeue lock 501541Srgrimes */ 511541Srgrimesstruct vmmeter { 521541Srgrimes /* 531541Srgrimes * General system activity. 541541Srgrimes */ 55170517Sattilio u_int v_swtch; /* (p) context switches */ 56170517Sattilio u_int v_trap; /* (p) calls to trap */ 57170517Sattilio u_int v_syscall; /* (p) calls to syscall() */ 58170517Sattilio u_int v_intr; /* (p) device interrupts */ 59170517Sattilio u_int v_soft; /* (p) software interrupts */ 601541Srgrimes /* 611541Srgrimes * Virtual memory activity. 621541Srgrimes */ 63170517Sattilio u_int v_vm_faults; /* (p) address memory faults */ 64246032Szont u_int v_io_faults; /* (p) page faults requiring I/O */ 65170517Sattilio u_int v_cow_faults; /* (p) copy-on-writes faults */ 66170517Sattilio u_int v_cow_optim; /* (p) optimized copy-on-writes faults */ 67170517Sattilio u_int v_zfod; /* (p) pages zero filled on demand */ 68170517Sattilio u_int v_ozfod; /* (p) optimized zero fill pages */ 69170517Sattilio u_int v_swapin; /* (p) swap pager pageins */ 70170517Sattilio u_int v_swapout; /* (p) swap pager pageouts */ 71170517Sattilio u_int v_swappgsin; /* (p) swap pager pages paged in */ 72170517Sattilio u_int v_swappgsout; /* (p) swap pager pages paged out */ 73170517Sattilio u_int v_vnodein; /* (p) vnode pager pageins */ 74170517Sattilio u_int v_vnodeout; /* (p) vnode pager pageouts */ 75170517Sattilio u_int v_vnodepgsin; /* (p) vnode_pager pages paged in */ 76170517Sattilio u_int v_vnodepgsout; /* (p) vnode pager pages paged out */ 77170517Sattilio u_int v_intrans; /* (p) intransit blocking page faults */ 78172317Salc u_int v_reactivated; /* (f) pages reactivated from free list */ 79170517Sattilio u_int v_pdwakeups; /* (f) times daemon has awaken from sleep */ 80242941Salc u_int v_pdpages; /* (p) pages analyzed by daemon */ 8114506Shsu 82207796Salc u_int v_tcached; /* (p) total pages cached */ 83238212Skib u_int v_dfree; /* (p) pages freed by daemon */ 84207739Salc u_int v_pfree; /* (p) pages freed by exiting processes */ 85170517Sattilio u_int v_tfree; /* (p) total pages freed */ 861541Srgrimes /* 871541Srgrimes * Distribution of page usages. 881541Srgrimes */ 89170517Sattilio u_int v_page_size; /* (c) page size in bytes */ 90170517Sattilio u_int v_page_count; /* (c) total number of pages in system */ 91170517Sattilio u_int v_free_reserved; /* (c) pages reserved for deadlock */ 92170517Sattilio u_int v_free_target; /* (c) pages desired free */ 93170517Sattilio u_int v_free_min; /* (c) pages desired free */ 94170517Sattilio u_int v_free_count; /* (f) pages free */ 95170517Sattilio u_int v_wire_count; /* (a) pages wired down */ 96170517Sattilio u_int v_active_count; /* (q) pages active */ 97170517Sattilio u_int v_inactive_target; /* (c) pages desired inactive */ 98170517Sattilio u_int v_inactive_count; /* (q) pages inactive */ 99180622Salc u_int v_cache_count; /* (f) pages on cache queue */ 100170517Sattilio u_int v_cache_min; /* (c) min pages desired on cache queue */ 101254304Sjeff u_int v_cache_max; /* (c) max pages in cached obj (unused) */ 102170517Sattilio u_int v_pageout_free_min; /* (c) min pages reserved for kernel */ 103170517Sattilio u_int v_interrupt_free_min; /* (c) reserved pages for int code */ 104170517Sattilio u_int v_free_severe; /* (c) severe page depletion point */ 10571429Sume /* 10671429Sume * Fork/vfork/rfork activity. 10771429Sume */ 108170517Sattilio u_int v_forks; /* (p) fork() calls */ 109170517Sattilio u_int v_vforks; /* (p) vfork() calls */ 110170517Sattilio u_int v_rforks; /* (p) rfork() calls */ 111170517Sattilio u_int v_kthreads; /* (p) fork() calls by kernel */ 112170517Sattilio u_int v_forkpages; /* (p) VM pages affected by fork() */ 113170517Sattilio u_int v_vforkpages; /* (p) VM pages affected by vfork() */ 114170517Sattilio u_int v_rforkpages; /* (p) VM pages affected by rfork() */ 115170517Sattilio u_int v_kthreadpages; /* (p) VM pages affected by fork() by kernel */ 1161541Srgrimes}; 11755205Speter#ifdef _KERNEL 11851337Sdillon 119170170Sattilioextern struct vmmeter cnt; 12051337Sdillon 121254304Sjeffextern int vm_pageout_wakeup_thresh; 122254304Sjeff 12351337Sdillon/* 12451337Sdillon * Return TRUE if we are under our severe low-free-pages threshold 12551337Sdillon * 12651337Sdillon * This routine is typically used at the user<->system interface to determine 12751337Sdillon * whether we need to block in order to avoid a low memory deadlock. 12851337Sdillon */ 12951337Sdillon 13051337Sdillonstatic __inline 13151337Sdillonint 13251337Sdillonvm_page_count_severe(void) 13351337Sdillon{ 134170170Sattilio return (cnt.v_free_severe > (cnt.v_free_count + cnt.v_cache_count)); 13551337Sdillon} 13651337Sdillon 13751337Sdillon/* 13851337Sdillon * Return TRUE if we are under our minimum low-free-pages threshold. 13951337Sdillon * 14051337Sdillon * This routine is typically used within the system to determine whether 14151337Sdillon * we can execute potentially very expensive code in terms of memory. It 14251337Sdillon * is also used by the pageout daemon to calculate when to sleep, when 14351337Sdillon * to wake waiters up, and when (after making a pass) to become more 14451337Sdillon * desparate. 14551337Sdillon */ 14651337Sdillon 14751337Sdillonstatic __inline 14851337Sdillonint 14951337Sdillonvm_page_count_min(void) 15051337Sdillon{ 151170170Sattilio return (cnt.v_free_min > (cnt.v_free_count + cnt.v_cache_count)); 15251337Sdillon} 15351337Sdillon 15451337Sdillon/* 15551337Sdillon * Return TRUE if we have not reached our free page target during 15651337Sdillon * free page recovery operations. 15751337Sdillon */ 15851337Sdillon 15951337Sdillonstatic __inline 16051337Sdillonint 16151337Sdillonvm_page_count_target(void) 16251337Sdillon{ 163170170Sattilio return (cnt.v_free_target > (cnt.v_free_count + cnt.v_cache_count)); 16451337Sdillon} 16551337Sdillon 16651337Sdillon/* 16751337Sdillon * Return the number of pages we need to free-up or cache 16851337Sdillon * A positive number indicates that we do not have enough free pages. 16951337Sdillon */ 17051337Sdillon 17151337Sdillonstatic __inline 17251337Sdillonint 17351337Sdillonvm_paging_target(void) 17451337Sdillon{ 175254304Sjeff return (cnt.v_free_target - (cnt.v_free_count + cnt.v_cache_count)); 17651337Sdillon} 17751337Sdillon 17851337Sdillon/* 179110225Salc * Returns TRUE if the pagedaemon needs to be woken up. 18051337Sdillon */ 18151337Sdillon 18251337Sdillonstatic __inline 18351337Sdillonint 18451337Sdillonvm_paging_needed(void) 18551337Sdillon{ 186301833Sngie return (cnt.v_free_count + cnt.v_cache_count < 187301833Sngie (u_int)vm_pageout_wakeup_thresh); 18851337Sdillon} 18951337Sdillon 1901541Srgrimes#endif 1911541Srgrimes 19297691Sbsdstruct vmtotal { 193164718Sru int16_t t_rq; /* length of the run queue */ 194330047Sjhb int16_t t_dw; /* threads in ``disk wait'' (neg priority) */ 195330047Sjhb int16_t t_pw; /* threads in page wait */ 196330047Sjhb int16_t t_sl; /* threads sleeping in core */ 197330047Sjhb int16_t t_sw; /* swapped out runnable/short block threads */ 198164718Sru int32_t t_vm; /* total virtual memory */ 199164718Sru int32_t t_avm; /* active virtual memory */ 200164718Sru int32_t t_rm; /* total real memory in use */ 201164718Sru int32_t t_arm; /* active real memory */ 202164718Sru int32_t t_vmshr; /* shared virtual memory */ 203164718Sru int32_t t_avmshr; /* active shared virtual memory */ 204164718Sru int32_t t_rmshr; /* shared real memory */ 205164718Sru int32_t t_armshr; /* active shared real memory */ 206164718Sru int32_t t_free; /* free memory pages */ 2071541Srgrimes}; 2081541Srgrimes 2091541Srgrimes#endif 210