mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-06 17:18:32 +00:00
- Revert signedness type changes to "struct vmtotal"; by making
them unsigned I made the possible overflows hard to detect, and it only saved 1 bit which isn't principal, even less now that the underlying issue with the total of virtual memory has been fixed. (For the record, it will overflow with >=2T of VM total, with 32-bit ints used to keep counters in pages.) - While here, fix printing of other "struct vmtotal" members such as t_rq, t_dw, t_pw, and t_sw as they are also signed. Reviewed by: bde MFC after: 3 days
This commit is contained in:
parent
983bba070e
commit
bad4d172b4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=164718
|
@ -95,18 +95,14 @@ main(int argc, char *argv[])
|
|||
printf(" procs kB virt mem real mem shared vm shared real free\n");
|
||||
printf(" r w l s tot act tot act tot act tot act\n");
|
||||
}
|
||||
printf("%2hu%2hu%2hu%2hu",v.t_rq-1,v.t_dw+v.t_pw,v.t_sl,v.t_sw);
|
||||
printf("%7lu %7lu %7lu%7lu",
|
||||
(unsigned long)pgtok(v.t_vm),
|
||||
(unsigned long)pgtok(v.t_avm),
|
||||
(unsigned long)pgtok(v.t_rm),
|
||||
(unsigned long)pgtok(v.t_arm));
|
||||
printf("%7lu%7lu%7lu%7lu%7lu\n",
|
||||
(unsigned long)pgtok(v.t_vmshr),
|
||||
(unsigned long)pgtok(v.t_avmshr),
|
||||
(unsigned long)pgtok(v.t_rmshr),
|
||||
(unsigned long)pgtok(v.t_armshr),
|
||||
(unsigned long)pgtok(v.t_free));
|
||||
printf("%2hd%2hd%2hd%2hd",v.t_rq-1,v.t_dw+v.t_pw,v.t_sl,v.t_sw);
|
||||
printf("%7d %7d %7d%7d",
|
||||
pgtok(v.t_vm),pgtok(v.t_avm),
|
||||
pgtok(v.t_rm),pgtok(v.t_arm));
|
||||
printf("%7d%7d%7d%7d%7d\n",
|
||||
pgtok(v.t_vmshr),pgtok(v.t_avmshr),
|
||||
pgtok(v.t_rmshr),pgtok(v.t_armshr),
|
||||
pgtok(v.t_free));
|
||||
sleep(5);
|
||||
i++;
|
||||
if(i>22) i=0;
|
||||
|
|
|
@ -54,7 +54,6 @@ static const char rcsid[] =
|
|||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -392,22 +391,19 @@ S_vmtotal(int l2, void *p)
|
|||
" (values in kilobytes)\n");
|
||||
printf("===============================================\n");
|
||||
printf(
|
||||
"Processes:\t\t(RUNQ: %hu Disk Wait: %hu Page Wait: "
|
||||
"%hu Sleep: %hu)\n",
|
||||
"Processes:\t\t(RUNQ: %hd Disk Wait: %hd Page Wait: "
|
||||
"%hd Sleep: %hd)\n",
|
||||
v->t_rq, v->t_dw, v->t_pw, v->t_sl);
|
||||
printf(
|
||||
"Virtual Memory:\t\t(Total: %juK, Active %juK)\n",
|
||||
(uintmax_t)v->t_vm * pageKilo,
|
||||
(uintmax_t)v->t_avm * pageKilo);
|
||||
printf("Real Memory:\t\t(Total: %juK Active %juK)\n",
|
||||
(uintmax_t)v->t_rm * pageKilo, (uintmax_t)v->t_arm * pageKilo);
|
||||
printf("Shared Virtual Memory:\t(Total: %juK Active: %juK)\n",
|
||||
(uintmax_t)v->t_vmshr * pageKilo,
|
||||
(uintmax_t)v->t_avmshr * pageKilo);
|
||||
printf("Shared Real Memory:\t(Total: %juK Active: %juK)\n",
|
||||
(uintmax_t)v->t_rmshr * pageKilo,
|
||||
(uintmax_t)v->t_armshr * pageKilo);
|
||||
printf("Free Memory Pages:\t%juK\n", (uintmax_t)v->t_free * pageKilo);
|
||||
"Virtual Memory:\t\t(Total: %dK, Active %dK)\n",
|
||||
v->t_vm * pageKilo, v->t_avm * pageKilo);
|
||||
printf("Real Memory:\t\t(Total: %dK Active %dK)\n",
|
||||
v->t_rm * pageKilo, v->t_arm * pageKilo);
|
||||
printf("Shared Virtual Memory:\t(Total: %dK Active: %dK)\n",
|
||||
v->t_vmshr * pageKilo, v->t_avmshr * pageKilo);
|
||||
printf("Shared Real Memory:\t(Total: %dK Active: %dK)\n",
|
||||
v->t_rmshr * pageKilo, v->t_armshr * pageKilo);
|
||||
printf("Free Memory Pages:\t%dK\n", v->t_free * pageKilo);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -191,20 +191,20 @@ vm_paging_needed(void)
|
|||
|
||||
/* systemwide totals computed every five seconds */
|
||||
struct vmtotal {
|
||||
uint16_t t_rq; /* length of the run queue */
|
||||
uint16_t t_dw; /* jobs in ``disk wait'' (neg priority) */
|
||||
uint16_t t_pw; /* jobs in page wait */
|
||||
uint16_t t_sl; /* jobs sleeping in core */
|
||||
uint16_t t_sw; /* swapped out runnable/short block jobs */
|
||||
uint32_t t_vm; /* total virtual memory */
|
||||
uint32_t t_avm; /* active virtual memory */
|
||||
uint32_t t_rm; /* total real memory in use */
|
||||
uint32_t t_arm; /* active real memory */
|
||||
uint32_t t_vmshr; /* shared virtual memory */
|
||||
uint32_t t_avmshr; /* active shared virtual memory */
|
||||
uint32_t t_rmshr; /* shared real memory */
|
||||
uint32_t t_armshr; /* active shared real memory */
|
||||
uint32_t t_free; /* free memory pages */
|
||||
int16_t t_rq; /* length of the run queue */
|
||||
int16_t t_dw; /* jobs in ``disk wait'' (neg priority) */
|
||||
int16_t t_pw; /* jobs in page wait */
|
||||
int16_t t_sl; /* jobs sleeping in core */
|
||||
int16_t t_sw; /* swapped out runnable/short block jobs */
|
||||
int32_t t_vm; /* total virtual memory */
|
||||
int32_t t_avm; /* active virtual memory */
|
||||
int32_t t_rm; /* total real memory in use */
|
||||
int32_t t_arm; /* active real memory */
|
||||
int32_t t_vmshr; /* shared virtual memory */
|
||||
int32_t t_avmshr; /* active shared virtual memory */
|
||||
int32_t t_rmshr; /* shared real memory */
|
||||
int32_t t_armshr; /* active shared real memory */
|
||||
int32_t t_free; /* free memory pages */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -58,7 +58,6 @@ static const char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94";
|
|||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <langinfo.h>
|
||||
#include <nlist.h>
|
||||
#include <paths.h>
|
||||
|
@ -137,8 +136,6 @@ static float cputime(int);
|
|||
static void dinfo(int, int, struct statinfo *, struct statinfo *);
|
||||
static void getinfo(struct Info *);
|
||||
static void putint(int, int, int, int);
|
||||
static void putuint(unsigned, int, int, int);
|
||||
static void putuintmax(uintmax_t, int, int, int);
|
||||
static void putfloat(double, int, int, int, int, int);
|
||||
static void putlongdouble(long double, int, int, int, int, int);
|
||||
static int ucount(void);
|
||||
|
@ -492,20 +489,20 @@ showkre()
|
|||
putfloat(avenrun[2], STATROW, STATCOL + 32, 5, 2, 0);
|
||||
mvaddstr(STATROW, STATCOL + 55, buf);
|
||||
#define pgtokb(pg) ((pg) * (s.v_page_size / 1024))
|
||||
putuintmax(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 7);
|
||||
putuintmax(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 12, 7);
|
||||
putuintmax(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 20, 8);
|
||||
putuintmax(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 29, 8);
|
||||
putuintmax(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 4, 7);
|
||||
putuintmax(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 12, 7);
|
||||
putuintmax(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 20, 8);
|
||||
putuintmax(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 29, 8);
|
||||
putuintmax(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 38, 7);
|
||||
putuint(total.t_rq - 1, PROCSROW + 2, PROCSCOL, 3);
|
||||
putuint(total.t_pw, PROCSROW + 2, PROCSCOL + 4, 3);
|
||||
putuint(total.t_dw, PROCSROW + 2, PROCSCOL + 8, 3);
|
||||
putuint(total.t_sl, PROCSROW + 2, PROCSCOL + 12, 3);
|
||||
putuint(total.t_sw, PROCSROW + 2, PROCSCOL + 16, 3);
|
||||
putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 7);
|
||||
putint(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 12, 7);
|
||||
putint(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 20, 8);
|
||||
putint(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 29, 8);
|
||||
putint(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 4, 7);
|
||||
putint(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 12, 7);
|
||||
putint(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 20, 8);
|
||||
putint(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 29, 8);
|
||||
putint(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 38, 7);
|
||||
putint(total.t_rq - 1, PROCSROW + 2, PROCSCOL, 3);
|
||||
putint(total.t_pw, PROCSROW + 2, PROCSCOL + 4, 3);
|
||||
putint(total.t_dw, PROCSROW + 2, PROCSCOL + 8, 3);
|
||||
putint(total.t_sl, PROCSROW + 2, PROCSCOL + 12, 3);
|
||||
putint(total.t_sw, PROCSROW + 2, PROCSCOL + 16, 3);
|
||||
PUTRATE(v_cow_faults, VMSTATROW, VMSTATCOL + 2, 8 - 2);
|
||||
PUTRATE(v_zfod, VMSTATROW + 1, VMSTATCOL + 2, 8 - 2);
|
||||
PUTRATE(v_ozfod, VMSTATROW + 2, VMSTATCOL, 8);
|
||||
|
@ -518,11 +515,11 @@ showkre()
|
|||
PUTRATE(v_pdwakeups, VMSTATROW + 8, VMSTATCOL, 8);
|
||||
PUTRATE(v_pdpages, VMSTATROW + 9, VMSTATCOL, 8);
|
||||
PUTRATE(v_intrans, VMSTATROW + 10, VMSTATCOL, 8);
|
||||
putuintmax(pgtokb(s.v_wire_count), VMSTATROW + 11, VMSTATCOL, 8);
|
||||
putuintmax(pgtokb(s.v_active_count), VMSTATROW + 12, VMSTATCOL, 8);
|
||||
putuintmax(pgtokb(s.v_inactive_count), VMSTATROW + 13, VMSTATCOL, 8);
|
||||
putuintmax(pgtokb(s.v_cache_count), VMSTATROW + 14, VMSTATCOL, 8);
|
||||
putuintmax(pgtokb(s.v_free_count), VMSTATROW + 15, VMSTATCOL, 8);
|
||||
putint(pgtokb(s.v_wire_count), VMSTATROW + 11, VMSTATCOL, 8);
|
||||
putint(pgtokb(s.v_active_count), VMSTATROW + 12, VMSTATCOL, 8);
|
||||
putint(pgtokb(s.v_inactive_count), VMSTATROW + 13, VMSTATCOL, 8);
|
||||
putint(pgtokb(s.v_cache_count), VMSTATROW + 14, VMSTATCOL, 8);
|
||||
putint(pgtokb(s.v_free_count), VMSTATROW + 15, VMSTATCOL, 8);
|
||||
if (LINES - 1 > VMSTATROW + 16)
|
||||
putint(s.bufspace / 1024, VMSTATROW + 16, VMSTATCOL, 8);
|
||||
PUTRATE(v_vnodein, PAGEROW + 2, PAGECOL + 6, 5);
|
||||
|
@ -696,70 +693,6 @@ putint(n, l, lc, w)
|
|||
addstr(b);
|
||||
}
|
||||
|
||||
static void
|
||||
putuint(n, l, lc, w)
|
||||
unsigned n;
|
||||
int l, lc, w;
|
||||
{
|
||||
int snr;
|
||||
char b[128];
|
||||
|
||||
move(l, lc);
|
||||
#ifdef DEBUG
|
||||
while (w-- > 0)
|
||||
addch('*');
|
||||
return;
|
||||
#endif
|
||||
if (n == 0) {
|
||||
while (w-- > 0)
|
||||
addch(' ');
|
||||
return;
|
||||
}
|
||||
snr = snprintf(b, sizeof(b), "%*u", w, n);
|
||||
if (snr != w)
|
||||
snr = snprintf(b, sizeof(b), "%*uk", w - 1, n / 1000);
|
||||
if (snr != w)
|
||||
snr = snprintf(b, sizeof(b), "%*uM", w - 1, n / 1000000);
|
||||
if (snr != w) {
|
||||
while (w-- > 0)
|
||||
addch('*');
|
||||
return;
|
||||
}
|
||||
addstr(b);
|
||||
}
|
||||
|
||||
static void
|
||||
putuintmax(n, l, lc, w)
|
||||
uintmax_t n;
|
||||
int l, lc, w;
|
||||
{
|
||||
int snr;
|
||||
char b[128];
|
||||
|
||||
move(l, lc);
|
||||
#ifdef DEBUG
|
||||
while (w-- > 0)
|
||||
addch('*');
|
||||
return;
|
||||
#endif
|
||||
if (n == 0) {
|
||||
while (w-- > 0)
|
||||
addch(' ');
|
||||
return;
|
||||
}
|
||||
snr = snprintf(b, sizeof(b), "%*ju", w, n);
|
||||
if (snr != w)
|
||||
snr = snprintf(b, sizeof(b), "%*juk", w - 1, n / 1000);
|
||||
if (snr != w)
|
||||
snr = snprintf(b, sizeof(b), "%*juM", w - 1, n / 1000000);
|
||||
if (snr != w) {
|
||||
while (w-- > 0)
|
||||
addch('*');
|
||||
return;
|
||||
}
|
||||
addstr(b);
|
||||
}
|
||||
|
||||
static void
|
||||
putfloat(f, l, lc, w, d, nz)
|
||||
double f;
|
||||
|
|
|
@ -65,7 +65,6 @@ __FBSDID("$FreeBSD$");
|
|||
#include <devstat.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <kvm.h>
|
||||
#include <limits.h>
|
||||
#include <memstat.h>
|
||||
|
@ -575,11 +574,11 @@ dovmstat(unsigned int interval, int reps)
|
|||
|
||||
fill_vmmeter(&sum);
|
||||
fill_vmtotal(&total);
|
||||
(void)printf("%2u %1u %1u",
|
||||
(void)printf("%2d %1d %1d",
|
||||
total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw);
|
||||
#define vmstat_pgtok(a) ((uintmax_t)(a) * (sum.v_page_size >> 10))
|
||||
#define vmstat_pgtok(a) ((a) * (sum.v_page_size >> 10))
|
||||
#define rate(x) (((x) + halfuptime) / uptime) /* round */
|
||||
(void)printf(" %7ju %6ju ", vmstat_pgtok(total.t_avm),
|
||||
(void)printf(" %7d %6d ", vmstat_pgtok(total.t_avm),
|
||||
vmstat_pgtok(total.t_free));
|
||||
(void)printf("%5lu ",
|
||||
(unsigned long)rate(sum.v_vm_faults - osum.v_vm_faults));
|
||||
|
|
Loading…
Reference in a new issue