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) _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"