History log of /netbsd-current/usr.bin/vmstat/vmstat.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.258 09-Sep-2023 ad

uidinfo is an SLIST.


# 1.257 01-Aug-2023 simonb

For vmstat -mW, add a total KB consumed column and widen a couple of
other fields.


Revision tags: netbsd-10-base
# 1.256 23-Oct-2022 simonb

Remove extraneous "d" in a printf format string in UVM history dump
(leftover int format specifier from conversion to FMTd32?).


# 1.255 16-Jul-2022 simonb

When operating on core files or /dev/mem when using the -M option,
use 64-bit math to calculate pool sizes. Fixes overflow errors for
pools larger than 4GB and gives the correct output with "vmstat -m"
for in use, total allocation and utilisation numbers.


# 1.254 16-Jul-2022 simonb

Move the call to getnlist() to after we check if kvm_openfiles(3) succeeded.
Avoids a coredump when called with "vmstat -M /dev/mem".


# 1.253 19-May-2022 simonb

Bump some column widths for "vmstat -mW".


# 1.252 27-Feb-2022 rillig

vmstat: unexport file-scope variable numdisks

There is no need to make this variable externally visible. There are
several more variables in this file that could be unexported, leave
these for someone who knows whether vmstat.c is used by other parts of
the tree as well.

No functional change, OK mrg.


# 1.251 09-Feb-2022 wiz

Fix typo in usage.


# 1.250 09-Feb-2022 mrg

allow the number of disks displayed in the default output
to be controlled.


# 1.249 01-Feb-2022 mrg

when picking which 2 disks to show in the 'vmstat' default output
and they haven't been specified on the command line, pick the two
devices that have had the largest read+write IO bytes count.


# 1.248 27-Nov-2021 rillig

usr.bin: remove unnecessary CONSTCOND, lint no longer needs it

Since 2021-01-31, lint no longer requires a CONSTCOND comment in a
do-while-0 statement since this is a common code pattern, especially in
statement-like macros.


# 1.247 22-Aug-2021 rillig

usr.bin: enable lint checks for most programs in /usr/bin

Previously, lint was only activated for the libraries, but not for the
kernel or userland programs. Activate lint for the programs in /usr/bin
for now, more will follow later.

This only affects builds that set MKLINT=yes.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base
# 1.246 02-Apr-2021 simonb

Drop setgid kmem, simplify nlist setup.


# 1.245 01-Apr-2021 simonb

Use kernel sysctl hashstat collection instead of kmem grovelling
directly. Also GC a few old hash nlist entries that no longer exist.


# 1.244 01-Apr-2021 simonb

Now that ports that use legacy intrcnt interrupt accounting have event
counters to show that data, for the live kernel case just show INTR
events for "vmstat -i".


# 1.243 03-Mar-2021 simonb

For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq. Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.


# 1.242 14-Jun-2020 ad

Remove PG_ZERO. It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


# 1.241 14-Jun-2020 ad

pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

branches: 1.227.2;
when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.257 01-Aug-2023 simonb

For vmstat -mW, add a total KB consumed column and widen a couple of
other fields.


Revision tags: netbsd-10-base
# 1.256 23-Oct-2022 simonb

Remove extraneous "d" in a printf format string in UVM history dump
(leftover int format specifier from conversion to FMTd32?).


# 1.255 16-Jul-2022 simonb

When operating on core files or /dev/mem when using the -M option,
use 64-bit math to calculate pool sizes. Fixes overflow errors for
pools larger than 4GB and gives the correct output with "vmstat -m"
for in use, total allocation and utilisation numbers.


# 1.254 16-Jul-2022 simonb

Move the call to getnlist() to after we check if kvm_openfiles(3) succeeded.
Avoids a coredump when called with "vmstat -M /dev/mem".


# 1.253 19-May-2022 simonb

Bump some column widths for "vmstat -mW".


# 1.252 27-Feb-2022 rillig

vmstat: unexport file-scope variable numdisks

There is no need to make this variable externally visible. There are
several more variables in this file that could be unexported, leave
these for someone who knows whether vmstat.c is used by other parts of
the tree as well.

No functional change, OK mrg.


# 1.251 09-Feb-2022 wiz

Fix typo in usage.


# 1.250 09-Feb-2022 mrg

allow the number of disks displayed in the default output
to be controlled.


# 1.249 01-Feb-2022 mrg

when picking which 2 disks to show in the 'vmstat' default output
and they haven't been specified on the command line, pick the two
devices that have had the largest read+write IO bytes count.


# 1.248 27-Nov-2021 rillig

usr.bin: remove unnecessary CONSTCOND, lint no longer needs it

Since 2021-01-31, lint no longer requires a CONSTCOND comment in a
do-while-0 statement since this is a common code pattern, especially in
statement-like macros.


# 1.247 22-Aug-2021 rillig

usr.bin: enable lint checks for most programs in /usr/bin

Previously, lint was only activated for the libraries, but not for the
kernel or userland programs. Activate lint for the programs in /usr/bin
for now, more will follow later.

This only affects builds that set MKLINT=yes.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base
# 1.246 02-Apr-2021 simonb

Drop setgid kmem, simplify nlist setup.


# 1.245 01-Apr-2021 simonb

Use kernel sysctl hashstat collection instead of kmem grovelling
directly. Also GC a few old hash nlist entries that no longer exist.


# 1.244 01-Apr-2021 simonb

Now that ports that use legacy intrcnt interrupt accounting have event
counters to show that data, for the live kernel case just show INTR
events for "vmstat -i".


# 1.243 03-Mar-2021 simonb

For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq. Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.


# 1.242 14-Jun-2020 ad

Remove PG_ZERO. It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


# 1.241 14-Jun-2020 ad

pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

branches: 1.227.2;
when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.256 23-Oct-2022 simonb

Remove extraneous "d" in a printf format string in UVM history dump
(leftover int format specifier from conversion to FMTd32?).


# 1.255 16-Jul-2022 simonb

When operating on core files or /dev/mem when using the -M option,
use 64-bit math to calculate pool sizes. Fixes overflow errors for
pools larger than 4GB and gives the correct output with "vmstat -m"
for in use, total allocation and utilisation numbers.


# 1.254 16-Jul-2022 simonb

Move the call to getnlist() to after we check if kvm_openfiles(3) succeeded.
Avoids a coredump when called with "vmstat -M /dev/mem".


# 1.253 19-May-2022 simonb

Bump some column widths for "vmstat -mW".


# 1.252 27-Feb-2022 rillig

vmstat: unexport file-scope variable numdisks

There is no need to make this variable externally visible. There are
several more variables in this file that could be unexported, leave
these for someone who knows whether vmstat.c is used by other parts of
the tree as well.

No functional change, OK mrg.


# 1.251 09-Feb-2022 wiz

Fix typo in usage.


# 1.250 09-Feb-2022 mrg

allow the number of disks displayed in the default output
to be controlled.


# 1.249 01-Feb-2022 mrg

