[Midnightbsd-cvs] src [10790] trunk/usr.bin/vmstat/vmstat.c: sync vmstat with freebsd 10

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jun 9 22:53:25 EDT 2018


Revision: 10790
          http://svnweb.midnightbsd.org/src/?rev=10790
Author:   laffer1
Date:     2018-06-09 22:53:24 -0400 (Sat, 09 Jun 2018)
Log Message:
-----------
sync vmstat with freebsd 10

Modified Paths:
--------------
    trunk/usr.bin/vmstat/Makefile
    trunk/usr.bin/vmstat/vmstat.8
    trunk/usr.bin/vmstat/vmstat.c

Property Changed:
----------------
    trunk/usr.bin/vmstat/vmstat.8

Modified: trunk/usr.bin/vmstat/Makefile
===================================================================
--- trunk/usr.bin/vmstat/Makefile	2018-06-10 02:52:54 UTC (rev 10789)
+++ trunk/usr.bin/vmstat/Makefile	2018-06-10 02:53:24 UTC (rev 10790)
@@ -1,5 +1,6 @@
+# $MidnightBSD$
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/vmstat/Makefile 201386 2010-01-02 10:27:05Z ed $
 
 PROG=	vmstat
 MAN=	vmstat.8

Modified: trunk/usr.bin/vmstat/vmstat.8
===================================================================
--- trunk/usr.bin/vmstat/vmstat.8	2018-06-10 02:52:54 UTC (rev 10789)
+++ trunk/usr.bin/vmstat/vmstat.8	2018-06-10 02:53:24 UTC (rev 10790)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 1986, 1993
 .\"	The Regents of the University of California.  All rights reserved.
 .\"
@@ -26,9 +27,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)vmstat.8	8.1 (Berkeley) 6/6/93
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/vmstat/vmstat.8 330047 2018-02-27 01:28:19Z jhb $
 .\"
-.Dd October 21, 2006
+.Dd January 18, 2018
 .Dt VMSTAT 8
 .Os
 .Sh NAME
@@ -37,10 +38,9 @@
 .Sh SYNOPSIS
 .Nm
 .\" .Op Fl fimst
-.Op Fl afHhimPsz
+.Op Fl afHhimoPsz
+.Op Fl M Ar core Op Fl N Ar system
 .Op Fl c Ar count
-.Op Fl M Ar core Op Fl N Ar system
-.Op Fl w Ar wait
 .Op Fl n Ar devs
 .Oo
 .Fl p
@@ -48,7 +48,9 @@
 .Ar type , if , pass
 .Sm on
 .Oc
-.Op Ar disks
+.Op Fl w Ar wait
+.Op Ar disks ...
+.Op wait Op count
 .Sh DESCRIPTION
 The
 .Nm
@@ -91,10 +93,12 @@
 system calls since system startup, and the number of pages of virtual memory
 involved in each.
 .It Fl h
-Changes memory columns into more easily human readable form.  Default if
+Changes memory columns into more easily human readable form.
+The default if
 standard output is a terminal device.
 .It Fl H
-Changes memory columns into straight numbers.  Default if standard output
+Changes memory columns into straight numbers.
+The default if standard output
 is not a terminal device (such as a script).
 .It Fl i
 Report on the number of interrupts taken by each device since system
@@ -116,6 +120,9 @@
 by type.
 .It Fl n
 Change the maximum number of disks to display from the default of 2.
+.It Fl o
+Display a list of virtual memory objects in the system and the resident
+memory used by each object.
 .It Fl P
 Report per-cpu system/user/idle cpu statistics.
 .It Fl p
@@ -214,36 +221,59 @@
 by zone.
 .El
 .Pp
+The
+.Ar wait
+and
+.Ar count
+arguments may be given after their respective flags at any point
+on the command line before the
+.Ar disks
+argument(s), or without their flags, as the final argument(s).
+The latter form is accepted for backwards compatibility, but it is
+preferred to use the forms with
+.Fl w
+and
+.Fl c
+to avoid ambiguity.
+.Pp
 By default,
 .Nm
 displays the following information:
 .Bl -tag -width indent
 .It procs
-Information about the numbers of processes in various states.
+Information about the number of threads in various states:
 .Pp
 .Bl -tag -width indent -compact
 .It r
-in run queue
+running or in run queue
 .It b
 blocked for resources (i/o, paging, etc.)
 .It w
-runnable or short sleeper (< 20 secs) but swapped
+swapped out
 .El
 .It memory
 Information about the usage of virtual and real memory.
