From abial@korin.warman.org.pl  Mon Feb  9 02:54:17 1998
Received: from korin.warman.org.pl (korin.nask.waw.pl [148.81.160.10])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id CAA07717
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 9 Feb 1998 02:54:14 -0800 (PST)
          (envelope-from abial@korin.warman.org.pl)
Received: (from abial@localhost)
	by korin.warman.org.pl (8.8.8/8.8.5) id LAA12208;
	Mon, 9 Feb 1998 11:38:45 +0100 (CET)
Message-Id: <199802091038.LAA12208@korin.warman.org.pl>
Date: Mon, 9 Feb 1998 11:38:45 +0100 (CET)
From: abial@nask.pl
Reply-To: abial@nask.pl
To: FreeBSD-gnats-submit@freebsd.org
Subject: sysctl vm.vmmeter - bogus and unsupported (patch incl.)
X-Send-Pr-Version: 3.2

>Number:         5689
>Category:       kern
>Synopsis:       sysctl vm.vmmeter - bogus and unsupported (patch incl.)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    phk
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Feb  9 03:00:01 PST 1998
>Closed-Date:    Fri Jan 10 23:31:02 PST 2003
>Last-Modified:  Fri Jan 10 23:31:02 PST 2003
>Originator:     Andrzej Bialecki
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
Research and Academic Network in Poland
>Environment:

	-current as of today

>Description:

	The oid name for sysctl vm.vmmeter is bogus and misleading. In fact,
	it refers to 'struct vmtotal', and not to the 'struct vmmeter' as its
	name would suggest. Besides, it's silently skipped in sysctl -a
	listing, as there's no specific handler for it.


>How-To-Repeat:

	sysctl vm.vmmeter 		# returns nothing
	sysctl -A|grep vm.vmmeter	# returns Format: S,vmtotal ...

>Fix:
	1. change the name of the oid in /sys/vm/vm_meter.c to the correct
	   one (i.e. vmmeter -> vmtotal)
	2. patch the sysctl(8) to correctly display the values (patch follows).


--- sysctl.c.orig	Tue Nov 18 03:37:45 1997
+++ sysctl.c	Mon Feb  9 08:43:57 1998
@@ -49,6 +49,7 @@
 #include <sys/stat.h>
 #include <sys/sysctl.h>
 #include <sys/resource.h>
+#include <sys/vmmeter.h>
 
 #include <ctype.h>
 #include <err.h>
@@ -242,6 +243,22 @@
 }
 
 static int
