Make 'sysctl vm.vmtotal' work properly using updated patch from Hiten.
(the patch in the PR was stale). PR: kern/5689 Submitted by: Hiten Pandya <hiten@unixdaemons.com>
This commit is contained in:
parent
42cf585a69
commit
f7550ecf3f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=109097
@ -54,6 +54,7 @@ static const char rcsid[] =
|
|||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
#include <sys/vmmeter.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
@ -322,6 +323,29 @@ S_timeval(int l2, void *p)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
static int
|
||||||
T_dev_t(int l2, void *p)
|
T_dev_t(int l2, void *p)
|
||||||
{
|
{
|
||||||
@ -587,6 +611,8 @@ show_var(int *oid, int nlen)
|
|||||||
func = S_timeval;
|
func = S_timeval;
|
||||||
else if (strcmp(fmt, "S,loadavg") == 0)
|
else if (strcmp(fmt, "S,loadavg") == 0)
|
||||||
func = S_loadavg;
|
func = S_loadavg;
|
||||||
|
else if (strcmp(fmt, "S,vmtotal") == 0)
|
||||||
|
func = S_vmtotal;
|
||||||
else if (strcmp(fmt, "T,dev_t") == 0)
|
else if (strcmp(fmt, "T,dev_t") == 0)
|
||||||
func = T_dev_t;
|
func = T_dev_t;
|
||||||
else
|
else
|
||||||
|
@ -237,7 +237,7 @@ vcnt(SYSCTL_HANDLER_ARGS)
|
|||||||
return(error);
|
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",
|
0, sizeof(struct vmtotal), vmtotal, "S,vmtotal",
|
||||||
"System virtual memory statistics");
|
"System virtual memory statistics");
|
||||||
SYSCTL_NODE(_vm, OID_AUTO, stats, CTLFLAG_RW, 0, "VM meter stats");
|
SYSCTL_NODE(_vm, OID_AUTO, stats, CTLFLAG_RW, 0, "VM meter stats");
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
/*
|
/*
|
||||||
* CTL_VM identifiers
|
* CTL_VM identifiers
|
||||||
*/
|
*/
|
||||||
#define VM_METER 1 /* struct vmmeter */
|
#define VM_TOTAL 1 /* struct vmtotal */
|
||||||
#define VM_LOADAVG 2 /* struct loadavg */
|
#define VM_LOADAVG 2 /* struct loadavg */
|
||||||
#define VM_V_FREE_MIN 3 /* cnt.v_free_min */
|
#define VM_V_FREE_MIN 3 /* cnt.v_free_min */
|
||||||
#define VM_V_FREE_TARGET 4 /* cnt.v_free_target */
|
#define VM_V_FREE_TARGET 4 /* cnt.v_free_target */
|
||||||
@ -91,7 +91,7 @@
|
|||||||
|
|
||||||
#define CTL_VM_NAMES { \
|
#define CTL_VM_NAMES { \
|
||||||
{ 0, 0 }, \
|
{ 0, 0 }, \
|
||||||
{ "vmmeter", CTLTYPE_STRUCT }, \
|
{ "vmtotal", CTLTYPE_STRUCT }, \
|
||||||
{ "loadavg", CTLTYPE_STRUCT }, \
|
{ "loadavg", CTLTYPE_STRUCT }, \
|
||||||
{ "v_free_min", CTLTYPE_INT }, \
|
{ "v_free_min", CTLTYPE_INT }, \
|
||||||
{ "v_free_target", CTLTYPE_INT }, \
|
{ "v_free_target", CTLTYPE_INT }, \
|
||||||
|
@ -784,7 +784,7 @@ getinfo(ls)
|
|||||||
|
|
||||||
size = sizeof(ls->Total);
|
size = sizeof(ls->Total);
|
||||||
mib[0] = CTL_VM;
|
mib[0] = CTL_VM;
|
||||||
mib[1] = VM_METER;
|
mib[1] = VM_TOTAL;
|
||||||
if (sysctl(mib, 2, &ls->Total, &size, NULL, 0) < 0) {
|
if (sysctl(mib, 2, &ls->Total, &size, NULL, 0) < 0) {
|
||||||
error("Can't get kernel info: %s\n", strerror(errno));
|
error("Can't get kernel info: %s\n", strerror(errno));
|
||||||
bzero(&ls->Total, sizeof(ls->Total));
|
bzero(&ls->Total, sizeof(ls->Total));
|
||||||
|
@ -472,7 +472,7 @@ dovmstat(interval, reps)
|
|||||||
kread(X_SUM, &sum, sizeof(sum));
|
kread(X_SUM, &sum, sizeof(sum));
|
||||||
size = sizeof(total);
|
size = sizeof(total);
|
||||||
mib[0] = CTL_VM;
|
mib[0] = CTL_VM;
|
||||||
mib[1] = VM_METER;
|
mib[1] = VM_TOTAL;
|
||||||
if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) {
|
if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) {
|
||||||
(void)printf("Can't get kerninfo: %s\n",
|
(void)printf("Can't get kerninfo: %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
Loading…
Reference in New Issue
Block a user