-Virtual pages (reported in units of 1024 bytes) are considered active if
-they belong to processes which are running or have run in the last 20
-seconds.
 .Pp
+Mapped virtual memory is a sum of all of the virtual pages belonging
+to mapped virtual memory objects.
+Note that the entire memory object's size is considered mapped even if
+only a subset of the object's pages are currently mapped.
+This statistic is not related to the active page queue which is used to track
+real memory.
+.Pp
 .Bl -tag -width indent -compact
 .It avm
-active virtual pages
+mapped virtual memory
+.Po previously called active in
+.Nm
+output
+.Pc
 .It fre
 size of the free list
 .El
 .It page
 Information about page faults and paging activity.
-These are averaged each five seconds, and given in units per second.
+These are given in units per second.
 .Pp
 .Bl -tag -width indent -compact
 .It flt
@@ -257,11 +287,11 @@
 .It po
 pages paged out
 .It fr
-pages freed per second
+pages freed
 .\" .It de
 .\" anticipated short term memory shortfall
 .It sr
-pages scanned by clock algorithm, per-second
+pages scanned by page daemon
 .El
 .It disks
 Disk operations per second (this field is system dependent).
@@ -290,15 +320,15 @@
 will only display the given devices or the devices matching the pattern,
 and will not randomly select other devices in the system.
 .It faults
-Trap/interrupt rate averages per second over last 5 seconds.
+Trap/interrupt rates per second.
 .Pp
 .Bl -tag -width indent -compact
 .It in
-device interrupts per interval (including clock interrupts)
+device interrupts (including clock interrupts)
 .It sy
-system calls per interval
+system calls
 .It cs
-cpu context switch rate (switches/interval)
+cpu context switches
 .El
 .It cpu
 Breakdown of percentage usage of CPU time.
@@ -307,7 +337,7 @@
 .It us
 user time for normal and low priority processes
 .It sy
-system time
+system and interrupt time
 .It id
 cpu idle
 .El
@@ -323,10 +353,7 @@
 The command:
 .Dl vmstat -w 5
 will print what the system is doing every five
-seconds; this is a good choice of printing interval since this is how often
-some of the statistics are sampled in the system.
-Others vary every second and running the output for a while will make it
-apparent which are recomputed every second.
+seconds.
 .Pp
 The command:
 .Dl vmstat -p da -p cd -w 1


Property changes on: trunk/usr.bin/vmstat/vmstat.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/vmstat/vmstat.c
===================================================================
--- trunk/usr.bin/vmstat/vmstat.c	2018-06-10 02:52:54 UTC (rev 10789)
+++ trunk/usr.bin/vmstat/vmstat.c	2018-06-10 02:53:24 UTC (rev 10790)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1980, 1986, 1991, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -40,7 +41,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/vmstat/vmstat.c 288453 2015-10-01 17:09:20Z jhb $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -53,6 +54,7 @@
 #include <sys/resource.h>
 #include <sys/sysctl.h>
 #include <sys/time.h>
+#include <sys/user.h>
 #include <sys/vmmeter.h>
 #include <sys/pcpu.h>
 
@@ -143,6 +145,7 @@
 #define	TIMESTAT	0x10
 #define	VMSTAT		0x20
 #define ZMEMSTAT	0x40
+#define	OBJSTAT		0x80
 
 static void	cpustats(void);
 static void	pcpustats(int, u_long, int);
@@ -149,6 +152,7 @@
 static void	devstats(void);
 static void	doforkst(void);
 static void	dointr(void);
+static void	doobjstat(void);
 static void	dosum(void);
 static void	dovmstat(unsigned int, int);
 static void	domemstat_malloc(void);
@@ -181,7 +185,7 @@
 	interval = reps = todo = 0;
 	maxshowdevs = 2;
 	hflag = isatty(1);
