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