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...
Konstantin Belousov
kostikbel at gmail.com
Tue May 2 09:55:35 UTC 2017
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)
More information about the svn-src-head
mailing list