On Sat, Jul 03, 2021 at 11:20:42AM +0100, Stuart Henderson wrote:
> On 2021/07/03 01:09, Anindya Mukherjee wrote:
> > Thanks for the discussion. This has been very illuminating. I have been 
> > digging
> > around in /usr/src/ and ignoring the atomic architectures (where I got 
> > stuck) it
> > looks like it should be possible to use uint64_t everywhere. I'm playing 
> > with
> > some changes on my machine to see if I can get at least systat(1) and 
> > vmstat(8)
> > to work with uint64_t. The ddb printer (uvmexp_print)is another consumer.
> > 
> > If it works in the base system then ideally every relevant port should be
> > updated to be consistent. That is indeed quite a big change; more than I
> > realised so thanks for setting me straight on that.
> 
> We have coped with bigger changes in structs like this before,
> it didn't used to be too difficult, but that was before go...
> 

Hi,

I have been running for a week with the following diff. This is just a POC and
hence there are a few ugly hacks. So far top(1), systat(1), and vmstat(8) seem
to be happy. I haven't hit the 32-bit overflow point for any counters yet but
the counts look right. I have completely ignored ports, but it looks like the
base system can run with this change. This was mostly to satisfy my curiosity.

Regards,
Anindya

? usr.bin/systat/vim_session
Index: sys/arch/amd64/include/atomic.h
===================================================================
RCS file: /cvs/src/sys/arch/amd64/include/atomic.h,v
retrieving revision 1.21
diff -u -p -r1.21 atomic.h
--- sys/arch/amd64/include/atomic.h     11 Mar 2021 11:16:55 -0000      1.21
+++ sys/arch/amd64/include/atomic.h     13 Jul 2021 07:42:51 -0000
@@ -150,6 +150,14 @@ _atomic_inc_long(volatile unsigned long 
 #define atomic_inc_long(_p) _atomic_inc_long(_p)
 
 static inline void
+_atomic_inc_uint64(volatile uint64_t *p)
+{
+       __asm volatile(_LOCK " incq %0"
+           : "+m" (*p));
+}
+#define atomic_inc_uint64(_p) _atomic_inc_uint64(_p)
+
+static inline void
 _atomic_dec_int(volatile unsigned int *p)
 {
        __asm volatile(_LOCK " decl %0"
@@ -166,6 +174,14 @@ _atomic_dec_long(volatile unsigned long 
 #define atomic_dec_long(_p) _atomic_dec_long(_p)
 
 static inline void
+_atomic_dec_uint64(volatile uint64_t *p)
+{
+       __asm volatile(_LOCK " decq %0"
+           : "+m" (*p));
+}
+#define atomic_dec_uint64(_p) _atomic_dec_uint64(_p)
+
+static inline void
 _atomic_add_int(volatile unsigned int *p, unsigned int v)
 {
        __asm volatile(_LOCK " addl %1,%0"
@@ -182,6 +198,15 @@ _atomic_add_long(volatile unsigned long 
            : "a" (v));
 }
 #define atomic_add_long(_p, _v) _atomic_add_long(_p, _v)
+
+static inline void
+_atomic_add_uint64(volatile uint64_t *p, uint64_t v)
+{
+       __asm volatile(_LOCK " addq %1,%0"
+           : "+m" (*p)
+           : "a" (v));
+}
+#define atomic_add_uint64(_p, _v) _atomic_add_uint64(_p, _v)
 
 static inline void
 _atomic_sub_int(volatile unsigned int *p, unsigned int v)
Index: sys/sys/sysctl.h
===================================================================
RCS file: /cvs/src/sys/sys/sysctl.h,v
retrieving revision 1.218
diff -u -p -r1.218 sysctl.h
--- sys/sys/sysctl.h    17 May 2021 17:54:31 -0000      1.218
+++ sys/sys/sysctl.h    13 Jul 2021 07:42:52 -0000
@@ -38,7 +38,8 @@
 #ifndef _SYS_SYSCTL_H_
 #define        _SYS_SYSCTL_H_
 
-#include <uvm/uvmexp.h>
+/*#include <uvm/uvmexp.h>*/
+#include "/usr/src/sys/uvm/uvmexp.h"
 
 /*
  * Definitions for sysctl call.  The sysctl call uses a hierarchical name
Index: sys/uvm/uvm_anon.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_anon.c,v
retrieving revision 1.54
diff -u -p -r1.54 uvm_anon.c
--- sys/uvm/uvm_anon.c  26 Mar 2021 13:40:05 -0000      1.54
+++ sys/uvm/uvm_anon.c  13 Jul 2021 07:42:52 -0000
@@ -119,7 +119,7 @@ uvm_anfree_list(struct vm_anon *anon, st
                if (anon->an_swslot != 0) {
                        /* This page is no longer only in swap. */
                        KASSERT(uvmexp.swpgonly > 0);
-                       atomic_dec_int(&uvmexp.swpgonly);
+                       atomic_dec_uint64(&uvmexp.swpgonly);
                }
        }
        anon->an_lock = NULL;
Index: sys/uvm/uvm_aobj.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_aobj.c,v
retrieving revision 1.99
diff -u -p -r1.99 uvm_aobj.c
--- sys/uvm/uvm_aobj.c  28 Jun 2021 11:19:01 -0000      1.99
+++ sys/uvm/uvm_aobj.c  13 Jul 2021 07:42:52 -0000
@@ -1516,6 +1516,6 @@ uao_dropswap_range(struct uvm_object *uo
         */
        if (swpgonlydelta > 0) {
                KASSERT(uvmexp.swpgonly >= swpgonlydelta);
-               atomic_add_int(&uvmexp.swpgonly, -swpgonlydelta);
+               atomic_add_uint64(&uvmexp.swpgonly, -swpgonlydelta);
        }
 }
Index: sys/uvm/uvm_km.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_km.c,v
retrieving revision 1.145
diff -u -p -r1.145 uvm_km.c
--- sys/uvm/uvm_km.c    15 Jun 2021 16:38:09 -0000      1.145
+++ sys/uvm/uvm_km.c    13 Jul 2021 07:42:52 -0000
@@ -271,7 +271,7 @@ uvm_km_pgremove(struct uvm_object *uobj,
 
        if (swpgonlydelta > 0) {
                KASSERT(uvmexp.swpgonly >= swpgonlydelta);
-               atomic_add_int(&uvmexp.swpgonly, -swpgonlydelta);
+               atomic_add_uint64(&uvmexp.swpgonly, -swpgonlydelta);
        }
 }
 
Index: sys/uvm/uvm_meter.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_meter.c,v
retrieving revision 1.42
diff -u -p -r1.42 uvm_meter.c
--- sys/uvm/uvm_meter.c 28 Dec 2020 14:01:23 -0000      1.42
+++ sys/uvm/uvm_meter.c 13 Jul 2021 07:42:52 -0000
@@ -329,29 +329,29 @@ uvmexp_read(struct uvmexp *uexp)
                counters_read(uvmexp_counters, counters, exp_ncounters);
 
                /* stat counters */
-               uexp->faults = (int)counters[faults];
-               uexp->pageins = (int)counters[pageins];
+               uexp->faults = counters[faults];
+               uexp->pageins = counters[pageins];
 
                /* fault subcounters */
-               uexp->fltnoram = (int)counters[flt_noram];
-               uexp->fltnoanon = (int)counters[flt_noanon];
-               uexp->fltnoamap = (int)counters[flt_noamap];
-               uexp->fltpgwait = (int)counters[flt_pgwait];
-               uexp->fltpgrele = (int)counters[flt_pgrele];
-               uexp->fltrelck = (int)counters[flt_relck];
-               uexp->fltrelckok = (int)counters[flt_relckok];
-               uexp->fltanget = (int)counters[flt_anget];
-               uexp->fltanretry = (int)counters[flt_anretry];
-               uexp->fltamcopy = (int)counters[flt_amcopy];
-               uexp->fltnamap = (int)counters[flt_namap];
-               uexp->fltnomap = (int)counters[flt_nomap];
-               uexp->fltlget = (int)counters[flt_lget];
-               uexp->fltget = (int)counters[flt_get];
-               uexp->flt_anon = (int)counters[flt_anon];
-               uexp->flt_acow = (int)counters[flt_acow];
-               uexp->flt_obj = (int)counters[flt_obj];
-               uexp->flt_prcopy = (int)counters[flt_prcopy];
-               uexp->flt_przero = (int)counters[flt_przero];
+               uexp->fltnoram = counters[flt_noram];
+               uexp->fltnoanon = counters[flt_noanon];
+               uexp->fltnoamap = counters[flt_noamap];
+               uexp->fltpgwait = counters[flt_pgwait];
+               uexp->fltpgrele = counters[flt_pgrele];
+               uexp->fltrelck = counters[flt_relck];
+               uexp->fltrelckok = counters[flt_relckok];
+               uexp->fltanget = counters[flt_anget];
+               uexp->fltanretry = counters[flt_anretry];
+               uexp->fltamcopy = counters[flt_amcopy];
+               uexp->fltnamap = counters[flt_namap];
+               uexp->fltnomap = counters[flt_nomap];
+               uexp->fltlget = counters[flt_lget];
+               uexp->fltget = counters[flt_get];
+               uexp->flt_anon = counters[flt_anon];
+               uexp->flt_acow = counters[flt_acow];
+               uexp->flt_obj = counters[flt_obj];
+               uexp->flt_prcopy = counters[flt_prcopy];
+               uexp->flt_przero = counters[flt_przero];
 }
 
 #ifdef DDB
@@ -367,48 +367,49 @@ uvmexp_print(int (*pr)(const char *, ...
        uvmexp_read(&uexp);
 
        (*pr)("Current UVM status:\n");
-       (*pr)("  pagesize=%d (0x%x), pagemask=0x%x, pageshift=%d\n",
+       (*pr)("  pagesize=%llu (0x%x), pagemask=0x%x, pageshift=%llu\n",
            uexp.pagesize, uexp.pagesize, uexp.pagemask,
            uexp.pageshift);
-       (*pr)("  %d VM pages: %d active, %d inactive, %d wired, %d free (%d 
zero)\n",
-           uexp.npages, uexp.active, uexp.inactive, uexp.wired,
-           uexp.free, uexp.zeropages);
-       (*pr)("  min  %d%% (%d) anon, %d%% (%d) vnode, %d%% (%d) vtext\n",
-           uexp.anonminpct, uexp.anonmin, uexp.vnodeminpct,
-           uexp.vnodemin, uexp.vtextminpct, uexp.vtextmin);
-       (*pr)("  freemin=%d, free-target=%d, inactive-target=%d, "
-           "wired-max=%d\n", uexp.freemin, uexp.freetarg, uexp.inactarg,
+       (*pr)("  %llu VM pages: %llu active, %llu inactive, %llu wired, "
+           "%llu free (%llu zero)\n", uexp.npages, uexp.active, uexp.inactive,
+           uexp.wired, uexp.free, uexp.zeropages);
+       (*pr)("  min  %llu%% (%llu) anon, %llu%% (%llu) vnode, "
+           "%llu%% (%llu) vtext\n", uexp.anonminpct, uexp.anonmin,
+           uexp.vnodeminpct, uexp.vnodemin, uexp.vtextminpct, uexp.vtextmin);
+       (*pr)("  freemin=%llu, free-target=%llu, inactive-target=%llu, "
+           "wired-max=%llu\n", uexp.freemin, uexp.freetarg, uexp.inactarg,
            uexp.wiredmax);
-       (*pr)("  faults=%d, traps=%d, intrs=%d, ctxswitch=%d fpuswitch=%d\n",
-           uexp.faults, uexp.traps, uexp.intrs, uexp.swtch,
-           uexp.fpswtch);
-       (*pr)("  softint=%d, syscalls=%d, kmapent=%d\n",
+       (*pr)("  faults=%llu, traps=%llu, intrs=%llu, "
+           "ctxswitch=%llu fpuswitch=%llu\n", uexp.faults, uexp.traps,
+           uexp.intrs, uexp.swtch, uexp.fpswtch);
+       (*pr)("  softint=%llu, syscalls=%llu, kmapent=%llu\n",
            uexp.softs, uexp.syscalls, uexp.kmapent);
 
        (*pr)("  fault counts:\n");
-       (*pr)("    noram=%d, noanon=%d, noamap=%d, pgwait=%d, pgrele=%d\n",
-           uexp.fltnoram, uexp.fltnoanon, uexp.fltnoamap,
+       (*pr)("    noram=%llu, noanon=%llu, noamap=%llu, pgwait=%llu, "
+           "pgrele=%llu\n", uexp.fltnoram, uexp.fltnoanon, uexp.fltnoamap,
            uexp.fltpgwait, uexp.fltpgrele);
-       (*pr)("    ok relocks(total)=%d(%d), anget(retries)=%d(%d), "
-           "amapcopy=%d\n", uexp.fltrelckok, uexp.fltrelck,
+       (*pr)("    ok relocks(total)=%llu(%llu), anget(retries)=%llu(%llu), "
+           "amapcopy=%llu\n", uexp.fltrelckok, uexp.fltrelck,
            uexp.fltanget, uexp.fltanretry, uexp.fltamcopy);
-       (*pr)("    neighbor anon/obj pg=%d/%d, gets(lock/unlock)=%d/%d\n",
-           uexp.fltnamap, uexp.fltnomap, uexp.fltlget, uexp.fltget);
-       (*pr)("    cases: anon=%d, anoncow=%d, obj=%d, prcopy=%d, przero=%d\n",
-           uexp.flt_anon, uexp.flt_acow, uexp.flt_obj, uexp.flt_prcopy,
-           uexp.flt_przero);
+       (*pr)("    neighbor anon/obj pg=%llu/%llu, "
+           "gets(lock/unlock)=%llu/%llu\n", uexp.fltnamap, uexp.fltnomap,
+           uexp.fltlget, uexp.fltget);
+       (*pr)("    cases: anon=%llu, anoncow=%llu, obj=%llu, prcopy=%llu, "
+           "przero=%llu\n", uexp.flt_anon, uexp.flt_acow, uexp.flt_obj,
+           uexp.flt_prcopy, uexp.flt_przero);
 
        (*pr)("  daemon and swap counts:\n");
-       (*pr)("    woke=%d, revs=%d, scans=%d, obscans=%d, anscans=%d\n",
-           uexp.pdwoke, uexp.pdrevs, uexp.pdscans, uexp.pdobscan,
-           uexp.pdanscan);
-       (*pr)("    busy=%d, freed=%d, reactivate=%d, deactivate=%d\n",
+       (*pr)("    woke=%llu, revs=%llu, scans=%llu, obscans=%llu, "
+           "anscans=%llu\n", uexp.pdwoke, uexp.pdrevs, uexp.pdscans,
+           uexp.pdobscan, uexp.pdanscan);
+       (*pr)("    busy=%llu, freed=%llu, reactivate=%llu, deactivate=%llu\n",
            uexp.pdbusy, uexp.pdfreed, uexp.pdreact, uexp.pddeact);
-       (*pr)("    pageouts=%d, pending=%d, nswget=%d\n", uexp.pdpageouts,
+       (*pr)("    pageouts=%llu, pending=%llu, nswget=%llu\n", uexp.pdpageouts,
            uexp.pdpending, uexp.nswget);
-       (*pr)("    nswapdev=%d\n",
+       (*pr)("    nswapdev=%llu\n",
            uexp.nswapdev);
-       (*pr)("    swpages=%d, swpginuse=%d, swpgonly=%d paging=%d\n",
+       (*pr)("    swpages=%llu, swpginuse=%llu, swpgonly=%llu paging=%llu\n",
            uexp.swpages, uexp.swpginuse, uexp.swpgonly, uexp.paging);
 
        (*pr)("  kernel pointers:\n");
Index: sys/uvm/uvm_pdaemon.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_pdaemon.c,v
retrieving revision 1.93
diff -u -p -r1.93 uvm_pdaemon.c
--- sys/uvm/uvm_pdaemon.c       29 Jun 2021 01:46:35 -0000      1.93
+++ sys/uvm/uvm_pdaemon.c       13 Jul 2021 07:42:52 -0000
@@ -1,9 +1,9 @@
 /*     $OpenBSD: uvm_pdaemon.c,v 1.93 2021/06/29 01:46:35 jsg Exp $    */
 /*     $NetBSD: uvm_pdaemon.c,v 1.23 2000/08/20 10:24:14 bjh21 Exp $   */
 
-/* 
+/*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
- * Copyright (c) 1991, 1993, The Regents of the University of California.  
+ * Copyright (c) 1991, 1993, The Regents of the University of California.
  *
  * All rights reserved.
  *
@@ -40,17 +40,17 @@
  *
  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
  * All rights reserved.
- * 
+ *
  * Permission to use, copy, modify and distribute this software and
  * its documentation is hereby granted, provided that both the copyright
  * notice and this permission notice appear in all copies of the
  * software, derivative works or modified versions, and any portions
  * thereof, and that both notices appear in supporting documentation.
- * 
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
- * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- * 
+ *
  * Carnegie Mellon requests users of this software to return to
  *
  *  Software Distribution Coordinator  or  [email protected]
@@ -289,7 +289,7 @@ uvm_pageout(void *arg)
                }
 
                if (pma != NULL) {
-                       /* 
+                       /*
                         * XXX If UVM_PMA_FREED isn't set, no pages
                         * were freed.  Should we set UVM_PMA_FAIL in
                         * that case?
@@ -352,8 +352,8 @@ uvm_aiodone_daemon(void *arg)
                        sched_pause(yield);
                }
                uvm_lock_fpageq();
-               wakeup(free <= uvmexp.reserve_kernel ? &uvm.pagedaemon :
-                   &uvmexp.free);
+               wakeup(free <= uvmexp.reserve_kernel ? (void *)&uvm.pagedaemon :
+                   (void *)&uvmexp.free);
                uvm_unlock_fpageq();
        }
 }
@@ -487,7 +487,7 @@ uvmpd_scan_inactive(struct pglist *pglst
                        if (p->pg_flags & PG_CLEAN) {
                                if (p->pg_flags & PQ_SWAPBACKED) {
                                        /* this page now lives only in swap */
-                                       atomic_inc_int(&uvmexp.swpgonly);
+                                       atomic_inc_uint64(&uvmexp.swpgonly);
                                }
 
                                /* zap all mappings with pmap_page_protect... */
@@ -676,7 +676,7 @@ uvmpd_scan_inactive(struct pglist *pglst
                 *
                 * note locking semantics of uvm_pager_put with PGO_PDFREECLUST:
                 *  IN: locked: page queues
-                * OUT: locked: 
+                * OUT: locked:
                 *     !locked: pageqs
                 */
 
@@ -990,7 +990,7 @@ uvmpd_drop(struct pglist *pglst)
                        if (p->pg_flags & PG_CLEAN) {
                                if (p->pg_flags & PQ_SWAPBACKED) {
                                        /* this page now lives only in swap */
-                                       atomic_inc_int(&uvmexp.swpgonly);
+                                       atomic_inc_uint64(&uvmexp.swpgonly);
                                }
 
                                /* zap all mappings with pmap_page_protect... */
Index: sys/uvm/uvm_swap.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_swap.c,v
retrieving revision 1.150
diff -u -p -r1.150 uvm_swap.c
--- sys/uvm/uvm_swap.c  26 Mar 2021 13:40:05 -0000      1.150
+++ sys/uvm/uvm_swap.c  13 Jul 2021 07:42:52 -0000
@@ -1574,14 +1574,14 @@ uvm_swap_get(struct vm_page *page, int s
 
        KERNEL_LOCK();
        /* this page is (about to be) no longer only in swap. */
-       atomic_dec_int(&uvmexp.swpgonly);
+       atomic_dec_uint64(&uvmexp.swpgonly);
 
        result = uvm_swap_io(&page, swslot, 1, B_READ |
            ((flags & PGO_SYNCIO) ? 0 : B_ASYNC));
 
        if (result != VM_PAGER_OK && result != VM_PAGER_PEND) {
                /* oops, the read failed so it really is still only in swap. */
-               atomic_inc_int(&uvmexp.swpgonly);
+               atomic_inc_uint64(&uvmexp.swpgonly);
        }
        KERNEL_UNLOCK();
        return (result);
Index: sys/uvm/uvmexp.h
===================================================================
RCS file: /cvs/src/sys/uvm/uvmexp.h,v
retrieving revision 1.9
diff -u -p -r1.9 uvmexp.h
--- sys/uvm/uvmexp.h    4 Mar 2021 09:00:03 -0000       1.9
+++ sys/uvm/uvmexp.h    13 Jul 2021 07:42:52 -0000
@@ -48,109 +48,128 @@
  */
 struct uvmexp {
        /* vm_page constants */
-       int pagesize;   /* size of a page (PAGE_SIZE): must be power of 2 */
-       int pagemask;   /* page mask */
-       int pageshift;  /* page shift */
+       uint64_t pagesize;   /* size of a page (PAGE_SIZE): must be power of
+                               2 */
+       uint64_t pagemask;   /* page mask */
+       uint64_t pageshift;  /* page shift */
 
        /* vm_page counters */
-       int npages;     /* [I] number of pages we manage */
-       int free;       /* [F] number of free pages */
-       int active;     /* number of active pages */
-       int inactive;   /* number of pages that we free'd but may want back */
-       int paging;     /* number of pages in the process of being paged out */
-       int wired;      /* number of wired pages */
-
-       int zeropages;          /* [F] number of zero'd pages */
-       int reserve_pagedaemon; /* [I] # of pages reserved for pagedaemon */
-       int reserve_kernel;     /* [I] # of pages reserved for kernel */
-       int unused01;           /* formerly anonpages */
-       int vnodepages;         /* XXX # of pages used by vnode page cache */
-       int vtextpages;         /* XXX # of pages used by vtext vnodes */
+       uint64_t npages;     /* [I] number of pages we manage */
+       uint64_t free;       /* [F] number of free pages */
+       uint64_t active;     /* number of active pages */
+       uint64_t inactive;   /* number of pages that we free'd but may want
+                               back */
+       uint64_t paging;     /* number of pages in the process of being paged
+                               out */
+       uint64_t wired;      /* number of wired pages */
+
+       uint64_t zeropages;          /* [F] number of zero'd pages */
+       uint64_t reserve_pagedaemon; /* [I] # of pages reserved for
+                                       pagedaemon */
+       uint64_t reserve_kernel;     /* [I] # of pages reserved for kernel */
+       uint64_t unused01;      /* formerly anonpages */
+       uint64_t vnodepages;    /* XXX # of pages used by vnode page cache */
+       uint64_t vtextpages;    /* XXX # of pages used by vtext vnodes */
 
        /* pageout params */
-       int freemin;    /* min number of free pages */
-       int freetarg;   /* target number of free pages */
-       int inactarg;   /* target number of inactive pages */
-       int wiredmax;   /* max number of wired pages */
-       int anonmin;    /* min threshold for anon pages */
-       int vtextmin;   /* min threshold for vtext pages */
-       int vnodemin;   /* min threshold for vnode pages */
-       int anonminpct; /* min percent anon pages */
-       int vtextminpct;/* min percent vtext pages */
-       int vnodeminpct;/* min percent vnode pages */
+       uint64_t freemin;       /* min number of free pages */
+       uint64_t freetarg;      /* target number of free pages */
+       uint64_t inactarg;      /* target number of inactive pages */
+       uint64_t wiredmax;      /* max number of wired pages */
+       uint64_t anonmin;       /* min threshold for anon pages */
+       uint64_t vtextmin;      /* min threshold for vtext pages */
+       uint64_t vnodemin;      /* min threshold for vnode pages */
+       uint64_t anonminpct;    /* min percent anon pages */
+       uint64_t vtextminpct;   /* min percent vtext pages */
+       uint64_t vnodeminpct;   /* min percent vnode pages */
 
        /* swap */
-       int nswapdev;   /* number of configured swap devices in system */
-       int swpages;    /* [K] number of PAGE_SIZE'ed swap pages */
-       int swpginuse;  /* number of swap pages in use */
-       int swpgonly;   /* [a] number of swap pages in use, not also in RAM */
-       int nswget;     /* number of swap pages moved from disk to RAM */
-       int nanon;      /* XXX number total of anon's in system */
-       int unused05;   /* formerly nanonneeded */
-       int unused06;   /* formerly nfreeanon */
+       uint64_t nswapdev;      /* number of configured swap devices in
+                                  system */
+       uint64_t swpages;       /* [K] number of PAGE_SIZE'ed swap pages */
+       uint64_t swpginuse;     /* number of swap pages in use */
+       uint64_t swpgonly;      /* [a] number of swap pages in use, not also in
+                                  RAM */
+       uint64_t nswget;        /* number of swap pages moved from disk to
+                                  RAM */
+       uint64_t nanon;         /* XXX number total of anon's in system */
+       uint64_t unused05;      /* formerly nanonneeded */
+       uint64_t unused06;      /* formerly nfreeanon */
 
        /* stat counters */
-       int faults;             /* page fault count */
-       int traps;              /* trap count */
-       int intrs;              /* interrupt count */
-       int swtch;              /* context switch count */
-       int softs;              /* software interrupt count */
-       int syscalls;           /* system calls */
-       int pageins;            /* pagein operation count */
+       uint64_t faults;        /* page fault count */
+       uint64_t traps;         /* trap count */
+       uint64_t intrs;         /* interrupt count */
+       uint64_t swtch;         /* context switch count */
+       uint64_t softs;         /* software interrupt count */
+       uint64_t syscalls;      /* system calls */
+       uint64_t pageins;       /* pagein operation count */
                                /* pageouts are in pdpageouts below */
-       int unused07;           /* formerly obsolete_swapins */
-       int unused08;           /* formerly obsolete_swapouts */
-       int pgswapin;           /* pages swapped in */
-       int pgswapout;          /* pages swapped out */
-       int forks;              /* forks */
-       int forks_ppwait;       /* forks where parent waits */
-       int forks_sharevm;      /* forks where vmspace is shared */
-       int pga_zerohit;        /* pagealloc where zero wanted and zero
+       uint64_t unused07;      /* formerly obsolete_swapins */
+       uint64_t unused08;      /* formerly obsolete_swapouts */
+       uint64_t pgswapin;      /* pages swapped in */
+       uint64_t pgswapout;     /* pages swapped out */
+       uint64_t forks;         /* forks */
+       uint64_t forks_ppwait;  /* forks where parent waits */
+       uint64_t forks_sharevm; /* forks where vmspace is shared */
+       uint64_t pga_zerohit;   /* pagealloc where zero wanted and zero
                                   was available */
-       int pga_zeromiss;       /* pagealloc where zero wanted and zero
+       uint64_t pga_zeromiss;  /* pagealloc where zero wanted and zero
                                   not available */
-       int unused09;           /* formerly zeroaborts */
+       uint64_t unused09;      /* formerly zeroaborts */
 
        /* fault subcounters */
-       int fltnoram;   /* number of times fault was out of ram */
-       int fltnoanon;  /* number of times fault was out of anons */
-       int fltnoamap;  /* number of times fault was out of amap chunks */
-       int fltpgwait;  /* number of times fault had to wait on a page */
-       int fltpgrele;  /* number of times fault found a released page */
-       int fltrelck;   /* number of times fault relock called */
-       int fltrelckok; /* number of times fault relock is a success */
-       int fltanget;   /* number of times fault gets anon page */
-       int fltanretry; /* number of times fault retrys an anon get */
-       int fltamcopy;  /* number of times fault clears "needs copy" */
-       int fltnamap;   /* number of times fault maps a neighbor anon page */
-       int fltnomap;   /* number of times fault maps a neighbor obj page */
-       int fltlget;    /* number of times fault does a locked pgo_get */
-       int fltget;     /* number of times fault does an unlocked get */
-       int flt_anon;   /* number of times fault anon (case 1a) */
-       int flt_acow;   /* number of times fault anon cow (case 1b) */
-       int flt_obj;    /* number of times fault is on object page (2a) */
-       int flt_prcopy; /* number of times fault promotes with copy (2b) */
-       int flt_przero; /* number of times fault promotes with zerofill (2b) */
+       uint64_t fltnoram;      /* number of times fault was out of ram */
+       uint64_t fltnoanon;     /* number of times fault was out of anons */
+       uint64_t fltnoamap;     /* number of times fault was out of amap
+                                  chunks */
+       uint64_t fltpgwait;     /* number of times fault had to wait on a
+                                  page */
+       uint64_t fltpgrele;     /* number of times fault found a released
+                                  page */
+       uint64_t fltrelck;      /* number of times fault relock called */
+       uint64_t fltrelckok;    /* number of times fault relock is a success */
+       uint64_t fltanget;      /* number of times fault gets anon page */
+       uint64_t fltanretry;    /* number of times fault retrys an anon get */
+       uint64_t fltamcopy;     /* number of times fault clears "needs copy" */
+       uint64_t fltnamap;      /* number of times fault maps a neighbor anon
+                                  page */
+       uint64_t fltnomap;      /* number of times fault maps a neighbor obj
+                                  page */
+       uint64_t fltlget;       /* number of times fault does a locked
+                                  pgo_get */
+       uint64_t fltget;        /* number of times fault does an unlocked get */
+       uint64_t flt_anon;      /* number of times fault anon (case 1a) */
+       uint64_t flt_acow;      /* number of times fault anon cow (case 1b) */
+       uint64_t flt_obj;       /* number of times fault is on object page
+                                  (2a) */
+       uint64_t flt_prcopy;    /* number of times fault promotes with copy
+                                  (2b) */
+       uint64_t flt_przero;    /* number of times fault promotes with zerofill
+                                  (2b) */
 
        /* daemon counters */
-       int pdwoke;     /* number of times daemon woke up */
-       int pdrevs;     /* number of times daemon rev'd clock hand */
-       int pdswout;    /* number of times daemon called for swapout */
-       int pdfreed;    /* number of pages daemon freed since boot */
-       int pdscans;    /* number of pages daemon scanned since boot */
-       int pdanscan;   /* number of anonymous pages scanned by daemon */
-       int pdobscan;   /* number of object pages scanned by daemon */
-       int pdreact;    /* number of pages daemon reactivated since boot */
-       int pdbusy;     /* number of times daemon found a busy page */
-       int pdpageouts; /* number of times daemon started a pageout */
-       int pdpending;  /* number of times daemon got a pending pagout */
-       int pddeact;    /* number of pages daemon deactivates */
-       int unused11;   /* formerly pdreanon */
-       int unused12;   /* formerly pdrevnode */
-       int unused13;   /* formerly pdrevtext */
+       uint64_t pdwoke;        /* number of times daemon woke up */
+       uint64_t pdrevs;        /* number of times daemon rev'd clock hand */
+       uint64_t pdswout;       /* number of times daemon called for swapout */
+       uint64_t pdfreed;       /* number of pages daemon freed since boot */
+       uint64_t pdscans;       /* number of pages daemon scanned since boot */
+       uint64_t pdanscan;      /* number of anonymous pages scanned by
+                                  daemon */
+       uint64_t pdobscan;      /* number of object pages scanned by daemon */
+       uint64_t pdreact;       /* number of pages daemon reactivated since
+                                  boot */
+       uint64_t pdbusy;        /* number of times daemon found a busy page */
+       uint64_t pdpageouts;    /* number of times daemon started a pageout */
+       uint64_t pdpending;     /* number of times daemon got a pending
+                                  pagout */
+       uint64_t pddeact;       /* number of pages daemon deactivates */
+       uint64_t unused11;      /* formerly pdreanon */
+       uint64_t unused12;      /* formerly pdrevnode */
+       uint64_t unused13;      /* formerly pdrevtext */
 
-       int fpswtch;    /* FPU context switches */
-       int kmapent;    /* number of kernel map entries */
+       uint64_t fpswtch;       /* FPU context switches */
+       uint64_t kmapent;       /* number of kernel map entries */
 };
 
 struct _ps_strings {
Index: usr.bin/systat/engine.c
===================================================================
RCS file: /cvs/src/usr.bin/systat/engine.c,v
retrieving revision 1.29
diff -u -p -r1.29 engine.c
--- usr.bin/systat/engine.c     2 Jul 2021 15:34:16 -0000       1.29
+++ usr.bin/systat/engine.c     13 Jul 2021 07:42:52 -0000
@@ -768,7 +768,7 @@ print_fld_size(field_def *fld, u_int64_t
 }
 
 void
-print_fld_ssdiv(field_def *fld, int64_t size, int d)
+print_fld_ssdiv(field_def *fld, uint64_t size, int d)
 {
        int len;
 
@@ -780,33 +780,33 @@ print_fld_ssdiv(field_def *fld, int64_t 
                return;
 
        tb_start();
-       if (tbprintft("%lld", size) <= len)
+       if (tbprintft("%llu", size) <= len)
                goto ok;
 
        tb_start();
        size /= d;
-       if (tbprintft("%lldK", size) <= len)
+       if (tbprintft("%lluK", size) <= len)
                goto ok;
        if (size == 0)
                goto err;
 
        tb_start();
        size /= d;
-       if (tbprintft("%lldM", size) <= len)
+       if (tbprintft("%lluM", size) <= len)
                goto ok;
        if (size == 0)
                goto err;
 
        tb_start();
        size /= d;
-       if (tbprintft("%lldG", size) <= len)
+       if (tbprintft("%lluG", size) <= len)
                goto ok;
        if (size == 0)
                goto err;
 
        tb_start();
        size /= d;
-       if (tbprintft("%lldT", size) <= len)
+       if (tbprintft("%lluT", size) <= len)
                goto ok;
 
 err:
@@ -819,7 +819,7 @@ ok:
 }
 
 void
-print_fld_ssize(field_def *fld, int64_t size)
+print_fld_ssize(field_def *fld, uint64_t size)
 {
        print_fld_ssdiv(fld, size, 1024);
 }
Index: usr.bin/systat/engine.h
===================================================================
RCS file: /cvs/src/usr.bin/systat/engine.h,v
retrieving revision 1.14
diff -u -p -r1.14 engine.h
--- usr.bin/systat/engine.h     2 Jul 2021 15:34:16 -0000       1.14
+++ usr.bin/systat/engine.h     13 Jul 2021 07:42:52 -0000
@@ -116,8 +116,8 @@ void print_fld_str(field_def *, const ch
 void print_fld_age(field_def *, unsigned int);
 void print_fld_sdiv(field_def *, u_int64_t, int);
 void print_fld_size(field_def *, u_int64_t);
-void print_fld_ssdiv(field_def *, int64_t, int);
-void print_fld_ssize(field_def *, int64_t);
+void print_fld_ssdiv(field_def *, uint64_t, int);
+void print_fld_ssize(field_def *, uint64_t);
 void print_fld_bw(field_def *, double);
 void print_fld_rate(field_def *, double);
 void print_fld_uint(field_def *, unsigned int);
Index: usr.bin/systat/uvm.c
===================================================================
RCS file: /cvs/src/usr.bin/systat/uvm.c,v
retrieving revision 1.5
diff -u -p -r1.5 uvm.c
--- usr.bin/systat/uvm.c        28 Jun 2019 13:35:04 -0000      1.5
+++ usr.bin/systat/uvm.c        13 Jul 2021 07:42:52 -0000
@@ -18,7 +18,8 @@
 
 #include <sys/types.h>
 #include <sys/signal.h>
-#include <sys/sysctl.h>
+/*#include <sys/sysctl.h>*/
+#include "/usr/src/sys/sys/sysctl.h"
 #include <sys/pool.h>
 #include <ctype.h>
 #include <err.h>
@@ -37,22 +38,23 @@ void print_uvm(void);
 int  read_uvm(void);
 int  select_uvm(void);
 
-void print_uvmexp_field(field_def *, field_def *, int *, int *, const char *);
+void print_uvmexp_field(field_def *, field_def *, uint64_t *, uint64_t *,
+    const char *);
 void print_uvmexp_line(int);
 
 struct uvmexp uvmexp;
 struct uvmexp last_uvmexp;
 
 struct uvmline {
-       int     *v1;
-       int     *ov1;
-       char    *n1;
-       int     *v2;
-       int     *ov2;
-       char    *n2;
-       int     *v3;
-       int     *ov3;
-       char    *n3;
+       uint64_t        *v1;
+       uint64_t        *ov1;
+       char            *n1;
+       uint64_t        *v2;
+       uint64_t        *ov2;
+       char            *n2;
+       uint64_t        *v3;
+       uint64_t        *ov3;
+       char            *n3;
 };
 
 struct uvmline uvmline[] = {
@@ -214,8 +216,8 @@ read_uvm(void)
 }
 
 void
-print_uvmexp_field(field_def *fvalue, field_def *fname, int *new, int *old,
-    const char *name)
+print_uvmexp_field(field_def *fvalue, field_def *fname, uint64_t *new,
+    uint64_t *old, const char *name)
 {
        char *uppername;
        size_t len, i;
Index: usr.bin/systat/vmstat.c
===================================================================
RCS file: /cvs/src/usr.bin/systat/vmstat.c,v
retrieving revision 1.91
diff -u -p -r1.91 vmstat.c
--- usr.bin/systat/vmstat.c     28 Jun 2019 13:35:04 -0000      1.91
+++ usr.bin/systat/vmstat.c     13 Jul 2021 07:42:52 -0000
@@ -40,7 +40,8 @@
 #include <sys/proc.h>
 #include <sys/sched.h>
 #include <sys/stat.h>
-#include <sys/sysctl.h>
+/*#include <sys/sysctl.h>*/
+#include "/usr/src/sys/sys/sysctl.h"
 #include <sys/time.h>
 #include <sys/vmmeter.h>
 
@@ -68,6 +69,9 @@ static struct Info {
        uint64_t *intrcnt;
 } s, s1, s2, s3, z;
 
+/* This is for testing only. */
+static int64_t uexpdelta;
+
 static int ncpu;
 
 extern struct _disk    cur;
@@ -315,12 +319,12 @@ labelkre(void)
 }
 
 #define X(fld) {s.fld[i]-=s1.fld[i];}
-#define Y(fld) {s.fld -= s1.fld;}
+#define Y(fld) {uexpdelta = s.fld - s1.fld;}
 #define Z(fld) {s.nchstats.fld -= s1.nchstats.fld;}
 #define PUTRATE(fld, l, c, w) \
        do { \
                Y(fld); \
-               putint((int)((float)s.fld/etime + 0.5), l, c, w); \
+               putint((int)((float)uexpdelta/etime + 0.5), l, c, w); \
        } while (0)
 #define MAXFAIL 5
 
Index: usr.bin/top/machine.c
===================================================================
RCS file: /cvs/src/usr.bin/top/machine.c,v
retrieving revision 1.110
diff -u -p -r1.110 machine.c
--- usr.bin/top/machine.c       26 Aug 2020 16:21:28 -0000      1.110
+++ usr.bin/top/machine.c       13 Jul 2021 07:42:52 -0000
@@ -40,7 +40,8 @@
 #include <sys/proc.h>
 #include <sys/sched.h>
 #include <sys/swap.h>
-#include <sys/sysctl.h>
+/*#include <sys/sysctl.h>*/
+#include "/usr/src/sys/sys/sysctl.h"
 
 #include <stdio.h>
 #include <stdlib.h>
Index: usr.bin/vmstat/vmstat.c
===================================================================
RCS file: /cvs/src/usr.bin/vmstat/vmstat.c,v
retrieving revision 1.150
diff -u -p -r1.150 vmstat.c
--- usr.bin/vmstat/vmstat.c     28 Nov 2019 16:27:26 -0000      1.150
+++ usr.bin/vmstat/vmstat.c     13 Jul 2021 07:42:52 -0000
@@ -36,7 +36,8 @@
 #include <sys/namei.h>
 #include <sys/malloc.h>
 #include <sys/ioctl.h>
-#include <sys/sysctl.h>
+/*#include <sys/sysctl.h>*/
+#include "/usr/src/sys/sys/sysctl.h"
 #include <sys/device.h>
 #include <sys/pool.h>
 #include <sys/sched.h>
@@ -363,19 +364,19 @@ dovmstat(u_int interval, int reps)
                        memset(&total, 0, sizeof(total));
                }
                (void)printf("%2u %3u", total.t_rq - 1, total.t_sl);
-#define        rate(x) ((unsigned)((((unsigned)x) + halfuptime) / uptime)) /* 
round */
-#define pgtok(a) ((a) * ((unsigned int)uvmexp.pagesize >> 10))
-               (void)printf("%5uM %6uM ",
+#define        rate(x) ((uint64_t)(((x) + halfuptime) / uptime)) /* round */
+#define pgtok(a) ((a) * (uvmexp.pagesize >> 10))
+               (void)printf("%5lluM %6lluM ",
                    pgtok(uvmexp.active + uvmexp.swpginuse) / 1024,
                    pgtok(uvmexp.free) / 1024);
-               (void)printf("%4u ", rate(uvmexp.faults - ouvmexp.faults));
-               (void)printf("%3u ", rate(uvmexp.pdreact - ouvmexp.pdreact));
-               (void)printf("%3u ", rate(uvmexp.pageins - ouvmexp.pageins));
-               (void)printf("%3u %3u ",
+               (void)printf("%4llu ", rate(uvmexp.faults - ouvmexp.faults));
+               (void)printf("%3llu ", rate(uvmexp.pdreact - ouvmexp.pdreact));
+               (void)printf("%3llu ", rate(uvmexp.pageins - ouvmexp.pageins));
+               (void)printf("%3llu %3d ",
                    rate(uvmexp.pdpageouts - ouvmexp.pdpageouts), 0);
-               (void)printf("%3u ", rate(uvmexp.pdscans - ouvmexp.pdscans));
+               (void)printf("%3llu ", rate(uvmexp.pdscans - ouvmexp.pdscans));
                dkstats();
-               (void)printf("%4u %5u %4u ",
+               (void)printf("%4llu %5llu %4llu ",
                    rate(uvmexp.intrs - ouvmexp.intrs),
                    rate(uvmexp.syscalls - ouvmexp.syscalls),
                    rate(uvmexp.swtch - ouvmexp.swtch));
@@ -457,13 +458,13 @@ dotimes(void)
                kread(X_UVMEXP, &uvmexp, sizeof(struct uvmexp));
        }
 
-       (void)printf("%u reactivates, %u total time (usec)\n",
+       (void)printf("%llu reactivates, %u total time (usec)\n",
            uvmexp.pdreact, rectime);
        if (uvmexp.pdreact != 0)
-               (void)printf("average: %u usec / reclaim\n",
+               (void)printf("average: %llu usec / reclaim\n",
                    rectime / uvmexp.pdreact);
        (void)printf("\n");
-       (void)printf("%u page ins, %u total time (msec)\n",
+       (void)printf("%llu page ins, %u total time (msec)\n",
            uvmexp.pageins, pgintime / 10);
        if (uvmexp.pageins != 0)
                (void)printf("average: %8.1f msec / page in\n",
@@ -502,49 +503,49 @@ dosum(void)
        }
 
        /* vm_page constants */
-       (void)printf("%11u bytes per page\n", uvmexp.pagesize);
+       (void)printf("%11llu bytes per page\n", uvmexp.pagesize);
 
        /* vm_page counters */
-       (void)printf("%11u pages managed\n", uvmexp.npages);
-       (void)printf("%11u pages free\n", uvmexp.free);
-       (void)printf("%11u pages active\n", uvmexp.active);
-       (void)printf("%11u pages inactive\n", uvmexp.inactive);
-       (void)printf("%11u pages being paged out\n", uvmexp.paging);
-       (void)printf("%11u pages wired\n", uvmexp.wired);
-       (void)printf("%11u pages zeroed\n", uvmexp.zeropages);
-       (void)printf("%11u pages reserved for pagedaemon\n",
+       (void)printf("%11llu pages managed\n", uvmexp.npages);
+       (void)printf("%11llu pages free\n", uvmexp.free);
+       (void)printf("%11llu pages active\n", uvmexp.active);
+       (void)printf("%11llu pages inactive\n", uvmexp.inactive);
+       (void)printf("%11llu pages being paged out\n", uvmexp.paging);
+       (void)printf("%11llu pages wired\n", uvmexp.wired);
+       (void)printf("%11llu pages zeroed\n", uvmexp.zeropages);
+       (void)printf("%11llu pages reserved for pagedaemon\n",
                     uvmexp.reserve_pagedaemon);
-       (void)printf("%11u pages reserved for kernel\n",
+       (void)printf("%11llu pages reserved for kernel\n",
                     uvmexp.reserve_kernel);
 
        /* swap */
-       (void)printf("%11u swap pages\n", uvmexp.swpages);
-       (void)printf("%11u swap pages in use\n", uvmexp.swpginuse);
+       (void)printf("%11llu swap pages\n", uvmexp.swpages);
+       (void)printf("%11llu swap pages in use\n", uvmexp.swpginuse);
 
        /* stat counters */
-       (void)printf("%11u page faults\n", uvmexp.faults);
-       (void)printf("%11u traps\n", uvmexp.traps);
-       (void)printf("%11u interrupts\n", uvmexp.intrs);
-       (void)printf("%11u cpu context switches\n", uvmexp.swtch);
-       (void)printf("%11u fpu context switches\n", uvmexp.fpswtch);
-       (void)printf("%11u software interrupts\n", uvmexp.softs);
-       (void)printf("%11u syscalls\n", uvmexp.syscalls);
-       (void)printf("%11u pagein operations\n", uvmexp.pageins);
-       (void)printf("%11u forks\n", uvmexp.forks);
-       (void)printf("%11u forks where vmspace is shared\n",
+       (void)printf("%11llu page faults\n", uvmexp.faults);
+       (void)printf("%11llu traps\n", uvmexp.traps);
+       (void)printf("%11llu interrupts\n", uvmexp.intrs);
+       (void)printf("%11llu cpu context switches\n", uvmexp.swtch);
+       (void)printf("%11llu fpu context switches\n", uvmexp.fpswtch);
+       (void)printf("%11llu software interrupts\n", uvmexp.softs);
+       (void)printf("%11llu syscalls\n", uvmexp.syscalls);
+       (void)printf("%11llu pagein operations\n", uvmexp.pageins);
+       (void)printf("%11llu forks\n", uvmexp.forks);
+       (void)printf("%11llu forks where vmspace is shared\n",
                     uvmexp.forks_sharevm);
-       (void)printf("%11u kernel map entries\n", uvmexp.kmapent);
-       (void)printf("%11u zeroed page hits\n", uvmexp.pga_zerohit);
-       (void)printf("%11u zeroed page misses\n", uvmexp.pga_zeromiss);
+       (void)printf("%11llu kernel map entries\n", uvmexp.kmapent);
+       (void)printf("%11llu zeroed page hits\n", uvmexp.pga_zerohit);
+       (void)printf("%11llu zeroed page misses\n", uvmexp.pga_zeromiss);
 
        /* daemon counters */
-       (void)printf("%11u number of times the pagedaemon woke up\n",
+       (void)printf("%11llu number of times the pagedaemon woke up\n",
                     uvmexp.pdwoke);
-       (void)printf("%11u revolutions of the clock hand\n", uvmexp.pdrevs);
-       (void)printf("%11u pages freed by pagedaemon\n", uvmexp.pdfreed);
-       (void)printf("%11u pages scanned by pagedaemon\n", uvmexp.pdscans);
-       (void)printf("%11u pages reactivated by pagedaemon\n", uvmexp.pdreact);
-       (void)printf("%11u busy pages found by pagedaemon\n", uvmexp.pdbusy);
+       (void)printf("%11llu revolutions of the clock hand\n", uvmexp.pdrevs);
+       (void)printf("%11llu pages freed by pagedaemon\n", uvmexp.pdfreed);
+       (void)printf("%11llu pages scanned by pagedaemon\n", uvmexp.pdscans);
+       (void)printf("%11llu pages reactivated by pagedaemon\n", 
uvmexp.pdreact);
+       (void)printf("%11llu busy pages found by pagedaemon\n", uvmexp.pdbusy);
 
        if (nlistf == NULL && memf == NULL) {
                size = sizeof(nchstats);

Reply via email to