1*748d5a7eSad /* $NetBSD: uvm_stat.c,v 1.46 2020/06/14 21:41:42 ad Exp $ */
2f2caacc7Smrg
3f2caacc7Smrg /*
4f2caacc7Smrg * Copyright (c) 1997 Charles D. Cranor and Washington University.
5f2caacc7Smrg * All rights reserved.
6f2caacc7Smrg *
7f2caacc7Smrg * Redistribution and use in source and binary forms, with or without
8f2caacc7Smrg * modification, are permitted provided that the following conditions
9f2caacc7Smrg * are met:
10f2caacc7Smrg * 1. Redistributions of source code must retain the above copyright
11f2caacc7Smrg * notice, this list of conditions and the following disclaimer.
12f2caacc7Smrg * 2. Redistributions in binary form must reproduce the above copyright
13f2caacc7Smrg * notice, this list of conditions and the following disclaimer in the
14f2caacc7Smrg * documentation and/or other materials provided with the distribution.
15f2caacc7Smrg *
16f2caacc7Smrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17f2caacc7Smrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18f2caacc7Smrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19f2caacc7Smrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20f2caacc7Smrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21f2caacc7Smrg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22f2caacc7Smrg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23f2caacc7Smrg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24f2caacc7Smrg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25f2caacc7Smrg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
261f6b921cSmrg *
271f6b921cSmrg * from: Id: uvm_stat.c,v 1.1.2.3 1997/12/19 15:01:00 mrg Exp
28f2caacc7Smrg */
29f2caacc7Smrg
30f2caacc7Smrg /*
31f2caacc7Smrg * uvm_stat.c
32f2caacc7Smrg */
33f2caacc7Smrg
34b616d1caSlukem #include <sys/cdefs.h>
35*748d5a7eSad __KERNEL_RCSID(0, "$NetBSD: uvm_stat.c,v 1.46 2020/06/14 21:41:42 ad Exp $");
36b616d1caSlukem
3752f0a628Syamt #include "opt_readahead.h"
38b616d1caSlukem #include "opt_ddb.h"
39b616d1caSlukem
40f2caacc7Smrg #include <sys/param.h>
41f2caacc7Smrg #include <sys/systm.h>
426a66466fSmatt #include <sys/cpu.h>
43f2caacc7Smrg
44f2caacc7Smrg #include <uvm/uvm.h>
4555a751c9Schs #include <uvm/uvm_ddb.h>
46f2caacc7Smrg
4755a751c9Schs #ifdef DDB
4855a751c9Schs
49277fd3d5Smrg #include <sys/pool.h>
50277fd3d5Smrg
5190aee42dSthorpej /*
5255a751c9Schs * uvmexp_print: ddb hook to print interesting uvm counters
53f2caacc7Smrg */
54e6c31d3dSthorpej void
uvmexp_print(void (* pr)(const char *,...))557b2a66beSenami uvmexp_print(void (*pr)(const char *, ...)
567b2a66beSenami __attribute__((__format__(__printf__,1,2))))
57f2caacc7Smrg {
58ba90a6baSad int64_t anonpg, execpg, filepg;
599d3e3eabSyamt int active, inactive;
60ba90a6baSad int poolpages, freepg;
619d3e3eabSyamt
629d3e3eabSyamt uvm_estimatepageable(&active, &inactive);
63f77ca713Sskrll poolpages = pool_totalpages_locked();
64e6c31d3dSthorpej
65ba90a6baSad /* this will sync all counters. */
66ba90a6baSad freepg = uvm_availmem(false);
67ba90a6baSad
68ba90a6baSad anonpg = cpu_count_get(CPU_COUNT_ANONCLEAN) +
69ba90a6baSad cpu_count_get(CPU_COUNT_ANONDIRTY) +
70ba90a6baSad cpu_count_get(CPU_COUNT_ANONUNKNOWN);
71ba90a6baSad execpg = cpu_count_get(CPU_COUNT_EXECPAGES);
72ba90a6baSad filepg = cpu_count_get(CPU_COUNT_FILECLEAN) +
73ba90a6baSad cpu_count_get(CPU_COUNT_FILEDIRTY) +
74ba90a6baSad cpu_count_get(CPU_COUNT_FILEUNKNOWN) -
75ba90a6baSad execpg;
76ba90a6baSad
7755a751c9Schs (*pr)("Current UVM status:\n");
7897d74546Smrg (*pr)(" pagesize=%d (0x%x), pagemask=0x%x, pageshift=%d, ncolors=%d\n",
79e6c31d3dSthorpej uvmexp.pagesize, uvmexp.pagesize, uvmexp.pagemask,
80b3322481Smatt uvmexp.pageshift, uvmexp.ncolors);
8155a751c9Schs (*pr)(" %d VM pages: %d active, %d inactive, %d wired, %d free\n",
82ba90a6baSad uvmexp.npages, active, inactive, uvmexp.wired, freepg);
83a98966d3Sad (*pr)(" pages %" PRId64 " anon, %" PRId64 " file, %" PRId64 " exec\n",
84ba90a6baSad anonpg, filepg, execpg);
859d3e3eabSyamt (*pr)(" freemin=%d, free-target=%d, wired-max=%d\n",
869d3e3eabSyamt uvmexp.freemin, uvmexp.freetarg, uvmexp.wiredmax);
87*748d5a7eSad (*pr)(" resv-pg=%d, resv-kernel=%d\n",
88*748d5a7eSad uvmexp.reserve_pagedaemon, uvmexp.reserve_kernel);
89277fd3d5Smrg (*pr)(" bootpages=%d, poolpages=%d\n",
90277fd3d5Smrg uvmexp.bootpages, poolpages);
916a66466fSmatt
92a98966d3Sad (*pr)(" faults=%" PRId64 ", traps=%" PRId64 ", "
93a98966d3Sad "intrs=%" PRId64 ", ctxswitch=%" PRId64 "\n",
94a98966d3Sad cpu_count_get(CPU_COUNT_NFAULT),
95a98966d3Sad cpu_count_get(CPU_COUNT_NTRAP),
96a98966d3Sad cpu_count_get(CPU_COUNT_NINTR),
97a98966d3Sad cpu_count_get(CPU_COUNT_NSWTCH));
98a98966d3Sad (*pr)(" softint=%" PRId64 ", syscalls=%" PRId64 "\n",
99a98966d3Sad cpu_count_get(CPU_COUNT_NSOFT),
100a98966d3Sad cpu_count_get(CPU_COUNT_NSYSCALL));
101e6c31d3dSthorpej
10255a751c9Schs (*pr)(" fault counts:\n");
103a98966d3Sad (*pr)(" noram=%" PRId64 ", noanon=%" PRId64 ", pgwait=%" PRId64
104a98966d3Sad ", pgrele=%" PRId64 "\n",
105a98966d3Sad cpu_count_get(CPU_COUNT_FLTNORAM),
106a98966d3Sad cpu_count_get(CPU_COUNT_FLTNOANON),
107a98966d3Sad cpu_count_get(CPU_COUNT_FLTPGWAIT),
108a98966d3Sad cpu_count_get(CPU_COUNT_FLTPGRELE));
109a98966d3Sad (*pr)(" ok relocks(total)=%" PRId64 "(%" PRId64 "), "
110a98966d3Sad "anget(retrys)=%" PRId64 "(%" PRId64 "), amapcopy=%" PRId64 "\n",
111a98966d3Sad cpu_count_get(CPU_COUNT_FLTRELCKOK),
112a98966d3Sad cpu_count_get(CPU_COUNT_FLTRELCK),
113a98966d3Sad cpu_count_get(CPU_COUNT_FLTANGET),
114a98966d3Sad cpu_count_get(CPU_COUNT_FLTANRETRY),
115a98966d3Sad cpu_count_get(CPU_COUNT_FLTAMCOPY));
116a98966d3Sad (*pr)(" neighbor anon/obj pg=%" PRId64 "/%" PRId64
117a98966d3Sad ", gets(lock/unlock)=%" PRId64 "/%" PRId64 "\n",
118a98966d3Sad cpu_count_get(CPU_COUNT_FLTNAMAP),
119a98966d3Sad cpu_count_get(CPU_COUNT_FLTNOMAP),
120a98966d3Sad cpu_count_get(CPU_COUNT_FLTLGET),
121a98966d3Sad cpu_count_get(CPU_COUNT_FLTGET));
122a98966d3Sad (*pr)(" cases: anon=%" PRId64 ", anoncow=%" PRId64 ", obj=%" PRId64
123a98966d3Sad ", prcopy=%" PRId64 ", przero=%" PRId64 "\n",
124a98966d3Sad cpu_count_get(CPU_COUNT_FLT_ANON),
125a98966d3Sad cpu_count_get(CPU_COUNT_FLT_ACOW),
126a98966d3Sad cpu_count_get(CPU_COUNT_FLT_OBJ),
127a98966d3Sad cpu_count_get(CPU_COUNT_FLT_PRCOPY),
128a98966d3Sad cpu_count_get(CPU_COUNT_FLT_PRZERO));
129e6c31d3dSthorpej
13055a751c9Schs (*pr)(" daemon and swap counts:\n");
13155a751c9Schs (*pr)(" woke=%d, revs=%d, scans=%d, obscans=%d, anscans=%d\n",
13255a751c9Schs uvmexp.pdwoke, uvmexp.pdrevs, uvmexp.pdscans, uvmexp.pdobscan,
13355a751c9Schs uvmexp.pdanscan);
13455a751c9Schs (*pr)(" busy=%d, freed=%d, reactivate=%d, deactivate=%d\n",
135e6c31d3dSthorpej uvmexp.pdbusy, uvmexp.pdfreed, uvmexp.pdreact, uvmexp.pddeact);
13655a751c9Schs (*pr)(" pageouts=%d, pending=%d, nswget=%d\n", uvmexp.pdpageouts,
137f2caacc7Smrg uvmexp.pdpending, uvmexp.nswget);
138627b0d50Syamt (*pr)(" nswapdev=%d, swpgavail=%d\n",
139627b0d50Syamt uvmexp.nswapdev, uvmexp.swpgavail);
140627b0d50Syamt (*pr)(" swpages=%d, swpginuse=%d, swpgonly=%d, paging=%d\n",
141d97d75d8Schs uvmexp.swpages, uvmexp.swpginuse, uvmexp.swpgonly, uvmexp.paging);
142f2caacc7Smrg }
14355a751c9Schs #endif
14452f0a628Syamt
14552f0a628Syamt #if defined(READAHEAD_STATS)
14652f0a628Syamt
14752f0a628Syamt #define UVM_RA_EVCNT_DEFINE(name) \
14852f0a628Syamt struct evcnt uvm_ra_##name = \
14952f0a628Syamt EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "readahead", #name); \
15052f0a628Syamt EVCNT_ATTACH_STATIC(uvm_ra_##name);
15152f0a628Syamt
15252f0a628Syamt UVM_RA_EVCNT_DEFINE(total);
15352f0a628Syamt UVM_RA_EVCNT_DEFINE(hit);
15452f0a628Syamt UVM_RA_EVCNT_DEFINE(miss);
15552f0a628Syamt
15652f0a628Syamt #endif /* defined(READAHEAD_STATS) */
157