Re: systat -vm output showing negative total virtual memory



On Thu, Nov 16, 2006 at 11:55:09AM +0100, Ulrich Spoerlein wrote:
Hi all,

this is on a two week old RELENG_6. The machine has 4GB RAM, SMP

CPU: Intel(R) Xeon(TM) CPU 3.00GHz (3012.12-MHz 686-class CPU)
Origin = "GenuineIntel" Id = 0xf43 Stepping = 3
Features=0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUS
H,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE>
Features2=0x641d<SSE3,RSVD2,MON,DS_CPL,CNTX-ID,CX16,<b14>>
AMD Features=0x20100000<NX,LM>
real memory = 3489071104 (3327 MB)
avail memory = 3414265856 (3256 MB)
ACPI APIC Table: <PTLTD APIC >
FreeBSD/SMP: Multiprocessor System Detected: 2 CPUs
cpu0 (BSP): APIC ID: 0
cpu1 (AP): APIC ID: 6


Mem:KB REAL VIRTUAL VN PAGER SWAP PAGER
Tot Share Tot Share Free in out in out
Act 1198620 115040 1480676 289860 153004 count
All 3330652 116920 -956751k 293960 pages

vm.vmtotal has this to say
System wide totals computed every five seconds: (values in kilobytes)
===============================================
Processes: (RUNQ: 3 Disk Wait: 1 Page Wait: 1 Sleep: 40)
Virtual Memory: (Total: 815944K, Active 355288K)
Real Memory: (Total: 2558540K Active 150424K)
Shared Virtual Memory: (Total: 11460K Active: 7856K)
Shared Real Memory: (Total: 6916K Active: 5044K)
Free Memory Pages: 890092K

If my reading of the sys/vm/vm_meter.c code is correct, then
all this is wrong; t_vm, t_avm, t_vmshr, and t_avmshr are all
in bytes (here's a snippet from vm_meter.c):

: totalp->t_vm += object->size;
: totalp->t_rm += object->resident_page_count;
: if (object->flags & OBJ_ACTIVE) {
: totalp->t_avm += object->size;
: totalp->t_arm += object->resident_page_count;
: }
: if (object->shadow_count > 1) {
: /* shared object */
: totalp->t_vmshr += object->size;
: totalp->t_rmshr += object->resident_page_count;
: if (object->flags & OBJ_ACTIVE) {
: totalp->t_avmshr += object->size;
: totalp->t_armshr += object->resident_page_count;
: }
: }

sysctl(8) knows that t_vm is in bytes, but for the other stats
it thinks they are in pages. "systat -vm" thinks they are all
in bytes. Here's a fix:

%%%
Index: sbin/sysctl/sysctl.c
===================================================================
RCS file: /home/ncvs/src/sbin/sysctl/sysctl.c,v
retrieving revision 1.67.2.7
diff -u -p -r1.67.2.7 sysctl.c
--- sbin/sysctl/sysctl.c 8 Sep 2006 09:45:35 -0000 1.67.2.7
+++ sbin/sysctl/sysctl.c 16 Nov 2006 14:51:18 -0000
@@ -395,14 +395,14 @@ S_vmtotal(int l2, void *p)
"%hu Sleep: %hu)\n",
v->t_rq, v->t_dw, v->t_pw, v->t_sl);
printf(
- "Virtual Memory:\t\t(Total: %luK, Active %lldK)\n",
+ "Virtual Memory:\t\t(Total: %luK, Active %luK)\n",
(unsigned long)v->t_vm / 1024,
- (long long)v->t_avm * pageKilo);
+ (unsigned long)v->t_avm / 1024);
printf("Real Memory:\t\t(Total: %lldK Active %lldK)\n",
(long long)v->t_rm * pageKilo, (long long)v->t_arm * pageKilo);
- printf("Shared Virtual Memory:\t(Total: %lldK Active: %lldK)\n",
- (long long)v->t_vmshr * pageKilo,
- (long long)v->t_avmshr * pageKilo);
+ printf("Shared Virtual Memory:\t(Total: %luK Active: %luK)\n",
+ (unsigned long)v->t_vmshr / 1024,
+ (unsigned long)v->t_avmshr / 1024);
printf("Shared Real Memory:\t(Total: %lldK Active: %lldK)\n",
(long long)v->t_rmshr * pageKilo,
(long long)v->t_armshr * pageKilo);
Index: usr.bin/systat/vmstat.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/systat/vmstat.c,v
retrieving revision 1.60.2.1
diff -u -p -r1.60.2.1 vmstat.c
--- usr.bin/systat/vmstat.c 21 Mar 2006 20:49:50 -0000 1.60.2.1
+++ usr.bin/systat/vmstat.c 16 Nov 2006 14:55:32 -0000
@@ -475,12 +475,12 @@ showkre()
#define pgtokb(pg) ((pg) * (s.v_page_size / 1024))
putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 3, 8);
putint(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 11, 8);
- putint(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 19, 9);
- putint(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 28, 9);
+ putint(total.t_avm/1024, MEMROW + 2, MEMCOL + 19, 9);
+ putint(total.t_avmshr/1024, MEMROW + 2, MEMCOL + 28, 9);
putint(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 3, 8);
putint(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 11, 8);
- putint(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 19, 9);
- putint(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 28, 9);
+ putint(total.t_vm/1024, MEMROW + 3, MEMCOL + 19, 9);
+ putint(total.t_vmshr/1024, MEMROW + 3, MEMCOL + 28, 9);
putint(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 37, 8);
putint(total.t_rq - 1, PROCSROW + 1, PROCSCOL + 3, 3);
putint(total.t_pw, PROCSROW + 1, PROCSCOL + 6, 3);
%%%


Cheers,
--
Ruslan Ermilov
ru@xxxxxxxxxxx
FreeBSD committer

Attachment: pgpgff8HZuJi4.pgp
Description: PGP signature



Relevant Pages

  • Next July 27: boot failure(hang) on x86_64 box.
    ... Freeing unused kernel memory: 1360k freed ... ACPI: PM-Timer IO Port: 0x488 ... CPU: L2 Cache: 1024K ... # AX.25 network device drivers ...
    (Linux-Kernel)
  • [PATCH] Document Linuxs memory barriers [try #3]
    ... The attached patch documents the Linux kernel's memory barriers. ... I've tried to get rid of the concept of memory accesses appearing on the bus; ... barring implicit enforcement by the CPU. ...
    (Linux-Kernel)
  • Oops in 2.6.28-rc9 and -rc8 -- mtrr issues / e1000e
    ... Bios 1.04beta did show correct memory sizing in dmidecode, ... I hope this is as simple as me doing something glaringly wrong in the kernel ... DMI present. ... CPU: L2 cache: 6144K ...
    (Linux-Kernel)
  • Re: read vs. mmap (or io vs. page faults)
    ... not fit in main memory, and there are overheads related to the heuristics ... But because the CPU is underutilized, ... reasonably sized user buffer). ... You have to measure the actual overhead to see what the actual cost is. ...
    (freebsd-questions)
  • RE: Excel Limitations??
    ... I doubt that upgrading the hardware on your PC will make any difference ... > Physical Memory ... EXE takes up about 95% of the CPU ...
    (microsoft.public.excel.misc)