Re: Kill uvm/uvm_stat.c

2019-12-04 Thread Mike Larkin
On Wed, Dec 04, 2019 at 03:19:41PM +0100, Martin Pieuchot wrote:
> Less is more.  Fewer files to look at, simpler it becomes to understand
> UVM.  uvm/uvm_stat.c contains just a ddb(4) function.  Let's move it to
> uvm/uvm_meter.c which also deals with counters. ok?
> 

Also reads ok to me.

-ml

> Index: conf/files
> ===
> RCS file: /cvs/src/sys/conf/files,v
> retrieving revision 1.677
> diff -u -p -r1.677 files
> --- conf/files5 Nov 2019 08:18:47 -   1.677
> +++ conf/files4 Dec 2019 14:15:03 -
> @@ -964,7 +964,6 @@ file uvm/uvm_page.c
>  file uvm/uvm_pager.c
>  file uvm/uvm_pdaemon.c
>  file uvm/uvm_pmemrange.c
> -file uvm/uvm_stat.c
>  file uvm/uvm_swap.c
>  file uvm/uvm_swap_encrypt.c  uvm_swap_encrypt
>  file uvm/uvm_unix.c
> Index: uvm/uvm_meter.c
> ===
> RCS file: /cvs/src/sys/uvm/uvm_meter.c,v
> retrieving revision 1.38
> diff -u -p -r1.38 uvm_meter.c
> --- uvm/uvm_meter.c   6 Nov 2018 07:49:38 -   1.38
> +++ uvm/uvm_meter.c   4 Dec 2019 14:16:01 -
> @@ -43,6 +43,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #ifdef UVM_SWAP_ENCRYPT
>  #include 
> @@ -312,3 +313,62 @@ uvm_total(struct vmtotal *totalp)
>   totalp->t_rmshr = 0;/* XXX */
>   totalp->t_armshr = 0;   /* XXX */
>  }
> +
> +#ifdef DDB
> +
> +/*
> + * uvmexp_print: ddb hook to print interesting uvm counters
> + */
> +void
> +uvmexp_print(int (*pr)(const char *, ...))
> +{
> +
> + (*pr)("Current UVM status:\n");
> + (*pr)("  pagesize=%d (0x%x), pagemask=0x%x, pageshift=%d\n",
> + uvmexp.pagesize, uvmexp.pagesize, uvmexp.pagemask,
> + uvmexp.pageshift);
> + (*pr)("  %d VM pages: %d active, %d inactive, %d wired, %d free (%d 
> zero)\n",
> + uvmexp.npages, uvmexp.active, uvmexp.inactive, uvmexp.wired,
> + uvmexp.free, uvmexp.zeropages);
> + (*pr)("  min  %d%% (%d) anon, %d%% (%d) vnode, %d%% (%d) vtext\n",
> + uvmexp.anonminpct, uvmexp.anonmin, uvmexp.vnodeminpct,
> + uvmexp.vnodemin, uvmexp.vtextminpct, uvmexp.vtextmin);
> + (*pr)("  freemin=%d, free-target=%d, inactive-target=%d, "
> + "wired-max=%d\n", uvmexp.freemin, uvmexp.freetarg, uvmexp.inactarg,
> + uvmexp.wiredmax);
> + (*pr)("  faults=%d, traps=%d, intrs=%d, ctxswitch=%d fpuswitch=%d\n",
> + uvmexp.faults, uvmexp.traps, uvmexp.intrs, uvmexp.swtch,
> + uvmexp.fpswtch);
> + (*pr)("  softint=%d, syscalls=%d, kmapent=%d\n",
> + uvmexp.softs, uvmexp.syscalls, uvmexp.kmapent);
> +
> + (*pr)("  fault counts:\n");
> + (*pr)("noram=%d, noanon=%d, noamap=%d, pgwait=%d, pgrele=%d\n",
> + uvmexp.fltnoram, uvmexp.fltnoanon, uvmexp.fltnoamap,
> + uvmexp.fltpgwait, uvmexp.fltpgrele);
> + (*pr)("ok relocks(total)=%d(%d), anget(retries)=%d(%d), "
> + "amapcopy=%d\n", uvmexp.fltrelckok, uvmexp.fltrelck,
> + uvmexp.fltanget, uvmexp.fltanretry, uvmexp.fltamcopy);
> + (*pr)("neighbor anon/obj pg=%d/%d, gets(lock/unlock)=%d/%d\n",
> + uvmexp.fltnamap, uvmexp.fltnomap, uvmexp.fltlget, uvmexp.fltget);
> + (*pr)("cases: anon=%d, anoncow=%d, obj=%d, prcopy=%d, przero=%d\n",
> + uvmexp.flt_anon, uvmexp.flt_acow, uvmexp.flt_obj, uvmexp.flt_prcopy,
> + uvmexp.flt_przero);
> +
> + (*pr)("  daemon and swap counts:\n");
> + (*pr)("woke=%d, revs=%d, scans=%d, obscans=%d, anscans=%d\n",
> + uvmexp.pdwoke, uvmexp.pdrevs, uvmexp.pdscans, uvmexp.pdobscan,
> + uvmexp.pdanscan);
> + (*pr)("busy=%d, freed=%d, reactivate=%d, deactivate=%d\n",
> + uvmexp.pdbusy, uvmexp.pdfreed, uvmexp.pdreact, uvmexp.pddeact);
> + (*pr)("pageouts=%d, pending=%d, nswget=%d\n", uvmexp.pdpageouts,
> + uvmexp.pdpending, uvmexp.nswget);
> + (*pr)("nswapdev=%d\n",
> + uvmexp.nswapdev);
> + (*pr)("swpages=%d, swpginuse=%d, swpgonly=%d paging=%d\n",
> + uvmexp.swpages, uvmexp.swpginuse, uvmexp.swpgonly, uvmexp.paging);
> +
> + (*pr)("  kernel pointers:\n");
> + (*pr)("objs(kern)=%p\n", uvm.kernel_object);
> +}
> +#endif
> Index: uvm/uvm_stat.c
> ===
> RCS file: uvm/uvm_stat.c
> diff -N uvm/uvm_stat.c
> --- uvm/uvm_stat.c19 Jun 2018 22:35:07 -  1.30
> +++ /dev/null 1 Jan 1970 00:00:00 -
> @@ -1,98 +0,0 @@
> -/*   $OpenBSD: uvm_stat.c,v 1.30 2018/06/19 22:35:07 krw Exp $*/
> -/*   $NetBSD: uvm_stat.c,v 1.18 2001/03/09 01:02:13 chs Exp $ */
> -
> -/*
> - * Copyright (c) 1997 Charles D. Cranor and Washington University.
> - * All rights reserved.
> - *
> - * Redistribution and use in source and binary forms, with or without
> - * modification, are permitted provided that the following conditions
> - * are met:
> - * 1. 

Kill uvm/uvm_stat.c

2019-12-04 Thread Martin Pieuchot
Less is more.  Fewer files to look at, simpler it becomes to understand
UVM.  uvm/uvm_stat.c contains just a ddb(4) function.  Let's move it to
uvm/uvm_meter.c which also deals with counters. ok?

Index: conf/files
===
RCS file: /cvs/src/sys/conf/files,v
retrieving revision 1.677
diff -u -p -r1.677 files
--- conf/files  5 Nov 2019 08:18:47 -   1.677
+++ conf/files  4 Dec 2019 14:15:03 -
@@ -964,7 +964,6 @@ file uvm/uvm_page.c
 file uvm/uvm_pager.c
 file uvm/uvm_pdaemon.c
 file uvm/uvm_pmemrange.c
-file uvm/uvm_stat.c
 file uvm/uvm_swap.c
 file uvm/uvm_swap_encrypt.cuvm_swap_encrypt
 file uvm/uvm_unix.c
Index: uvm/uvm_meter.c
===
RCS file: /cvs/src/sys/uvm/uvm_meter.c,v
retrieving revision 1.38
diff -u -p -r1.38 uvm_meter.c
--- uvm/uvm_meter.c 6 Nov 2018 07:49:38 -   1.38
+++ uvm/uvm_meter.c 4 Dec 2019 14:16:01 -
@@ -43,6 +43,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #ifdef UVM_SWAP_ENCRYPT
 #include 
@@ -312,3 +313,62 @@ uvm_total(struct vmtotal *totalp)
totalp->t_rmshr = 0;/* XXX */
totalp->t_armshr = 0;   /* XXX */
 }
+
+#ifdef DDB
+
+/*
+ * uvmexp_print: ddb hook to print interesting uvm counters
+ */
+void
+uvmexp_print(int (*pr)(const char *, ...))
+{
+
+   (*pr)("Current UVM status:\n");
+   (*pr)("  pagesize=%d (0x%x), pagemask=0x%x, pageshift=%d\n",
+   uvmexp.pagesize, uvmexp.pagesize, uvmexp.pagemask,
+   uvmexp.pageshift);
+   (*pr)("  %d VM pages: %d active, %d inactive, %d wired, %d free (%d 
zero)\n",
+   uvmexp.npages, uvmexp.active, uvmexp.inactive, uvmexp.wired,
+   uvmexp.free, uvmexp.zeropages);
+   (*pr)("  min  %d%% (%d) anon, %d%% (%d) vnode, %d%% (%d) vtext\n",
+   uvmexp.anonminpct, uvmexp.anonmin, uvmexp.vnodeminpct,
+   uvmexp.vnodemin, uvmexp.vtextminpct, uvmexp.vtextmin);
+   (*pr)("  freemin=%d, free-target=%d, inactive-target=%d, "
+   "wired-max=%d\n", uvmexp.freemin, uvmexp.freetarg, uvmexp.inactarg,
+   uvmexp.wiredmax);
+   (*pr)("  faults=%d, traps=%d, intrs=%d, ctxswitch=%d fpuswitch=%d\n",
+   uvmexp.faults, uvmexp.traps, uvmexp.intrs, uvmexp.swtch,
+   uvmexp.fpswtch);
+   (*pr)("  softint=%d, syscalls=%d, kmapent=%d\n",
+   uvmexp.softs, uvmexp.syscalls, uvmexp.kmapent);
+
+   (*pr)("  fault counts:\n");
+   (*pr)("noram=%d, noanon=%d, noamap=%d, pgwait=%d, pgrele=%d\n",
+   uvmexp.fltnoram, uvmexp.fltnoanon, uvmexp.fltnoamap,
+   uvmexp.fltpgwait, uvmexp.fltpgrele);
+   (*pr)("ok relocks(total)=%d(%d), anget(retries)=%d(%d), "
+   "amapcopy=%d\n", uvmexp.fltrelckok, uvmexp.fltrelck,
+   uvmexp.fltanget, uvmexp.fltanretry, uvmexp.fltamcopy);
+   (*pr)("neighbor anon/obj pg=%d/%d, gets(lock/unlock)=%d/%d\n",
+   uvmexp.fltnamap, uvmexp.fltnomap, uvmexp.fltlget, uvmexp.fltget);
+   (*pr)("cases: anon=%d, anoncow=%d, obj=%d, prcopy=%d, przero=%d\n",
+   uvmexp.flt_anon, uvmexp.flt_acow, uvmexp.flt_obj, uvmexp.flt_prcopy,
+   uvmexp.flt_przero);
+
+   (*pr)("  daemon and swap counts:\n");
+   (*pr)("woke=%d, revs=%d, scans=%d, obscans=%d, anscans=%d\n",
+   uvmexp.pdwoke, uvmexp.pdrevs, uvmexp.pdscans, uvmexp.pdobscan,
+   uvmexp.pdanscan);
+   (*pr)("busy=%d, freed=%d, reactivate=%d, deactivate=%d\n",
+   uvmexp.pdbusy, uvmexp.pdfreed, uvmexp.pdreact, uvmexp.pddeact);
+   (*pr)("pageouts=%d, pending=%d, nswget=%d\n", uvmexp.pdpageouts,
+   uvmexp.pdpending, uvmexp.nswget);
+   (*pr)("nswapdev=%d\n",
+   uvmexp.nswapdev);
+   (*pr)("swpages=%d, swpginuse=%d, swpgonly=%d paging=%d\n",
+   uvmexp.swpages, uvmexp.swpginuse, uvmexp.swpgonly, uvmexp.paging);
+
+   (*pr)("  kernel pointers:\n");
+   (*pr)("objs(kern)=%p\n", uvm.kernel_object);
+}
+#endif
Index: uvm/uvm_stat.c
===
RCS file: uvm/uvm_stat.c
diff -N uvm/uvm_stat.c
--- uvm/uvm_stat.c  19 Jun 2018 22:35:07 -  1.30
+++ /dev/null   1 Jan 1970 00:00:00 -
@@ -1,98 +0,0 @@
-/* $OpenBSD: uvm_stat.c,v 1.30 2018/06/19 22:35:07 krw Exp $*/
-/* $NetBSD: uvm_stat.c,v 1.18 2001/03/09 01:02:13 chs Exp $ */
-
-/*
- * Copyright (c) 1997 Charles D. Cranor and Washington University.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *notice, this list of conditions