when picking which 2 disks to show in the 'vmstat' default output
and they haven't been specified on the command line, pick the two
devices that have had the largest read+write IO bytes count.


# 1.248 27-Nov-2021 rillig

usr.bin: remove unnecessary CONSTCOND, lint no longer needs it

Since 2021-01-31, lint no longer requires a CONSTCOND comment in a
do-while-0 statement since this is a common code pattern, especially in
statement-like macros.


# 1.247 22-Aug-2021 rillig

usr.bin: enable lint checks for most programs in /usr/bin

Previously, lint was only activated for the libraries, but not for the
kernel or userland programs. Activate lint for the programs in /usr/bin
for now, more will follow later.

This only affects builds that set MKLINT=yes.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base
# 1.246 02-Apr-2021 simonb

Drop setgid kmem, simplify nlist setup.


# 1.245 01-Apr-2021 simonb

Use kernel sysctl hashstat collection instead of kmem grovelling
directly. Also GC a few old hash nlist entries that no longer exist.


# 1.244 01-Apr-2021 simonb

Now that ports that use legacy intrcnt interrupt accounting have event
counters to show that data, for the live kernel case just show INTR
events for "vmstat -i".


# 1.243 03-Mar-2021 simonb

For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq. Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.


# 1.242 14-Jun-2020 ad

Remove PG_ZERO. It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


# 1.241 14-Jun-2020 ad

pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

branches: 1.227.2;
when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.255 16-Jul-2022 simonb

When operating on core files or /dev/mem when using the -M option,
use 64-bit math to calculate pool sizes. Fixes overflow errors for
pools larger than 4GB and gives the correct output with "vmstat -m"
for in use, total allocation and utilisation numbers.


# 1.254 16-Jul-2022 simonb

Move the call to getnlist() to after we check if kvm_openfiles(3) succeeded.
Avoids a coredump when called with "vmstat -M /dev/mem".


# 1.253 19-May-2022 simonb

Bump some column widths for "vmstat -mW".


# 1.252 27-Feb-2022 rillig

vmstat: unexport file-scope variable numdisks

There is no need to make this variable externally visible. There are
several more variables in this file that could be unexported, leave
these for someone who knows whether vmstat.c is used by other parts of
the tree as well.

No functional change, OK mrg.


# 1.251 09-Feb-2022 wiz

Fix typo in usage.


# 1.250 09-Feb-2022 mrg

allow the number of disks displayed in the default output
to be controlled.


# 1.249 01-Feb-2022 mrg

when picking which 2 disks to show in the 'vmstat' default output
and they haven't been specified on the command line, pick the two
devices that have had the largest read+write IO bytes count.


# 1.248 27-Nov-2021 rillig

usr.bin: remove unnecessary CONSTCOND, lint no longer needs it

Since 2021-01-31, lint no longer requires a CONSTCOND comment in a
do-while-0 statement since this is a common code pattern, especially in
statement-like macros.


# 1.247 22-Aug-2021 rillig

usr.bin: enable lint checks for most programs in /usr/bin

Previously, lint was only activated for the libraries, but not for the
kernel or userland programs. Activate lint for the programs in /usr/bin
for now, more will follow later.

This only affects builds that set MKLINT=yes.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base
# 1.246 02-Apr-2021 simonb

Drop setgid kmem, simplify nlist setup.


# 1.245 01-Apr-2021 simonb

Use kernel sysctl hashstat collection instead of kmem grovelling
directly. Also GC a few old hash nlist entries that no longer exist.


# 1.244 01-Apr-2021 simonb

Now that ports that use legacy intrcnt interrupt accounting have event
counters to show that data, for the live kernel case just show INTR
events for "vmstat -i".


# 1.243 03-Mar-2021 simonb

For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq. Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.


# 1.242 14-Jun-2020 ad

Remove PG_ZERO. It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


# 1.241 14-Jun-2020 ad

pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

branches: 1.227.2;
when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.253 19-May-2022 simonb

Bump some column widths for "vmstat -mW".


# 1.252 27-Feb-2022 rillig

vmstat: unexport file-scope variable numdisks

There is no need to make this variable externally visible. There are
several more variables in this file that could be unexported, leave
these for someone who knows whether vmstat.c is used by other parts of
the tree as well.

No functional change, OK mrg.


# 1.251 09-Feb-2022 wiz

Fix typo in usage.


# 1.250 09-Feb-2022 mrg

allow the number of disks displayed in the default output
to be controlled.


# 1.249 01-Feb-2022 mrg

when picking which 2 disks to show in the 'vmstat' default output
and they haven't been specified on the command line, pick the two
devices that have had the largest read+write IO bytes count.


# 1.248 27-Nov-2021 rillig

usr.bin: remove unnecessary CONSTCOND, lint no longer needs it

Since 2021-01-31, lint no longer requires a CONSTCOND comment in a
do-while-0 statement since this is a common code pattern, especially in
statement-like macros.


# 1.247 22-Aug-2021 rillig

usr.bin: enable lint checks for most programs in /usr/bin

Previously, lint was only activated for the libraries, but not for the
kernel or userland programs. Activate lint for the programs in /usr/bin
for now, more will follow later.

This only affects builds that set MKLINT=yes.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base
# 1.246 02-Apr-2021 simonb

Drop setgid kmem, simplify nlist setup.


# 1.245 01-Apr-2021 simonb

Use kernel sysctl hashstat collection instead of kmem grovelling
directly. Also GC a few old hash nlist entries that no longer exist.


# 1.244 01-Apr-2021 simonb

Now that ports that use legacy intrcnt interrupt accounting have event
counters to show that data, for the live kernel case just show INTR
events for "vmstat -i".


# 1.243 03-Mar-2021 simonb

For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq. Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.


# 1.242 14-Jun-2020 ad

Remove PG_ZERO. It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


# 1.241 14-Jun-2020 ad

pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

branches: 1.227.2;
when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.252 27-Feb-2022 rillig

vmstat: unexport file-scope variable numdisks

There is no need to make this variable externally visible. There are
several more variables in this file that could be unexported, leave
these for someone who knows whether vmstat.c is used by other parts of
the tree as well.

No functional change, OK mrg.


# 1.251 09-Feb-2022 wiz

Fix typo in usage.


# 1.250 09-Feb-2022 mrg

allow the number of disks displayed in the default output
to be controlled.


# 1.249 01-Feb-2022 mrg

when picking which 2 disks to show in the 'vmstat' default output
and they haven't been specified on the command line, pick the two
devices that have had the largest read+write IO bytes count.


# 1.248 27-Nov-2021 rillig

usr.bin: remove unnecessary CONSTCOND, lint no longer needs it

Since 2021-01-31, lint no longer requires a CONSTCOND comment in a
do-while-0 statement since this is a common code pattern, especially in
statement-like macros.


# 1.247 22-Aug-2021 rillig

usr.bin: enable lint checks for most programs in /usr/bin

Previously, lint was only activated for the libraries, but not for the
kernel or userland programs. Activate lint for the programs in /usr/bin
for now, more will follow later.