+S_vmtotal(int l2, void *p)
+{
+	struct vmtotal *v = (struct vmtotal*)p;
+
+	if (l2 != sizeof *v)
+		err(1, "S_vmtotal %d != %d", l2, sizeof *v);
+
+	printf("\n  procs       virt mem      real mem     shared vm   shared real    free\n");
+	printf(" r d p s    tot    act    tot    act    tot    act    tot    act\n");
+	printf("%2d%2d%2d%2d",v->t_rq,v->t_dw,v->t_pw,v->t_sl);
+	printf("%7d%7d%7d%7d",v->t_vm,v->t_avm,v->t_rm,v->t_arm);
+	printf("%7d%7d%7d%7d%7d",v->t_vmshr,v->t_avmshr,v->t_rmshr,v->t_armshr,v->t_free);
+	return (0);
+}
+
+static int
 S_timeval(int l2, void *p)
 {
 	struct timeval *tv = (struct timeval*)p;
@@ -393,6 +410,7 @@
 		if (!strcmp(fmt, "S,clockinfo"))	func = S_clockinfo;
 		else if (!strcmp(fmt, "S,timeval"))	func = S_timeval;
 		else if (!strcmp(fmt, "S,loadavg"))	func = S_loadavg;
+		else if (!strcmp(fmt, "S,vmtotal"))	func = S_vmtotal;
 		else if (!strcmp(fmt, "T,dev_t"))	func = T_dev_t;
 		if (func) {
 			if (!nflag)

>Release-Note:
>Audit-Trail:

From: abial@nask.pl
To: freebsd-gnats-submit@freebsd.org, abial@nask.pl
Cc:  Subject: Re: kern/5689: sysctl vm.vmmeter - bogus and unsupported (patch incl.)
Date: Tue, 24 Feb 1998 12:48:59 +0100 (CET)

 The patch here is partially bad - in printf's there should be "%hu" insted
 of "%d". Sorry.
 
 Andrzej Bialecki
 
Responsible-Changed-From-To: freebsd-bugs->phk 
Responsible-Changed-By: johan 
Responsible-Changed-When: Thu Aug 10 09:03:24 PDT 2000 
Responsible-Changed-Why:  
Paul, I saw you where committing to this area recently. 
Can you please see if this is still an issue and  
take appropriate action? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=5689 

From: Hiten Pandya <hiten@angelica.unixdaemons.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/5689 sysctl vm.vmmeter - bogus and unsupported
Date: Sun, 8 Dec 2002 13:49:40 -0500

 Here is a new patch; and the kernel side of the changes.  Hopefully,
 there will be committed after/before 5.0 is released, depending on how
 the schedule resolves itself.
 
 %%%
 Index: sbin/sysctl/sysctl.c
 ===================================================================
 RCS file: /home/ncvs/src/sbin/sysctl/sysctl.c,v
 retrieving revision 1.48
 diff -u -r1.48 sysctl.c
 --- sbin/sysctl/sysctl.c	2002/11/12 21:18:21	1.48
 +++ sbin/sysctl/sysctl.c	2002/12/08 14:58:56
 @@ -54,6 +54,7 @@
  #include <sys/resource.h>
  #include <sys/stat.h>
  #include <sys/sysctl.h>
 +#include <sys/vmmeter.h>
  
  #include <ctype.h>
  #include <err.h>
 @@ -323,6 +324,29 @@
  }
  
  static int
 +S_vmtotal(int l2, void *p)
 +{
 +	struct vmtotal *v = (struct vmtotal *)p;
 +
 +	if (l2 != sizeof(*v)) {
 +		warnx("S_vmtotal %d != %d", l2, sizeof(*v));
 +		return (0);
 +	}
 +
 +	printf("\nSystem wide totals computed every five seconds:\n");
 +	printf("===============================================\n");
 +	printf("Processes: (RUNQ:\t %hu Disk Wait: %hu Page Wait: %hu Sleep: %hu)\n",
 +		v->t_rq, v->t_dw, v->t_pw, v->t_sl);
 +	printf("Virtual Memory:\t\t (Total: %hu Active %hu)\n", v->t_vm, v->t_avm);
 +	printf("Real Memory:\t\t (Total: %hu Active %hu)\n", v->t_rm, v->t_arm);
 +	printf("Shared Virtual Memory:\t (Total: %hu Active: %hu)\n", v->t_vmshr, v->t_avmshr);
 +	printf("Shared Real Memory:\t (Total: %hu Active: %hu)\n", v->t_rmshr, v->t_armshr);
 +	printf("Free Memory Pages:\t %hu\n", v->t_free);
 +	
 +	return (0);
 +}
 +
 +static int
  T_dev_t(int l2, void *p)
  {
  	dev_t *d = (dev_t *)p;
 @@ -587,6 +611,8 @@
  			func = S_timeval;
  		else if (strcmp(fmt, "S,loadavg") == 0)
  			func = S_loadavg;
 +		else if (strcmp(fmt, "S,vmtotal") == 0)
 +			func = S_vmtotal;
  		else if (strcmp(fmt, "T,dev_t") == 0)
  			func = T_dev_t;
  		else
 Index: sys/vm/vm_meter.c
 ===================================================================
 RCS file: /home/ncvs/src/sys/vm/vm_meter.c,v
 retrieving revision 1.66
 diff -u -r1.66 vm_meter.c
 --- sys/vm/vm_meter.c	2002/10/02 20:31:47	1.66
 +++ sys/vm/vm_meter.c	2002/12/08 14:59:01
 @@ -222,7 +222,7 @@
  	return(error);
  }
  
 -SYSCTL_PROC(_vm, VM_METER, vmmeter, CTLTYPE_OPAQUE|CTLFLAG_RD,
 +SYSCTL_PROC(_vm, VM_TOTAL, vmtotal, CTLTYPE_OPAQUE|CTLFLAG_RD,
      0, sizeof(struct vmtotal), vmtotal, "S,vmtotal", 
      "System virtual memory statistics");
  SYSCTL_NODE(_vm, OID_AUTO, stats, CTLFLAG_RW, 0, "VM meter stats");
 Index: sys/vm/vm_param.h
 ===================================================================
 RCS file: /home/ncvs/src/sys/vm/vm_param.h,v
 retrieving revision 1.15
 diff -u -r1.15 vm_param.h
 --- sys/vm/vm_param.h	2001/10/10 23:06:54	1.15
 +++ sys/vm/vm_param.h	2002/12/08 14:59:02
 @@ -76,7 +76,7 @@
  /*
   * CTL_VM identifiers
   */
 -#define	VM_METER		1	/* struct vmmeter */
 +#define	VM_TOTAL		1	/* struct vmtotal */
  #define	VM_LOADAVG	 	2	/* struct loadavg */
  #define VM_V_FREE_MIN		3	/* cnt.v_free_min */
  #define VM_V_FREE_TARGET	4	/* cnt.v_free_target */
 @@ -91,7 +91,7 @@
  
  #define CTL_VM_NAMES { \
  	{ 0, 0 }, \
 -	{ "vmmeter", CTLTYPE_STRUCT }, \
 +	{ "vmtotal", CTLTYPE_STRUCT }, \
  	{ "loadavg", CTLTYPE_STRUCT }, \
  	{ "v_free_min", CTLTYPE_INT }, \
  	{ "v_free_target", CTLTYPE_INT }, \
 Index: usr.bin/systat/vmstat.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/systat/vmstat.c,v
 retrieving revision 1.52
 diff -u -r1.52 vmstat.c
 --- usr.bin/systat/vmstat.c	2002/06/06 23:01:50	1.52
 +++ usr.bin/systat/vmstat.c	2002/12/08 14:59:05
 @@ -784,7 +784,7 @@
  
  	size = sizeof(ls->Total);
  	mib[0] = CTL_VM;
 -	mib[1] = VM_METER;
 +	mib[1] = VM_TOTAL;
  	if (sysctl(mib, 2, &ls->Total, &size, NULL, 0) < 0) {
  		error("Can't get kernel info: %s\n", strerror(errno));
  		bzero(&ls->Total, sizeof(ls->Total));
 Index: usr.bin/vmstat/vmstat.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/vmstat/vmstat.c,v
 retrieving revision 1.59
 diff -u -r1.59 vmstat.c
 --- usr.bin/vmstat/vmstat.c	2002/08/09 15:47:43	1.59
 +++ usr.bin/vmstat/vmstat.c	2002/12/08 14:59:07
 @@ -472,7 +472,7 @@
  		kread(X_SUM, &sum, sizeof(sum));
  		size = sizeof(total);
  		mib[0] = CTL_VM;
 -		mib[1] = VM_METER;
 +		mib[1] = VM_TOTAL;
  		if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) {
  			(void)printf("Can't get kerninfo: %s\n",
  				     strerror(errno));
 %%%
 
 Cheers.
 
 -- 
 Hiten Pandya (hiten@unixdaemons.com, hiten@uk.FreeBSD.org)
 http://www.unixdaemons.com/~hiten/
State-Changed-From-To: open->closed 
State-Changed-By: dillon 
State-Changed-When: Fri Jan 10 23:24:31 PST 2003 
State-Changed-Why:  
Committed updated patch from Hiten to -current. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=5689 
>Unformatted:
