Bug 2137 - [vm] systat(1) total vm statistics are bad
Summary: [vm] systat(1) total vm statistics are bad
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 3.0-CURRENT
Hardware: Any Any
: Normal Affects Many People
Assignee: Konstantin Belousov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 1996-12-02 22:00 UTC by Tor Egge
Modified: 2021-01-03 16:31 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tor Egge 1996-12-02 22:00:02 UTC
	Running systat shows bad values for total virtual memory. e.g.
        In this example, it shows 3274676 KB, while it should be 
	                      77316980216 KB.

---- systat output
    3 users    Load  0.18  0.38  0.20                  Mon Dec  2 18:35

Mem:KB    REAL            VIRTUAL                     VN PAGER  SWAP PAGER
        Tot   Share      Tot    Share    Free         in  out     in  out
Act   25168    3984  4143252     4492  329352 count
All  193988    4820  3274676     6664         pages
--- top output
 last pid:   530;  load averages:  0.14,  0.34,  0.20                   18:36:00
50 processes:  2 running, 48 sleeping
CPU states:  1.2% user,  0.0% nice,  1.2% system,  0.0% interrupt, 97.7% idle
Mem: 151M Active, 8728K Inact, 22M Wired, 8345K Buf, 322M Free
Swap: 685M Total, 64K Used, 685M Free
---- vmtotal structure contents
$1 = {t_rq = 2, t_dw = 0, t_pw = 0, t_sl = 21, t_sw = 0, t_vm = -2145615227, 
  t_avm = 1036180, t_rm = 48722, t_arm = 6262, t_vmshr = 1681, 
  t_avmshr = 1516, t_rmshr = 1217, t_armshr = 1109, t_free = 82113}
----

Using 64 bit numbers, counting the same vm objects, the result is 19329245054,
which means 73735 GB total virtual memory.

Fix: 

Use 64 bits arithmetic in showkre() in /usr/src/usr.bin/systat/vmstat.c.
Make space for a 12 digit number showing the total virtual memory.

optional extra change in vmtotal() in /usr/src/sys/vm/vm_meter.c:
	
  By ignoring the objects where object->size == 0x7fffffff, the t_vm field
  in the vmtotal structure will have a low lower value. These objects are of
  type OBJT_VNODE, referencing vnodes of type VBLK and tag VT_UFS, referencing
  inodes for the block devices corresponding to the currently mounted ufs file
  systems. Not ignoring them means adding almost 8192 GB virtual memory for
  each mounted ufs filesystem.

  By ignoring the objects where object->ref_count == 0, you will also 
  reduce the t_vm field somewhat.
How-To-Repeat: 
   run systat.
Comment 1 Poul-Henning Kamp freebsd_committer freebsd_triage 1998-05-25 09:04:10 UTC
State Changed
From-To: open->suspended

Awaiting committer 
Comment 2 Jesper Skriver freebsd_committer freebsd_triage 2001-05-28 00:09:06 UTC
Responsible Changed
From-To: freebsd-bugs->tegge

Originator is now a commit'er himself
Comment 3 Mark Linimon freebsd_committer freebsd_triage 2008-04-25 11:05:48 UTC
Responsible Changed
From-To: tegge->freebsd-bugs