This only affects builds that set MKLINT=yes.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base
# 1.246 02-Apr-2021 simonb

Drop setgid kmem, simplify nlist setup.


# 1.245 01-Apr-2021 simonb

Use kernel sysctl hashstat collection instead of kmem grovelling
directly. Also GC a few old hash nlist entries that no longer exist.


# 1.244 01-Apr-2021 simonb

Now that ports that use legacy intrcnt interrupt accounting have event
counters to show that data, for the live kernel case just show INTR
events for "vmstat -i".


# 1.243 03-Mar-2021 simonb

For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq. Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.


# 1.242 14-Jun-2020 ad

Remove PG_ZERO. It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


# 1.241 14-Jun-2020 ad

pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

branches: 1.227.2;
when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.251 09-Feb-2022 wiz

Fix typo in usage.


# 1.250 09-Feb-2022 mrg

allow the number of disks displayed in the default output
to be controlled.


# 1.249 01-Feb-2022 mrg

when picking which 2 disks to show in the 'vmstat' default output
and they haven't been specified on the command line, pick the two
devices that have had the largest read+write IO bytes count.


# 1.248 27-Nov-2021 rillig

usr.bin: remove unnecessary CONSTCOND, lint no longer needs it

Since 2021-01-31, lint no longer requires a CONSTCOND comment in a
do-while-0 statement since this is a common code pattern, especially in
statement-like macros.


# 1.247 22-Aug-2021 rillig

usr.bin: enable lint checks for most programs in /usr/bin

Previously, lint was only activated for the libraries, but not for the
kernel or userland programs. Activate lint for the programs in /usr/bin
for now, more will follow later.

This only affects builds that set MKLINT=yes.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base
# 1.246 02-Apr-2021 simonb

Drop setgid kmem, simplify nlist setup.


# 1.245 01-Apr-2021 simonb

Use kernel sysctl hashstat collection instead of kmem grovelling
directly. Also GC a few old hash nlist entries that no longer exist.


# 1.244 01-Apr-2021 simonb

Now that ports that use legacy intrcnt interrupt accounting have event
counters to show that data, for the live kernel case just show INTR
events for "vmstat -i".


# 1.243 03-Mar-2021 simonb

For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq. Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.


# 1.242 14-Jun-2020 ad

Remove PG_ZERO. It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


# 1.241 14-Jun-2020 ad

pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

branches: 1.227.2;
when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.249 01-Feb-2022 mrg

when picking which 2 disks to show in the 'vmstat' default output
and they haven't been specified on the command line, pick the two
devices that have had the largest read+write IO bytes count.


# 1.248 27-Nov-2021 rillig

usr.bin: remove unnecessary CONSTCOND, lint no longer needs it

Since 2021-01-31, lint no longer requires a CONSTCOND comment in a
do-while-0 statement since this is a common code pattern, especially in
statement-like macros.


# 1.247 22-Aug-2021 rillig

usr.bin: enable lint checks for most programs in /usr/bin

Previously, lint was only activated for the libraries, but not for the
kernel or userland programs. Activate lint for the programs in /usr/bin
for now, more will follow later.

This only affects builds that set MKLINT=yes.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base
# 1.246 02-Apr-2021 simonb

Drop setgid kmem, simplify nlist setup.


# 1.245 01-Apr-2021 simonb

Use kernel sysctl hashstat collection instead of kmem grovelling
directly. Also GC a few old hash nlist entries that no longer exist.


# 1.244 01-Apr-2021 simonb

Now that ports that use legacy intrcnt interrupt accounting have event
counters to show that data, for the live kernel case just show INTR
events for "vmstat -i".


# 1.243 03-Mar-2021 simonb

For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq. Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.


# 1.242 14-Jun-2020 ad

Remove PG_ZERO. It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


# 1.241 14-Jun-2020 ad

pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

branches: 1.227.2;
when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.248 27-Nov-2021 rillig

usr.bin: remove unnecessary CONSTCOND, lint no longer needs it

Since 2021-01-31, lint no longer requires a CONSTCOND comment in a
do-while-0 statement since this is a common code pattern, especially in
statement-like macros.


# 1.247 22-Aug-2021 rillig

usr.bin: enable lint checks for most programs in /usr/bin

Previously, lint was only activated for the libraries, but not for the
kernel or userland programs. Activate lint for the programs in /usr/bin
for now, more will follow later.

This only affects builds that set MKLINT=yes.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base
# 1.246 02-Apr-2021 simonb

Drop setgid kmem, simplify nlist setup.


# 1.245 01-Apr-2021 simonb

Use kernel sysctl hashstat collection instead of kmem grovelling
directly. Also GC a few old hash nlist entries that no longer exist.


# 1.244 01-Apr-2021 simonb

Now that ports that use legacy intrcnt interrupt accounting have event
counters to show that data, for the live kernel case just show INTR
events for "vmstat -i".


# 1.243 03-Mar-2021 simonb

For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq. Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.


# 1.242 14-Jun-2020 ad

Remove PG_ZERO. It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


# 1.241 14-Jun-2020 ad

pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

branches: 1.227.2;
when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.247 22-Aug-2021 rillig

usr.bin: enable lint checks for most programs in /usr/bin

Previously, lint was only activated for the libraries, but not for the
kernel or userland programs. Activate lint for the programs in /usr/bin
for now, more will follow later.

This only affects builds that set MKLINT=yes.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base
# 1.246 02-Apr-2021 simonb

Drop setgid kmem, simplify nlist setup.


# 1.245 01-Apr-2021 simonb

Use kernel sysctl hashstat collection instead of kmem grovelling
directly. Also GC a few old hash nlist entries that no longer exist.


# 1.244 01-Apr-2021 simonb

Now that ports that use legacy intrcnt interrupt accounting have event
counters to show that data, for the live kernel case just show INTR
events for "vmstat -i".


# 1.243 03-Mar-2021 simonb

For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq. Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.


# 1.242 14-Jun-2020 ad

Remove PG_ZERO. It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


# 1.241 14-Jun-2020 ad

pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

branches: 1.227.2;
when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.246 02-Apr-2021 simonb

Drop setgid kmem, simplify nlist setup.


# 1.245 01-Apr-2021 simonb

Use kernel sysctl hashstat collection instead of kmem grovelling
directly. Also GC a few old hash nlist entries that no longer exist.


# 1.244 01-Apr-2021 simonb

Now that ports that use legacy intrcnt interrupt accounting have event
counters to show that data, for the live kernel case just show INTR
events for "vmstat -i".


# 1.243 03-Mar-2021 simonb

For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq. Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.


# 1.242 14-Jun-2020 ad

Remove PG_ZERO. It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


# 1.241 14-Jun-2020 ad

pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

branches: 1.227.2;
when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.245 01-Apr-2021 simonb

Use kernel sysctl hashstat collection instead of kmem grovelling
directly. Also GC a few old hash nlist entries that no longer exist.


# 1.244 01-Apr-2021 simonb

Now that ports that use legacy intrcnt interrupt accounting have event
counters to show that data, for the live kernel case just show INTR
events for "vmstat -i".


# 1.243 03-Mar-2021 simonb

For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq. Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.


# 1.242 14-Jun-2020 ad

Remove PG_ZERO. It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


# 1.241 14-Jun-2020 ad

pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

branches: 1.227.2;
when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.243 03-Mar-2021 simonb

For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq. Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.


# 1.242 14-Jun-2020 ad

Remove PG_ZERO. It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


# 1.241 14-Jun-2020 ad

pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

branches: 1.227.2;
when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.242 14-Jun-2020 ad

Remove PG_ZERO. It worked brilliantly on x86 machines from the mid-90s but
having spent an age experimenting with it over the last 6 months on various
machines and with different use cases it's always either break-even or a
slight net loss for me.


# 1.241 14-Jun-2020 ad

pool_cache:

- make all counters per-CPU and make cache layer do its work with atomic ops.
- conserve memory by caching empty groups globally.


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.240 11-Jun-2020 ad

Counter tweaks:

- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one(). It has no users and doesn't save a whole lot.
For the cheap option, give cpu_count_sync() a boolean parameter indicating
that a cached value is okay, and rate limit the updates for cached values
to hz.


Revision tags: phil-wifi-20200421 phil-wifi-20200411 phil-wifi-20200406
# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


Revision tags: is-mlppp-base
# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.239 23-Mar-2020 ad

ncs_collisions is gone.


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.238 22-Mar-2020 ad

Process concurrent page faults on individual uvm_objects / vm_amaps in
parallel, where the relevant pages are already in-core. Proposed on
tech-kern.

Temporarily disabled on MP architectures with __HAVE_UNLOCKED_PMAP until
adjustments are made to their pmaps.


# 1.237 22-Mar-2020 ad

- nchash is gone.
- Report new namecache stats.


# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.236 25-Jan-2020 simonb

Fix alignment of Flags column for vmstat -mW.


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.235 15-Jan-2020 ad

vmstat -s: report new stats:

0 per-cpu stats one synced
7246 per-cpu stats all synced
4092 anon pages possibly dirty
8881 anon pages dirty
0 anon pages clean
68 file pages possibly dirty
0 file pages dirty
2367889 file pages clean


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.234 08-Jan-2020 ad

Show reverse misses too.


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.233 06-Jan-2020 ad

- Report namecache reverse hits with vmstat -s.
- ncvhashtbl is no more.


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.232 04-Jan-2020 mrg

move the time nlist fetches into their own namelist and only
fetch them when necessary. allow for fallback uses of older
time sources if others are not present.

this stops vmstat from exiting if it can't get the addresses
of these time values it often doesn't need (eg, running kernels
use the sysctl method), which has cropped up recently wit the
removal of boottime variable.


a slighly modified version of this patch (modified to handle
the old boottime variable over the new one) works against a
netbsd-9 vmstat in -current too.

XXX: pullup


# 1.231 03-Jan-2020 thorpej

boottime in the kernel is no more. Instead, read timebasebin and convert
from bintime to timespec.


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.230 27-Dec-2019 msaitoh

s/sucess/success/ in comment.


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.229 22-Dec-2019 ad

Have vmstat -H report on vcache_hashtab.


Revision tags: phil-wifi-20191119
# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-0-RC1 netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.228 13-Sep-2019 christos

Expose struct namecache.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.227 09-May-2019 mrg

when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2; 1.224.4;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.227 09-May-2019 mrg

when dumping a kernhist history replace "%s" with "%p" so that the
kernhist in kernel can be a little more usable without making the
userland dumping code crash.


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.226 30-Apr-2019 simonb

Use PRWORD for printing -m/-mW totals so fields don't run in to each other.

While here, update field widths for 'vmstat -mW' for modern machines.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.225 13-Dec-2018 sevan

typo


Revision tags: pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.224 04-Dec-2017 mrg

branches: 1.224.2;
deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.224 04-Dec-2017 mrg

deref the right address to get the pool_allocator.


# 1.223 03-Dec-2017 mrg

remove now wrong comment. minor KNF.


# 1.222 03-Dec-2017 mrg

fix the kvm version of counting pool pages for vmstat -s.


# 1.221 02-Dec-2017 mrg

add two new members to uvmexp_sysctl{}: bootpages and poolpages.
bootpages is set to the pages allocated via uvm_pageboot_alloc().
poolpages is calculated from the list of pools nr_pages members.

this brings us closer to having a valid total of pages known by
the system, vs actual pages originally managed.

XXX: poolpages needs some handling for PR_RECURSIVE pools still.


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.220 03-Nov-2017 pgoyette

Remove the ABI version-and-length check that was recently introduced;
sysctl(9) ABIs should be stable across versions.

XXX Pull-up to -8


# 1.219 28-Oct-2017 pgoyette

Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.218 06-Sep-2017 mlelstv

Don't print "nan" when there is no disk activity.


Revision tags: perseant-stdc-iso10646-base
# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

branches: 1.216.6;
"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


# 1.217 04-Jul-2017 mlelstv

Use I/O timestamps to compute disk statistics for better precision.

Disk statistics are collected in a fixed size array, that got corrupted
when a disk was detached. Adapt by skipping entries of detached disks
and detect reused disknames at the array end.


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320 bouyer-socketcan-base pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


Revision tags: pgoyette-localcount-20170107
# 1.216 05-Jan-2017 ryo

"vmstat -ie[v]" auto fit to minimum columns

Reviewed by msaitoh@


# 1.215 05-Jan-2017 pgoyette

Adapt to use of bintime(9) for kernel history timestamps (7.99.55).


# 1.214 04-Jan-2017 pgoyette

Fix error handling confusion between error and errno


# 1.213 04-Jan-2017 pgoyette

Adapt to new version of the sysctl export structure


# 1.212 02-Jan-2017 pgoyette

Use appropriate PRI* format specifiers for fixed-bit-size numbers

Should fix i386 build.


# 1.211 02-Jan-2017 pgoyette

For kvm-based kernhist code, print size of history table and "next free"
pointer, same as we do for sysctl-based code.


# 1.210 02-Jan-2017 pgoyette

Restore the kvm-grovelling code for use on crash files (where sysctl(3)
is not available). Otherwise, this would always report on the current
running kernel regardless of the use of -M option.


# 1.209 02-Jan-2017 pgoyette

For kernel history display, replace the kvm grovelling with the newly
available sysctl access to the history data.

XXX vmstat still uses kvm for several other displays


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).


Revision tags: pgoyette-localcount-20161104
# 1.208 04-Oct-2016 christos

No point in using float here; makes evbmips64 need __truncdfsf2, and that
causes static linking issues because of softfloat.


Revision tags: localcount-20160914
# 1.207 05-Sep-2016 sevan

Drop main() prototype.


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.206 24-Dec-2014 dennis

branches: 1.206.2;
Update stats-keeping in sys/kern/vfs_cache.c to remove (most)
races while allowing consistent lockless sampling of the per-cpu
statistics without atomic operations. Update comment describing
the locking protocol to include this.

These files were fumble-fingered out of the last commit.


# 1.205 12-Sep-2014 skrll

Trailing whitespace.


# 1.204 12-Sep-2014 skrll

Print the cpu in the kernhist record.


Revision tags: netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.203 12-Jul-2014 nakayama

branches: 1.203.2;
Use u_long to avoid negative value outputs.


# 1.202 14-Jun-2014 joerg

Init summary counters.


# 1.201 14-Jun-2014 joerg

Fix format string for ILP32.


# 1.200 13-Jun-2014 joerg

Use kern.pool for the live system.


# 1.199 03-Jun-2014 joerg

GC left-over kread.


# 1.198 03-Jun-2014 joerg

Use CPU statistics from uvmexp when possible.


# 1.197 03-Jun-2014 joerg

Use kern.clockrate if possible.


# 1.196 03-Jun-2014 joerg

Convert the remaining uvmexp users to the sysctl as default source.


# 1.195 03-Jun-2014 joerg

Use vm.uvmexp data as much as possible for vmstat -s.
Temporarily disable shadowing warning until the other users are cleaned
up.


# 1.194 03-Jun-2014 joerg

Provide sysctl for namecache statistics.


# 1.193 02-Jun-2014 joerg

Make missing kern.evcnt an error, don't try to fallback to kmem use.


Revision tags: yamt-pagecache-base9
# 1.192 08-May-2014 hannken

Add a global vnode cache:

- vcache_get() retrieves a referenced and initialised vnode / fs node pair.
- vcache_remove() removes a vnode / fs node pair from the cache.

On cache miss vcache_get() calls new vfs operation vfs_loadvnode() to
initialise a vnode / fs node pair. This call is guaranteed exclusive,
no other thread will try to load this vnode / fs node pair.

Convert ufs/ext2fs, ufs/ffs and ufs/mfs to use this interface.

Remove now unused ufs/ufs_ihash

Discussed on tech-kern.

Welcome to 6.99.41


Revision tags: riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3
# 1.191 19-Feb-2014 dsl

branches: 1.191.2;
Remove some pointless inclusions os sys/user.h


# 1.190 24-Nov-2013 rmind

Remove cpu_queue (and thus eleminate another use of CIRCLEQ) by replacing
its uses with cpu_infos array. Extra testing by christos@.


# 1.189 10-Nov-2013 mrg

add a row with totals for some pool statistics.


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6 yamt-pagecache-base5
# 1.188 29-Apr-2012 para

branches: 1.188.2;
remove malloc(9) output function from vmstat
it is not required and working any more


Revision tags: yamt-pagecache-base4
# 1.187 20-Mar-2012 matt

Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-1-5-RELEASE netbsd-6-1-4-RELEASE netbsd-6-0-5-RELEASE netbsd-6-1-3-RELEASE netbsd-6-0-4-RELEASE netbsd-6-1-2-RELEASE netbsd-6-0-3-RELEASE netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.186 15-Oct-2011 christos

branches: 1.186.2;
use warn instead of perror.


# 1.185 15-Oct-2011 christos

unbreak -f -H -h, etc, part 1
- get nlist once in the beginning and fix the flags. Not each time! It is
not like the kernel will change it symbols in the middle of the run.


# 1.184 21-Sep-2011 jym

Use __arraycount(), as done above.


# 1.183 06-Sep-2011 joerg

Mark usage as static and __dead.


# 1.182 26-Jul-2011 yamt

dopoolcache: don't print unused caches unless verbose


Revision tags: cherry-xenmp-base
# 1.181 17-May-2011 mrg

move and rename the uvm history code out of uvm_stat to "kernhist".

rename "UVMHIST" option to enable the uvm histories.

TODO:
- make UVMHIST properly depend upon KERNHIST
- enable dynamic registration of histories. this is mostly just
allocating something in a bitmap, and is only for viewing multiple
histories in a merged form.


tested on amd64 and sparc64.


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 1.180 16-Feb-2011 nakayama

Fix header, format and total count of system interrupt counters.


# 1.179 05-Feb-2011 mlelstv

dosum also needs getnlist


# 1.178 31-Jan-2011 christos

deal with detecting the first and last cpu differently.


# 1.177 31-Jan-2011 matt

Make sure to getnlist in dovmstat


# 1.176 29-Jan-2011 matt

Defer nlist processing until we know we need to it. If everything can be
obtained via sysctl, we can skip it entirely. This means we can run even
if not setgid.

getuptime will now use sysctl/clock_gettime if memf is NULL.
doevcnt now sues sysctl(kern.evcnt) is memf is NULL. It falls back to
groveling if sysctl returns an error of ENOENT.
dointr will call doevcnt to evcnt based intr stats.


Revision tags: matt-mips64-premerge-20101231
# 1.175 25-Dec-2010 christos

branches: 1.175.2;
can't play games with structure names since cpu_data refers to cpu_info, so
provide our own copy for everything.


# 1.174 25-Dec-2010 christos

use a local definition of cpu_info if we have __HAVE_CPU_DATA_FIRST


# 1.173 25-Dec-2010 christos

Don't crash on old kernels that don't have the new per cpu counters.


# 1.172 24-Dec-2010 enami

We still need to update ouvmexp to output the differene from
previous iteration.


# 1.171 20-Dec-2010 christos

make this work with the per-cpu counters.


# 1.170 18-Oct-2010 christos

simplify and modernize:
- make sysctl mibs static
- use warn/warnx for warnings
makes binary 4K smaller.


# 1.169 07-Jul-2010 pooka

Make "i" unsigned to mirror change to struct uvm_history


# 1.168 05-Apr-2010 he

Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic()
calls for under- and overflow of the ks_active members under
DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h
and not sys/param.h, as the latter caused build problems.

Ride the kernel revision bump of my previous change.


# 1.167 05-Apr-2010 he

Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:

Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3

Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.

While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)

This was discussed with and somewhat hestitantly OKed by rmind@


Revision tags: matt-premerge-20091211
# 1.166 21-Oct-2009 rmind

Remove uarea swap-out functionality:

- Addresses the issue described in PR/38828.
- Some simplification in threading and sleepq subsystems.
- Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
- Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
- Avoids few scans on LWP list and thus potentially long holds of proc_lock.
- Cuts ~1.5k lines of code. Reduces amd64 kernel size by ~4k.
- Removes __SWAP_BROKEN cases.

Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
acorn26 (thanks to <bjh21>).

Discussed on <tech-kern>, reviewed by <ad>.


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.165 18-Jan-2009 lukem

fix -Wsign-compare issues


# 1.164 28-Nov-2008 dholland

Add missing fflush() in one of three places that print stuff repeatedly
every so often. PR 32836 from Takuro KUBOTA.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2
# 1.163 22-Oct-2008 matt

branches: 1.163.6;
NFS hash tables no longer exist.


Revision tags: wrstuden-revivesa-base-3 wrstuden-revivesa-base-2
# 1.162 20-Aug-2008 he

Restore the "pages actige" and "pages inactive" value printouts
in "vmstat -s" output when run on the active kernel.

The reason we can't easily provide these values out of a crash
dump, is that these fields are no longer proper members of
struct uvmexp, but rather are estimated by and dependent on
the currently active page replacement policy in the kernel.


# 1.161 21-Jul-2008 lukem

Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.


# 1.160 24-Jun-2008 he

Fix alignment of fields for "vmstat -m" when KMEMSTATS are available:
o Make "prop dictionary" fit in the "Type" coloumn
o Ensure that fields don't run into each other (adds a space between fields)
o Ensure that a Limit of >100000K fits in the field width


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.159 04-Jun-2008 ad

vmstat -s: report cpu pagealloc hits/misses.


Revision tags: yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2
# 1.158 28-Apr-2008 martin

branches: 1.158.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-base hpcarm-cleanup-base
# 1.157 26-Dec-2007 ad

branches: 1.157.4;
Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.


# 1.156 20-Dec-2007 ad

- Support two different sizes of pool_cache group. The default has 14 or 15
items, and the new large groups (for busy caches) have 62 or 63 items.
- Add PR_LARGECACHE flag as a hint that a pool_cache should use large groups.
This should be eventually be tuned at runtime.
- Report group size for vmstat -C.


Revision tags: cube-autoconf-base
# 1.155 05-Dec-2007 yamt

add -C to usage.


# 1.154 07-Nov-2007 ad

Add -C option to display pool_cache info, eg:

Pool cache statistics.
Name Spin Full Empty PoolLayer CacheLayer Hit% CpuLayer Hit%
pipepl 0 1 3 385 42862 99.1 985780 95.7
fdescpl 0 0 2 310 31133 99.0 1029620 97.0
cwdipl 0 0 2 310 31227 99.0 1029714 97.0
filepl 0 1 4 680 141415 99.5 24011135 99.4


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase wrstuden-fixsa-base-1 netbsd-4-0-RELEASE netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-mips64-base wrstuden-fixsa-base netbsd-4-base
# 1.153 17-Oct-2006 christos

branches: 1.153.8;
warns=4, pass lint.


# 1.152 16-Oct-2006 christos

use howmany(), instead of open-coding the calculation.


# 1.151 27-Sep-2006 yamt

increase a chance to fit within 80 char width consoles.
- use PRWORD for dovmstat as well.
- reduce number of drives shown by default from 3 to 2.


# 1.150 15-Sep-2006 yamt

sync with kernel after yamt-pdpolicy merge.


# 1.149 15-Aug-2006 kardel

PR 34205: workaround struct timeval tv_sec not being SUS compliant issue (reported by Takeshi Nakayama)


Revision tags: abandoned-netbsd-4-base
# 1.148 21-Jul-2006 simonb

branches: 1.148.2;
Dump some column widths.


# 1.147 09-Jul-2006 kardel

accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)


# 1.146 08-Jul-2006 yamt

include evcnt.h rather than device.h.


Revision tags: chap-midi-nbase chap-midi-base
# 1.145 07-Jun-2006 kardel

support timecounters (struct time gone, use time_second then)


Revision tags: simonb-timecounters-base
# 1.144 02-May-2006 christos

branches: 1.144.2;
Coverity CID 884: Avoid NULL deref.


# 1.143 02-May-2006 christos

Coverity CID 885: Avoid NULL deref.


# 1.142 02-May-2006 christos

Coverity CID 886: Avoid NULL deref.


# 1.141 27-Apr-2006 simonb

Unwrap a not too long line.


# 1.140 14-Apr-2006 blymn

Update statistics reporting to use new kernel framework, rename dkstats*
to a more generic name since it no longer just deals with disk.


# 1.139 05-Feb-2006 dsl

Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().
Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.


# 1.138 22-Oct-2005 nonaka

branches: 1.138.2;
Don't forget original allocated memory address.


# 1.137 02-Oct-2005 chs

optimize pool_caches similarly to how I optimized pools before:
split the single list of pool cache groups into three lists:
completely full, partially full, and completely empty.
use LIST instead of TAILQ where appropriate.


# 1.136 07-Aug-2005 blymn

Add support for tape statistics.


# 1.135 02-Jun-2005 lukem

appease gcc -Wuninitialized


# 1.134 30-May-2005 chs

rename "kbucket" to "kmembuckets", for greater clarity.
don't forget to update vmstat this time.


# 1.133 22-May-2005 chs

do not rely on the pre-evcnt interrupt counter kernel symbols being present.
if they do not exist, then interrupt stats are all in evcnts.


# 1.132 15-May-2005 yamt

remove anon related statistics which are no longer used.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.131 10-Mar-2005 wiz

Add -t to usage.


# 1.130 10-Mar-2005 he

Add a '-t' option to print the contents of the vmtotal structure,
possibly repeatedly.


# 1.129 26-Feb-2005 dsl

WARNS=3


# 1.128 30-Jan-2005 simonb

Remove a blank line.


# 1.127 26-Jan-2005 wiz

Sync with manpage (add -W, sort).


# 1.126 26-Jan-2005 simonb

Add a "wide" mode output (selected with -W) to show more information
about memory pools, including pool page size, flags and utilisation.


# 1.125 20-Dec-2004 dsainty

Correct typo in an error message: allocatior -> allocator


# 1.124 05-Nov-2004 dsl

Add (unsigned char) cast to ctype functions


# 1.123 15-Oct-2004 enami

Make vmstat -s prints:
- uvmexp.pdre{anon,file,exec}.
- real number of namecache stats.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.122 28-Feb-2004 junyoung

pidhash and pgrphash should have been removed from here as well when the
new pid allocator was committed 3/2003.


# 1.121 13-Feb-2004 wiz

Uppercase CPU, plural is CPUs.


# 1.120 22-Jan-2004 dbj

fixes to keep default output under 80 columns
reduce default number of disks to 3 from 4
adjust widths of cpu stats if one of them is 100%
always put spaces between # of processes runnable (from pr 12691)


# 1.119 28-Sep-2003 simonb

Extra columns appeared in one line of the "Memory statistics by type"
header in '94 and '97. Grow the other line a little so that it looks
pretty again.


# 1.118 19-Sep-2003 itojun

realloc pedant


# 1.117 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.116 15-Jul-2003 itojun

snprintf


# 1.115 02-Jul-2003 simonb

No need to cast the third argument of ioctl() to "char *".


# 1.114 11-Jun-2003 drochner

no need to #include <sys/dkstat.h>


# 1.113 06-May-2003 dsl

Make vmstat -m skip memory pools that have never been used - unless -v given.
Update man page to match.


# 1.112 09-Apr-2003 thorpej

Update for cached physical addresses in the pool caches.


# 1.111 19-Mar-2003 dsl

Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.


# 1.110 01-Feb-2003 matt

