Home | History | Annotate | Line # | Download | only in uvm
uvm_stat.c revision 1.45
      1 /*	$NetBSD: uvm_stat.c,v 1.45 2020/06/11 22:21:05 ad Exp $	 */
      2 
      3 /*
      4  * Copyright (c) 1997 Charles D. Cranor and Washington University.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  *
     27  * from: Id: uvm_stat.c,v 1.1.2.3 1997/12/19 15:01:00 mrg Exp
     28  */
     29 
     30 /*
     31  * uvm_stat.c
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: uvm_stat.c,v 1.45 2020/06/11 22:21:05 ad Exp $");
     36 
     37 #include "opt_readahead.h"
     38 #include "opt_ddb.h"
     39 
     40 #include <sys/param.h>
     41 #include <sys/systm.h>
     42 #include <sys/cpu.h>
     43 
     44 #include <uvm/uvm.h>
     45 #include <uvm/uvm_ddb.h>
     46 
     47 #ifdef DDB
     48 
     49 #include <sys/pool.h>
     50 
     51 /*
     52  * uvmexp_print: ddb hook to print interesting uvm counters
     53  */
     54 void
     55 uvmexp_print(void (*pr)(const char *, ...)
     56     __attribute__((__format__(__printf__,1,2))))
     57 {
     58 	int64_t anonpg, execpg, filepg;
     59 	int active, inactive;
     60 	int poolpages, freepg;
     61 
     62 	uvm_estimatepageable(&active, &inactive);
     63 	poolpages = pool_totalpages_locked();
     64 
     65 	/* this will sync all counters. */
     66 	freepg = uvm_availmem(false);
     67 
     68 	anonpg = cpu_count_get(CPU_COUNT_ANONCLEAN) +
     69 	    cpu_count_get(CPU_COUNT_ANONDIRTY) +
     70 	    cpu_count_get(CPU_COUNT_ANONUNKNOWN);
     71 	execpg = cpu_count_get(CPU_COUNT_EXECPAGES);
     72 	filepg = cpu_count_get(CPU_COUNT_FILECLEAN) +
     73 	    cpu_count_get(CPU_COUNT_FILEDIRTY) +
     74 	    cpu_count_get(CPU_COUNT_FILEUNKNOWN) -
     75 	    execpg;
     76 
     77 	(*pr)("Current UVM status:\n");
     78 	(*pr)("  pagesize=%d (0x%x), pagemask=0x%x, pageshift=%d, ncolors=%d\n",
     79 	    uvmexp.pagesize, uvmexp.pagesize, uvmexp.pagemask,
     80 	    uvmexp.pageshift, uvmexp.ncolors);
     81 	(*pr)("  %d VM pages: %d active, %d inactive, %d wired, %d free\n",
     82 	    uvmexp.npages, active, inactive, uvmexp.wired, freepg);
     83 	(*pr)("  pages  %" PRId64 " anon, %" PRId64 " file, %" PRId64 " exec\n",
     84 	    anonpg, filepg, execpg);
     85 	(*pr)("  freemin=%d, free-target=%d, wired-max=%d\n",
     86 	    uvmexp.freemin, uvmexp.freetarg, uvmexp.wiredmax);
     87 	(*pr)("  resv-pg=%d, resv-kernel=%d, zeropages=%" PRId64 "\n",
     88 	    uvmexp.reserve_pagedaemon, uvmexp.reserve_kernel,
     89 	    cpu_count_get(CPU_COUNT_ZEROPAGES));
     90 	(*pr)("  bootpages=%d, poolpages=%d\n",
     91 	    uvmexp.bootpages, poolpages);
     92 
     93 	(*pr)("  faults=%" PRId64 ", traps=%" PRId64 ", "
     94 	      "intrs=%" PRId64 ", ctxswitch=%" PRId64 "\n",
     95 	    cpu_count_get(CPU_COUNT_NFAULT),
     96 	    cpu_count_get(CPU_COUNT_NTRAP),
     97 	    cpu_count_get(CPU_COUNT_NINTR),
     98 	    cpu_count_get(CPU_COUNT_NSWTCH));
     99 	(*pr)("   softint=%" PRId64 ", syscalls=%" PRId64 "\n",
    100 	    cpu_count_get(CPU_COUNT_NSOFT),
    101 	    cpu_count_get(CPU_COUNT_NSYSCALL));
    102 
    103 	(*pr)("  fault counts:\n");
    104 	(*pr)("    noram=%" PRId64 ", noanon=%" PRId64 ", pgwait=%" PRId64
    105 	    ", pgrele=%" PRId64 "\n",
    106 	    cpu_count_get(CPU_COUNT_FLTNORAM),
    107 	    cpu_count_get(CPU_COUNT_FLTNOANON),
    108 	    cpu_count_get(CPU_COUNT_FLTPGWAIT),
    109 	    cpu_count_get(CPU_COUNT_FLTPGRELE));
    110 	(*pr)("    ok relocks(total)=%" PRId64 "(%" PRId64 "), "
    111 	    "anget(retrys)=%" PRId64 "(%" PRId64 "), amapcopy=%" PRId64 "\n",
    112 	    cpu_count_get(CPU_COUNT_FLTRELCKOK),
    113 	    cpu_count_get(CPU_COUNT_FLTRELCK),
    114 	    cpu_count_get(CPU_COUNT_FLTANGET),
    115 	    cpu_count_get(CPU_COUNT_FLTANRETRY),
    116 	    cpu_count_get(CPU_COUNT_FLTAMCOPY));
    117 	(*pr)("    neighbor anon/obj pg=%" PRId64 "/%" PRId64
    118 	    ", gets(lock/unlock)=%" PRId64 "/%" PRId64 "\n",
    119 	    cpu_count_get(CPU_COUNT_FLTNAMAP),
    120 	    cpu_count_get(CPU_COUNT_FLTNOMAP),
    121 	    cpu_count_get(CPU_COUNT_FLTLGET),
    122 	    cpu_count_get(CPU_COUNT_FLTGET));
    123 	(*pr)("    cases: anon=%" PRId64 ", anoncow=%" PRId64 ", obj=%" PRId64
    124 	    ", prcopy=%" PRId64 ", przero=%" PRId64 "\n",
    125 	    cpu_count_get(CPU_COUNT_FLT_ANON),
    126 	    cpu_count_get(CPU_COUNT_FLT_ACOW),
    127 	    cpu_count_get(CPU_COUNT_FLT_OBJ),
    128 	    cpu_count_get(CPU_COUNT_FLT_PRCOPY),
    129 	    cpu_count_get(CPU_COUNT_FLT_PRZERO));
    130 
    131 	(*pr)("  daemon and swap counts:\n");
    132 	(*pr)("    woke=%d, revs=%d, scans=%d, obscans=%d, anscans=%d\n",
    133 	    uvmexp.pdwoke, uvmexp.pdrevs, uvmexp.pdscans, uvmexp.pdobscan,
    134 	    uvmexp.pdanscan);
    135 	(*pr)("    busy=%d, freed=%d, reactivate=%d, deactivate=%d\n",
    136 	    uvmexp.pdbusy, uvmexp.pdfreed, uvmexp.pdreact, uvmexp.pddeact);
    137 	(*pr)("    pageouts=%d, pending=%d, nswget=%d\n", uvmexp.pdpageouts,
    138 	    uvmexp.pdpending, uvmexp.nswget);
    139 	(*pr)("    nswapdev=%d, swpgavail=%d\n",
    140 	    uvmexp.nswapdev, uvmexp.swpgavail);
    141 	(*pr)("    swpages=%d, swpginuse=%d, swpgonly=%d, paging=%d\n",
    142 	    uvmexp.swpages, uvmexp.swpginuse, uvmexp.swpgonly, uvmexp.paging);
    143 }
    144 #endif
    145 
    146 #if defined(READAHEAD_STATS)
    147 
    148 #define	UVM_RA_EVCNT_DEFINE(name) \
    149 struct evcnt uvm_ra_##name = \
    150 EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "readahead", #name); \
    151 EVCNT_ATTACH_STATIC(uvm_ra_##name);
    152 
    153 UVM_RA_EVCNT_DEFINE(total);
    154 UVM_RA_EVCNT_DEFINE(hit);
    155 UVM_RA_EVCNT_DEFINE(miss);
    156 
    157 #endif /* defined(READAHEAD_STATS) */
    158