Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 May 2017 12:55:27 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        Alan Somers <asomers@freebsd.org>, Gleb Smirnoff <glebius@freebsd.org>, "src-committers@freebsd.org" <src-committers@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "svn-src-head@freebsd.org" <svn-src-head@freebsd.org>
Subject:   Re: svn commit: r317061 - in head: libexec/rpc.rstatd sys/amd64/amd64 sys/amd64/include sys/arm/arm sys/arm/include sys/arm64/include sys/cddl/contrib/opensolaris/uts/common/fs/zfs sys/compat/linprocfs...
Message-ID:  <20170502095527.GB1622@kib.kiev.ua>
In-Reply-To: <20170501163725.U972@besplex.bde.org>
References:  <201704171734.v3HHYlf5022945@repo.freebsd.org> <CAOtMX2jdNj0du0ZuUKPr16iHK_YeNVzf-nDvwC-MuFM003VVAg@mail.gmail.com> <20170419130428.J956@besplex.bde.org> <20170430201324.GV1622@kib.kiev.ua> <20170501163725.U972@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, May 01, 2017 at 06:25:11PM +1000, Bruce Evans wrote:
> XX Index: subr_counter.c
> XX ===================================================================
> XX --- subr_counter.c	(revision 317604)
> XX +++ subr_counter.c	(working copy)
> XX @@ -78,11 +78,15 @@
> XX  sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS)
> XX  {
> XX  	uint64_t out;
> XX +	uint32_t out32;
> XX  	int error;
> XX 
> XX  	out = counter_u64_fetch(*(counter_u64_t *)arg1);
> XX 
> XX -	error = SYSCTL_OUT(req, &out, sizeof(uint64_t));
> XX +	if (req->oldlen == 4 && (out32 = out) == out)
> XX +		error = SYSCTL_OUT(req, &out32, sizeof(out32));
> XX +	else
> XX +		error = SYSCTL_OUT(req, &out, sizeof(out));
> XX 
> XX  	if (error || !req->newptr)
> XX  		return (error);
> 
> This does the minimum necessary to fix the current problem.
> 
> This works until the counters become too large for a u_int.  There
> could be an option to get truncation with no error, but that would
> require an API change, so applications should be required to do the
> truncation for themself if that is what they want.

Yes, this is approximately what I consider to be enough fix, but with
some details which I do not like and which did not worked well on my
test machine with enough memory to generate lot of increments.

Below is what I consider to be good enough.  I will proceed with this
version unless very strong objections appear.

diff --git a/sys/vm/vm_meter.c b/sys/vm/vm_meter.c
index 5f4cd46ab1e..93d5161de89 100644
--- a/sys/vm/vm_meter.c
+++ b/sys/vm/vm_meter.c
@@ -266,8 +266,29 @@ static SYSCTL_NODE(_vm_stats, OID_AUTO, vm, CTLFLAG_RW, 0,
 	"VM meter vm stats");
 SYSCTL_NODE(_vm_stats, OID_AUTO, misc, CTLFLAG_RW, 0, "VM meter misc stats");
 
+static int
+sysctl_handle_vmstat(SYSCTL_HANDLER_ARGS)
+{
+	uint64_t out;
+#ifdef COMPAT_FREEBSD11
+	uint32_t out1;
+#endif
+
+	out = counter_u64_fetch(*(counter_u64_t *)arg1);
+#ifdef COMPAT_FREEBSD11
+	if (req->oldlen == sizeof(uint32_t)) {
+		out1 = 0xffffffff;
+		if (out < out1)
+			out1 = out;
+		return (SYSCTL_OUT(req, &out1, sizeof(uint32_t)));
+	}
+#endif
+	return (SYSCTL_OUT(req, &out, sizeof(uint64_t)));
+}
+
 #define	VM_STATS(parent, var, descr) \
-    SYSCTL_COUNTER_U64(parent, OID_AUTO, var, CTLFLAG_RD, &vm_cnt.var, descr)
+    SYSCTL_OID(parent, OID_AUTO, var, CTLTYPE_U64 | CTLFLAG_MPSAFE | \
+    CTLFLAG_RD, &vm_cnt.var, 0, sysctl_handle_vmstat, "QU", descr);
 #define	VM_STATS_VM(var, descr)		VM_STATS(_vm_stats_vm, var, descr)
 #define	VM_STATS_SYS(var, descr)	VM_STATS(_vm_stats_sys, var, descr)
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170502095527.GB1622>