The last NULL entry should not be printed on missing symbols.


# 1.109 01-Feb-2003 thorpej

Update for extensible malloc types.


Revision tags: fvdl_fs64_base
# 1.108 12-Dec-2002 atatat

The -u option takes an argument, so we need the corresponding : in the
getopt() string. Does no one use uvm histories any more, or does
everyone just dump all the histories?


# 1.107 22-Nov-2002 simonb

Remove pc532-only hacks to access wildly different interrupt accounting
now that interrupts are tracked with evcnt(9) on this port.


# 1.106 21-Nov-2002 simonb

Include <machine/intr.h> to get "struct iv" (in pc532-specific code).


# 1.105 18-Nov-2002 nathanw

In getuptime(), use kread() to get the current time as well as boottime,
instead of calling time(3).

This makes rate calculations of crash dumps sensible; in contrast,
subtracting the boot time of the crash dump from the current time of the
running system produces a not-very-meaningful number.


# 1.104 01-Nov-2002 mrg

iostat(8) and systat(8) support for separate read/write disk statistics.
"iostat -x" now shows these (ala linux/solaris), but this is only splitting
the read/write bytes/transactions, not adding any new metrics. "systat
iostat" now has two new commands to switch between combined/separate mode
for both it's numbers & bar modes.


# 1.103 18-Sep-2002 mycroft

sleep() -> nanosleep()


# 1.102 10-Aug-2002 soren

Print newline before pool stats.


# 1.101 30-Jun-2002 sommerfeld

Since the KERN_CP_TIME sysctl reports total clock ticks across all
cpus and hz is measured in ticks per cpu, divide tick count by ncpu to
determine elapsed time since last sample.

Fixes I/O rate deflation observed on multiprocessors.


Revision tags: netbsd-1-6-base
# 1.100 13-Mar-2002 simonb

branches: 1.100.2;
Don't provide a local declaration of 'struct pool_cache_group' now that
it's in <sys/pool.h>.


# 1.99 11-Mar-2002 enami

Fix broken indentation.


# 1.98 10-Mar-2002 christos

fix pool_allocator fallout. bad boy jason!


# 1.97 20-Feb-2002 enami

Don't forget to fetch pool cache group.


# 1.96 20-Feb-2002 enami

When printing pool stats, print pool cache stats also if -v is given.


# 1.95 28-Jan-2002 simonb

Use the new disk and tty stats sysctls when operating on a live kernel,
dk*() don't need to worry about setgid() games anymore.


# 1.94 09-Dec-2001 chs

replace "vnode" and "vtext" with "file" and "exec" in uvmexp field names.


# 1.93 06-Dec-2001 lukem

print average chain length as %8.2f instead of %8d


# 1.92 29-Nov-2001 thorpej

KERNBASE is a constant that kernland has no business using; it's
existence and value are machine-dependent, and using KERNBASE
either breaks binary compatibility across the same MACHINE_ARCH
or prevents this program from compiling at all.


# 1.91 26-Nov-2001 jmc

Cast the printf'ing of the 2 size_t vars in dohashstat to unsigned long long as
some ports have size_t's which are larger than int's.


# 1.90 26-Nov-2001 lukem

- Separate hashstat namelist into separate hashnl[], and don't barf if
some of the symbols can't be found
- Only kvm_nlist() hashnl[] and histnl[] once
- Add a description to struct kernel_hash, and print with -L
- Sort entries in khashes[]
- Don't exit on unknown hashes; just display a warning and move on


# 1.89 26-Nov-2001 lukem

add stats for nchash & ncvhash


# 1.88 26-Nov-2001 lukem

- Use -H (instead of -h) to list all hash stats.
- Add '-h hashname' to only list the stats for hashname.
- Add -L to list valid hashes
- Fix up some whitespace


# 1.87 26-Nov-2001 lukem

- replace -h uvmhist with -u uvmhist, and -H with -U, since uvm history stuff
isn't generally enabled by default, and i wanted -h for something else.
- implement -h, which displays statistics for various kernel hash tables
- add deref_kptr(), which does the hard work of kvm_read() et al
- various minor cleanups


# 1.86 21-Nov-2001 enami

Check array boundary correctly.


# 1.85 21-Nov-2001 enami

Print evcnt/intrcnt as unsigned.


# 1.84 07-Oct-2001 bjh21

When summarizing pool memory usage, account for PR_RECURSIVE pools
specially so as to avoid counting the same memory twice.


# 1.83 26-Aug-2001 matt

Adjust vmstat -i / -e for wider event names


# 1.82 13-Jun-2001 lukem

when printing "avm fre" fields, use " %5ld %5ld " instead of "%6ld%6ld ",
because it's better to slightly right-shift the display than run numbers
together when you've got > 99999KB avm or fre.


# 1.81 02-May-2001 thorpej

Move the number of page colors to the top of the display.


# 1.80 01-May-2001 thorpej

Add the number of page colors to uvmexp.


# 1.79 29-Apr-2001 thorpej

Print print color bucket hit/miss stats.


# 1.78 05-Apr-2001 jhawk

Make -c and -w work properly when printing non-default statistics.


# 1.77 09-Mar-2001 simonb

Show number of pages used by executables now that they're are counted
by UVM.


# 1.76 27-Jan-2001 enami

Prevent integer overflow.


# 1.75 27-Jan-2001 enami

Cosmetic changes.


# 1.74 01-Dec-2000 simonb

Don't "extern" variables and function in dkstats.c, declare them in
dkstats.h instead.


# 1.73 30-Nov-2000 simonb

ANSIfy.


# 1.72 30-Nov-2000 simonb

Use a better description for the vnode page cache pages.


# 1.71 30-Nov-2000 simonb

Show anonpages and vnodepages in "vmstat -s".


# 1.70 28-Sep-2000 sommerfeld

Move cpu header right 3 spaces to match grouping in man page


# 1.69 23-Sep-2000 enami

Make vmstat -m to put at least one space between each numbers.


# 1.68 21-Sep-2000 thorpej

Display number of zero page aborts.


# 1.67 29-Jun-2000 mrg

remove include of <vm/vm.h>


Revision tags: netbsd-1-5-ALPHA2 netbsd-1-5-base
# 1.66 04-Jun-2000 cgd

branches: 1.66.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).


# 1.65 04-Jun-2000 itojun

cp_time is no longer available in the kernel.
remove it from namelist[] to make vmstat work.


# 1.64 04-Jun-2000 perry

include sys/sched.h to get definition of CPUSTATES


Revision tags: minoura-xpg4dl-base
# 1.63 24-Apr-2000 thorpej

branches: 1.63.2;
Print the zero page statistics.


# 1.62 14-Apr-2000 simonb

Don't declare 'extern opt*' getopt variables.


# 1.61 27-Mar-2000 kleink

Cast timeval members to types we know the printf conversions of.


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.60 05-Dec-1999 fredb

More fallout from CL* purge.


Revision tags: comdex-fall-1999-base
# 1.59 02-Nov-1999 soren