tegge has returned his commit bit for safekeeping.
Comment 4 Enji Cooper freebsd_committer freebsd_triage 2015-11-10 09:01:50 UTC
This is still sadly valid on 11-CURRENT -- please note that the amount of memory shown is negative ~2GB :(...

This affects many people because... having this much memory is commonplace now.

% sysctl hw.physmem
hw.physmem: 3188523008
% systat -vmstat

    6 users    Load  0.38  0.28  0.82                  Nov 10 00:59

Mem:KB    REAL            VIRTUAL                       VN PAGER   SWAP PAGER
        Tot   Share      Tot    Share    Free           in   out     in   out
Act   24340    7768   577584    11968  114780  count
All   27000    7816   -2146M    24652          pages
Comment 5 Pawel Biernacki freebsd_committer freebsd_triage 2017-11-15 13:53:36 UTC
Partial fix was committed in r325852 https://lists.freebsd.org/pipermail/svn-src-head/2017-November/106221.html.

I've separate patches for systat and vmstat that are needed to take advantage of the new struct vmtotal size.  Stay tuned.
Comment 6 commit-hook freebsd_committer freebsd_triage 2017-11-21 19:55:58 UTC
A commit references this bug:

Author: kib
Date: Tue Nov 21 19:55:32 UTC 2017
New revision: 326073
URL: https://svnweb.freebsd.org/changeset/base/326073

Log:
  systat: use and correctly display 64bit counters.

  Following struct vmtotal changes, make systat use and correctly
  display 64-bit counters.  Switch to humanize_number(3) to overcome
  homegrown arithmetics limits in pretty printing large numbers.  Use
  1024 as a divisor for memory fields to make it consistent with other
  tools and users expectations.

  Submitted by:	Pawel Biernacki <pawel.biernacki@gmail.com>
  Sponsored by:	Mysterious Code Ltd.
  PR:	2137
  Differential revision:	https://reviews.freebsd.org/D13105

Changes:
  head/usr.bin/systat/Makefile
  head/usr.bin/systat/vmstat.c
Comment 7 Pawel Biernacki freebsd_committer freebsd_triage 2017-11-23 19:22:35 UTC
Final change has been committed in r326139.  All base system consumers of struct vmtotal are now properly displaying large counters.
Comment 8 Eugene Grosbein freebsd_committer freebsd_triage 2018-02-02 20:13:44 UTC
Fixed over two months ago. No MFC planned.
Comment 9 commit-hook freebsd_committer freebsd_triage 2021-01-03 16:30:41 UTC
A commit in branch stable/11 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=72b42d209ff5b37c615048fb251d7bf9eb276381

commit 72b42d209ff5b37c615048fb251d7bf9eb276381
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2018-11-15 17:25:32 +0000
Commit:     Michael Reifenberger <mr@FreeBSD.org>
CommitDate: 2021-01-03 16:29:50 +0000

    MFC r340361:

    Fix printing of 64-bit counters on 32-bit ppc platforms.

    Several statistic counters are uint64_t values and are printed by systat
    using %lu. This results in displaying wrong numbers. Use PRIu64 instead.
    While there, print variables of size_t using %zd.

    Approved by:            re (gjb@)
    Differential Revision:  https://reviews.freebsd.org/D17838

    (cherry picked from commit 45e9405ea4b05926b22a743237cbfe918206db50)

    systat: use and correctly display 64bit counters.

    Following struct vmtotal changes, make systat use and correctly
    display 64-bit counters.  Switch to humanize_number(3) to overcome
    homegrown arithmetics limits in pretty printing large numbers.  Use
    1024 as a divisor for memory fields to make it consistent with other
    tools and users expectations.

    Submitted by:   Pawel Biernacki <pawel.biernacki@gmail.com>
    Sponsored by:   Mysterious Code Ltd.
    PR:     2137
    Differential revision:  https://reviews.freebsd.org/D13105

    (cherry picked from commit 90dd3e79cc4d721b17c473fdaf3ba3d6d912b138)

    Order declarations alphabetically.
    Match signess of the format and the value.

    Noted by:       bde
    Sponsored by:   The FreeBSD Foundation

    (cherry picked from commit 1b7a3d1f5ffe700203f12654cd01a08a84551b4a)

    MFC r340361, r345804: catch up on systat in head/

    [Neither of these originally mine, but the latter commit referenced
    fixes an -fno-common issue and the former is a bugfix]

    r340361:
    Fix printing of 64-bit counters on 32-bit ppc platforms.

    Several statistic counters are uint64_t values and are printed by systat
    using %lu. This results in displaying wrong numbers. Use PRIu64 instead.
    While there, print variables of size_t using %zd.

    r345804:
    systat -zarc to display disk activities like -vm

    PR:             213310
    (cherry picked from commit a70af2507f720c2d7f56f51a18d358123b4770a5)

    MFC r360919,r360929,r361084:

    Patch systat -zarc to display cumulative rate and round down large numbers by SI units

    Introduce sysputpage() to display large page size with human readable format.
      Using UI units allows to fit larger numbers in columns.
      Stop calling v_page_size - this is a value that doesn't change at runtime.
      Renamed WINDOW *wnd to *wd to avoid conflict with global *wnd variable.
      Use bit-shift to convert page size to byte.

    PR:             237664, 246458
    Submitted by:   ota@j.email.ne.jp

    (cherry picked from commit 65d1fd13ac2182f7ca0c223bb723fba6d780740f)

    MFC r363095:
    Handle device removal and removal+add cases to fix infinity rate.

    PR:             219829
    Submitted by:   ota@j.email.ne.jp
    Reported by:    rezo@live.cn
    Differential Revision:  https://reviews.freebsd.org/D25226

    (cherry picked from commit 7a446028cedb13a0d2004cf6f584291a976392da)

    PR:             219829, 237664, 246458, 213310, 2137

 usr.bin/systat/Makefile       |   4 +-
 usr.bin/systat/devs.c         | 126 ++++++++++++++++++++++--
 usr.bin/systat/devs.h         |  16 ++-
 usr.bin/systat/extern.h       |   7 +-
 usr.bin/systat/fetch.c        |   9 +-
 usr.bin/systat/icmp6.c        |   9 +-
 usr.bin/systat/ifcmds.c       |   2 +
 usr.bin/systat/ifstat.c       | 118 +++++++++++++---------
 usr.bin/systat/iostat.c       |  46 ++++-----
 usr.bin/systat/ip.c           |   7 +-
 usr.bin/systat/ip6.c          |   7 +-
 usr.bin/systat/main.c         |  13 +--
 usr.bin/systat/swap.c         |  17 +++-
 usr.bin/systat/sysput.c (new) | 118 ++++++++++++++++++++++
 usr.bin/systat/systat.1       |   1 +
 usr.bin/systat/systat.h       |   4 +
 usr.bin/systat/tcp.c          |   3 +-
 usr.bin/systat/vmstat.c       | 221 +++++++++++++++---------------------------
 usr.bin/systat/zarc.c         | 124 +++++++++++++++---------
 19 files changed, 548 insertions(+), 304 deletions(-)
Comment 10 commit-hook freebsd_committer freebsd_triage 2021-01-03 16:31:30 UTC
A commit in branch stable/11 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=72b42d209ff5b37c615048fb251d7bf9eb276381

commit 72b42d209ff5b37c615048fb251d7bf9eb276381
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2018-11-15 17:25:32 +0000
Commit:     Michael Reifenberger <mr@FreeBSD.org>
CommitDate: 2021-01-03 16:29:50 +0000

    MFC r340361:

    Fix printing of 64-bit counters on 32-bit ppc platforms.

    Several statistic counters are uint64_t values and are printed by systat
    using %lu. This results in displaying wrong numbers. Use PRIu64 instead.
    While there, print variables of size_t using %zd.

    Approved by:            re (gjb@)
    Differential Revision:  https://reviews.freebsd.org/D17838

    (cherry picked from commit 45e9405ea4b05926b22a743237cbfe918206db50)

    systat: use and correctly display 64bit counters.

    Following struct vmtotal changes, make systat use and correctly
    display 64-bit counters.  Switch to humanize_number(3) to overcome
    homegrown arithmetics limits in pretty printing large numbers.  Use
    1024 as a divisor for memory fields to make it consistent with other
    tools and users expectations.

    Submitted by:   Pawel Biernacki <pawel.biernacki@gmail.com>
    Sponsored by:   Mysterious Code Ltd.
    PR:     2137
    Differential revision:  https://reviews.freebsd.org/D13105

    (cherry picked from commit 90dd3e79cc4d721b17c473fdaf3ba3d6d912b138)

    Order declarations alphabetically.
    Match signess of the format and the value.

    Noted by:       bde
    Sponsored by:   The FreeBSD Foundation

    (cherry picked from commit 1b7a3d1f5ffe700203f12654cd01a08a84551b4a)

    MFC r340361, r345804: catch up on systat in head/

    [Neither of these originally mine, but the latter commit referenced
    fixes an -fno-common issue and the former is a bugfix]

    r340361:
    Fix printing of 64-bit counters on 32-bit ppc platforms.

    Several statistic counters are uint64_t values and are printed by systat
    using %lu. This results in displaying wrong numbers. Use PRIu64 instead.
    While there, print variables of size_t using %zd.

    r345804:
    systat -zarc to display disk activities like -vm

    PR:             213310
    (cherry picked from commit a70af2507f720c2d7f56f51a18d358123b4770a5)

    MFC r360919,r360929,r361084:

    Patch systat -zarc to display cumulative rate and round down large numbers by SI units

    Introduce sysputpage() to display large page size with human readable format.
      Using UI units allows to fit larger numbers in columns.
      Stop calling v_page_size - this is a value that doesn't change at runtime.
      Renamed WINDOW *wnd to *wd to avoid conflict with global *wnd variable.
      Use bit-shift to convert page size to byte.

    PR:             237664, 246458
    Submitted by:   ota@j.email.ne.jp

    (cherry picked from commit 65d1fd13ac2182f7ca0c223bb723fba6d780740f)

    MFC r363095:
    Handle device removal and removal+add cases to fix infinity rate.

    PR:             219829
    Submitted by:   ota@j.email.ne.jp
    Reported by:    rezo@live.cn
    Differential Revision:  https://reviews.freebsd.org/D25226

    (cherry picked from commit 7a446028cedb13a0d2004cf6f584291a976392da)

    PR:             219829, 237664, 246458, 213310, 2137

 usr.bin/systat/Makefile       |   4 +-
 usr.bin/systat/devs.c         | 126 ++++++++++++++++++++++--
 usr.bin/systat/devs.h         |  16 ++-
 usr.bin/systat/extern.h       |   7 +-
 usr.bin/systat/fetch.c        |   9 +-
 usr.bin/systat/icmp6.c        |   9 +-
 usr.bin/systat/ifcmds.c       |   2 +
 usr.bin/systat/ifstat.c       | 118 +++++++++++++---------
 usr.bin/systat/iostat.c       |  46 ++++-----
 usr.bin/systat/ip.c           |   7 +-
 usr.bin/systat/ip6.c          |   7 +-
 usr.bin/systat/main.c         |  13 +--
 usr.bin/systat/swap.c         |  17 +++-
 usr.bin/systat/sysput.c (new) | 118 ++++++++++++++++++++++
 usr.bin/systat/systat.1       |   1 +
 usr.bin/systat/systat.h       |   4 +
 usr.bin/systat/tcp.c          |   3 +-
 usr.bin/systat/vmstat.c       | 221 +++++++++++++++---------------------------
 usr.bin/systat/zarc.c         | 124 +++++++++++++++---------
 19 files changed, 548 insertions(+), 304 deletions(-)