-	while ((c = getopt(argc, argv, "ac:fhHiM:mN:n:Pp:stw:z")) != -1) {
+	while ((c = getopt(argc, argv, "ac:fhHiM:mN:n:oPp:stw:z")) != -1) {
 		switch (c) {
 		case 'a':
 			aflag++;
@@ -220,6 +224,9 @@
 				errx(1, "number of devices %d is < 0",
 				     maxshowdevs);
 			break;
+		case 'o':
+			todo |= OBJSTAT;
+			break;
 		case 'p':
 			if (devstat_buildmatch(optarg, &matches, &num_matches) != 0)
 				errx(1, "%s", devstat_errbuf);
@@ -289,8 +296,6 @@
 		argv = getdrivedata(argv);
 	}
 
-#define	BACKWARD_COMPATIBILITY
-#ifdef	BACKWARD_COMPATIBILITY
 	if (*argv) {
 		f = atof(*argv);
 		interval = f * 1000;
@@ -297,7 +302,6 @@
 		if (*++argv)
 			reps = atoi(*argv);
 	}
-#endif
 
 	if (interval) {
 		if (!reps)
@@ -313,6 +317,8 @@
 		domemstat_zone();
 	if (todo & SUMSTAT)
 		dosum();
+	if (todo & OBJSTAT)
+		doobjstat();
 #ifdef notyet
 	if (todo & TIMESTAT)
 		dotimes();
@@ -469,6 +475,7 @@
 			ADD_FROM_PCPU(i, v_intr);
 			ADD_FROM_PCPU(i, v_soft);
 			ADD_FROM_PCPU(i, v_vm_faults);
+			ADD_FROM_PCPU(i, v_io_faults);
 			ADD_FROM_PCPU(i, v_cow_faults);
 			ADD_FROM_PCPU(i, v_cow_optim);
 			ADD_FROM_PCPU(i, v_zfod);
@@ -507,6 +514,7 @@
 
 		/* vm */
 		GET_VM_STATS(vm, v_vm_faults);
+		GET_VM_STATS(vm, v_io_faults);
 		GET_VM_STATS(vm, v_cow_faults);
 		GET_VM_STATS(vm, v_cow_optim);
 		GET_VM_STATS(vm, v_zfod);
@@ -648,6 +656,8 @@
 	uptime = getuptime();
 	halfuptime = uptime / 2;
 	rate_adj = 1;
+	ncpus = 1;
+	maxid = 0;
 
 	/*
 	 * If the user stops the program (control-Z) and then resumes it,
@@ -693,7 +703,7 @@
 	}
 	for (hdrcnt = 1;;) {
 		if (!--hdrcnt)
-			printhdr(ncpus, cpumask);
+			printhdr(maxid, cpumask);
 		if (kd != NULL) {
 			if (kvm_getcptime(kd, cur.cp_time) < 0)
 				errx(1, "kvm_getcptime: %s", kvm_geterr(kd));
@@ -744,7 +754,7 @@
 				errx(1, "%s", devstat_errbuf);
 				break;
 			case 1:
-				printhdr(ncpus, cpumask);
+				printhdr(maxid, cpumask);
 				break;
 			default:
 				break;
@@ -813,7 +823,7 @@
 }
 
 static void
-printhdr(int ncpus, u_long cpumask)
+printhdr(int maxid, u_long cpumask)
 {
 	int i, num_shown;
 
@@ -825,7 +835,7 @@
 		(void)printf("disk");
 	(void)printf("   faults         ");
 	if (Pflag) {
-		for (i = 0; i < ncpus; i++) {
+		for (i = 0; i <= maxid; i++) {
 			if (cpumask & (1ul << i))
 				printf("cpu%-2d    ", i);
 		}
@@ -841,8 +851,10 @@
 				     dev_select[i].unit_number);
 	(void)printf("  in   sy   cs");
 	if (Pflag) {
-		for (i = 0; i < ncpus; i++)
-			printf(" us sy id");
+		for (i = 0; i <= maxid; i++) {
+			if (cpumask & (1ul << i))
+				printf(" us sy id");
+		}
 		printf("\n");
 	} else
 		printf(" us sy id\n");
@@ -968,6 +980,7 @@
 	(void)printf("%9u zero fill pages prezeroed\n", sum.v_ozfod);
 	(void)printf("%9u intransit blocking page faults\n", sum.v_intrans);
 	(void)printf("%9u total VM faults taken\n", sum.v_vm_faults);
+	(void)printf("%9u page faults requiring I/O\n", sum.v_io_faults);
 	(void)printf("%9u pages affected by kernel thread creation\n", sum.v_kthreadpages);
 	(void)printf("%9u pages affected by  fork()\n", sum.v_forkpages);
 	(void)printf("%9u pages affected by vfork()\n", sum.v_vforkpages);
@@ -1295,6 +1308,129 @@
 	printf("\n");
 }
 
+static void
+display_object(struct kinfo_vmobject *kvo)
+{
+	const char *str;
+
+	printf("%5jd ", (uintmax_t)kvo->kvo_resident);
+	printf("%5jd ", (uintmax_t)kvo->kvo_active);
+	printf("%5jd ", (uintmax_t)kvo->kvo_inactive);
+	printf("%3d ", kvo->kvo_ref_count);
+	printf("%3d ", kvo->kvo_shadow_count);
+	switch (kvo->kvo_memattr) {
+#ifdef VM_MEMATTR_UNCACHEABLE
+	case VM_MEMATTR_UNCACHEABLE:
+		str = "UC";
+		break;
+#endif
+#ifdef VM_MEMATTR_WRITE_COMBINING
+	case VM_MEMATTR_WRITE_COMBINING:
+		str = "WC";
+		break;
+#endif
+#ifdef VM_MEMATTR_WRITE_THROUGH
+	case VM_MEMATTR_WRITE_THROUGH:
+		str = "WT";
+		break;
+#endif
+#ifdef VM_MEMATTR_WRITE_PROTECTED
+	case VM_MEMATTR_WRITE_PROTECTED:
+		str = "WP";
+		break;
+#endif
+#ifdef VM_MEMATTR_WRITE_BACK
+	case VM_MEMATTR_WRITE_BACK:
+		str = "WB";
+		break;
+#endif
+#ifdef VM_MEMATTR_WEAK_UNCACHEABLE
+	case VM_MEMATTR_WEAK_UNCACHEABLE:
+		str = "UC-";
+		break;
+#endif
+#ifdef VM_MEMATTR_WB_WA
+	case VM_MEMATTR_WB_WA:
+		str = "WB";
+		break;
+#endif
+#ifdef VM_MEMATTR_NOCACHE
+	case VM_MEMATTR_NOCACHE:
+		str = "NC";
+		break;
+#endif
+#ifdef VM_MEMATTR_DEVICE
+	case VM_MEMATTR_DEVICE:
+		str = "DEV";
+		break;
+#endif
+#ifdef VM_MEMATTR_CACHEABLE
+	case VM_MEMATTR_CACHEABLE:
+		str = "C";
+		break;
+#endif
+#ifdef VM_MEMATTR_PREFETCHABLE
+	case VM_MEMATTR_PREFETCHABLE:
+		str = "PRE";
+		break;
+#endif
+	default:
+		str = "??";
+		break;
+	}
+	printf("%-3s ", str);
+	switch (kvo->kvo_type) {
+	case KVME_TYPE_NONE:
+		str = "--";
+		break;
+	case KVME_TYPE_DEFAULT:
+		str = "df";
+		break;
+	case KVME_TYPE_VNODE:
+		str = "vn";
+		break;
+	case KVME_TYPE_SWAP:
+		str = "sw";
+		break;
+	case KVME_TYPE_DEVICE:
+		str = "dv";
+		break;
+	case KVME_TYPE_PHYS:
+		str = "ph";
+		break;
+	case KVME_TYPE_DEAD:
+		str = "dd";
+		break;
+	case KVME_TYPE_SG:
+		str = "sg";
+		break;
+	case KVME_TYPE_UNKNOWN:
+	default:
+		str = "??";
+		break;
+	}
+	printf("%-2s ", str);
+	printf("%-s\n", kvo->kvo_path);
+}
+
+static void
+doobjstat(void)
+{
+	struct kinfo_vmobject *kvo;
+	int cnt, i;
+
+	kvo = kinfo_getvmobject(&cnt);
+	if (kvo == NULL) {
+		warn("Failed to fetch VM object list");
+		return;
+	}
+	printf("%5s %5s %5s %3s %3s %3s %2s %s\n", "RES", "ACT", "INACT",
+	    "REF", "SHD", "CM", "TP", "PATH");
+	for (i = 0; i < cnt; i++)
+		display_object(&kvo[i]);
+	free(kvo);
+}
+
 /*
  * kread reads something from the kernel, given its nlist index.
  */
@@ -1347,7 +1483,7 @@
 usage(void)
 {
 	(void)fprintf(stderr, "%s%s",
-		"usage: vmstat [-afHhimPsz] [-c count] [-M core [-N system]] [-w wait]\n",
-		"              [-n devs] [-p type,if,pass] [disks]\n");
+		"usage: vmstat [-afHhimoPsz] [-M core [-N system]] [-c count] [-n devs]\n",
+		"              [-p type,if,pass] [-w wait] [disks] [wait [count]]\n");
 	exit(1);
 }



More information about the Midnightbsd-cvs mailing list