Make pool output fit in 80 columns on most machines.


# 1.58 30-Oct-1999 thorpej

This program has to use KVM alrady, so use that to read uvmexp, rather
than sysctl. This can now read VM stats from crash dumps.


Revision tags: netbsd-1-4-PATCH003 netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.57 31-Mar-1999 thorpej

branches: 1.57.4;
Define __POOL_EXPOSE to get at the guts of the pool descriptor.


# 1.56 24-Mar-1999 mrg

completely remove Mach VM support. all that is left is the all the
header files as UVM still uses (most of) these.


# 1.55 12-Feb-1999 kleink

<sys/fcntl.h> -> <fcntl.h>


# 1.54 11-Jan-1999 thorpej

Nuke all mentions of vmstat -t. PR #6433, Geoff Wing.


# 1.53 10-Aug-1998 perry

bzero->memset, bcopy->memcpy, bcmp->memcmp


# 1.52 01-Aug-1998 thorpej

Display the number of idle pages per pool.


# 1.51 27-Jul-1998 pk

Print memory pool statistics.


# 1.50 26-Jul-1998 mycroft

const poisoning.


# 1.49 19-Jul-1998 drochner

Fix handling of privileges - the gid was given up before dkinit()
was called.
Pass the gid to use for KVM access explicitely to dkinit(), the caller
decides whether to call setgid(getgid()) or not.


# 1.48 06-Jul-1998 mrg

- change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places


# 1.47 05-Jul-1998 mrg

KNF.


# 1.46 05-Mar-1998 mrg

use the uvmexp.pageins member for "pi".


# 1.45 13-Feb-1998 thorpej

Add support for listing and dumping UVM history buffers.


# 1.44 09-Feb-1998 mrg

print almost all of uvmexp with -s. do pagein/pageout counts correctly.
also include freed pages count (that was missing from mach vm, but present
in the "output" but hard coded to 0 in vmstat.c.


# 1.43 07-Feb-1998 mrg

print out the contents of uvmexp for "vmstat -s"


# 1.42 07-Feb-1998 mrg

flesh out standard vmstat output with UVM.


# 1.41 07-Feb-1998 mrg

GC old old old "NEWVM". make run under UVM, if not report everything yet..


# 1.40 04-Jan-1998 thorpej

Revive the -f option: report fork statistics.


# 1.39 01-Nov-1997 lukem

getopt returns -1 not EOF


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.38 20-Oct-1997 mrg

WARNSify; deprecate register; fix some broken fprintf() statements found from WARNS.


# 1.37 18-Oct-1997 mrg

merge lite-2.


# 1.36 10-Apr-1997 is

Repair the formatting of the by-memory-type table of "vmstat -m"
("MSDOSFS mount" is too big for %12s).
Note that this breaks naive parser scripts, but they would not parse
the earlier "MSDOSFS mount" line correctly, anyway.


# 1.35 10-Apr-1997 is

"undefined" -> "undef/%d" for memory type names. Similar, but not identical
to Ken Raeburns proposal from PR 1012, herewith closed.


# 1.34 22-Feb-1997 thorpej

If kmem stats are not being gathered by the kernel, print a useful
message to that effect. Fixes PR #3187, submitted by
Guenther Grau <s_grau@ira.uka.de> (fix by me).


# 1.33 29-Nov-1996 thorpej

Compute `halfuptime' correctly when `uptime' == 1.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2944.


# 1.32 25-Nov-1996 cgd

print all evcnt structures, not just those which have the name "intr".
Printing only those with the name "intr" is too restrictive, because it
means that devices can only have one interrupt, which makes little
sense for many devices and absolutely no sense for several common busses.


# 1.31 08-Aug-1996 mycroft

Remove straggling references to dk_ndrive and dk_xfer.


# 1.30 05-Jun-1996 cgd

the kernel 'boottime' variable is a timeval. copy it out of kernel
memory as such (not as a time_t).


Revision tags: netbsd-1-2-base
# 1.29 10-May-1996 thorpej

branches: 1.29.4;
New userland code to read the statistics kept by the NetBSD generic
disk framework, from John M. Vinopal <banshee@gabriella.resort.com>


# 1.28 04-Apr-1996 cgd

update for the fact that 'allevents' is now a TAILQ.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.27 10-Oct-1995 cgd

print interrupt names in 14 cols. really should be dynamic.


# 1.26 08-Oct-1995 cgd

don't forget to accumulate interrupt counts found via allevents.


# 1.25 08-Oct-1995 cgd

fix spacing problem in interrupt/total/rate output line of vmstat -i


# 1.24 24-Sep-1995 phil

For the pc532, get struct iv from the protected part of <machine/psl.h>.


# 1.23 27-Aug-1995 phil

pc532 specific interrupt code. (From Matthias Pfaller.)


# 1.22 27-Jun-1995 jtc

sys/signal.h -> signal.h


# 1.21 07-May-1995 cgd

fix up RCS ids


# 1.20 29-Apr-1995 cgd

cast pointers to longs, not ints.


# 1.19 17-Apr-1995 ragge

VAX machine dependent defs removed.


# 1.18 14-Mar-1995 pk

Make use of the new kernel event counters; from Theo.


# 1.17 24-Dec-1994 cgd

size is a size_t!


# 1.16 06-Oct-1994 mycroft

Fix RCS id format.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.15 13-May-1994 cgd

re-enable new bucket foo, also widen type name field by one for miscfs mount


# 1.14 11-May-1994 cgd

rcsids


# 1.13 11-May-1994 cgd

clean up import. also, stub read_names for the i386, and comment out
some refs to kmem stats fields that we don't have yet. This will need
hacking, (1) for the various ports, (2) for the kmem stuff, and won't
work completely right until those happen, and until the new vm system
is integrated.


# 1.12 15-Apr-1994 cgd

clean, exported variable (and contents) changes


# 1.11 13-Mar-1994 cgd

fix to work with new config. SCSI device name support is totally hosed.


# 1.10 06-Dec-1993 cgd

get rid of __386BSD__ and replace as appropriate with __NetBSD__ and i386


# 1.9 10-Nov-1993 deraadt

some nice new things


# 1.8 02-Oct-1993 cgd

widen "Type" field of vmstat -m by 2 characters


# 1.7 23-Aug-1993 cgd

make various vm counters part of the "standard" nlist (for mw)


# 1.6 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.5 06-Jun-1993 cgd

clean up interrupt count printing a bit...


# 1.4 25-May-1993 cgd

fix dependencies on M_LAST's old off-by-one error...
(arguably, the old error wasn't an error, but, given some
of the old usage of M_LAST and its name, i say it was)


# 1.3 21-May-1993 cgd

add rcs ids, and update for "arch"


# 1.2 04-May-1993 deraadt

iostat and vmstat being taught about drives..


Revision tags: netbsd-0-8 netbsd-alpha-1
# 1.1 09-Apr-1993 cgd

branches: 1.1.1;
added, from net/2 (patch 124).