为什么 free 和 vmstat 显示不同的信息(总计和已用信息)

为什么 free 和 vmstat 显示不同的信息(总计和已用信息)
[root@host ~]# free && vmstat -s && cat /proc/meminfo
              total        used        free      shared  buff/cache   available
Mem:      131753676   110322904     1436448     4182648    19994324    16242632
Swap:       2097148      652076     1445072
    131753680 K total memory
    110322960 K used memory
    110589888 K active memory
      5185160 K inactive memory
      1436396 K free memory
       436808 K buffer memory
     19557516 K swap cache
      2097148 K total swap
       652076 K used swap
      1445072 K free swap
   2625228480 non-nice user cpu ticks
        43747 nice user cpu ticks
   1431460404 system cpu ticks
  44167309796 idle cpu ticks
      6674586 IO-wait cpu ticks
            0 IRQ cpu ticks
    145914225 softirq cpu ticks
            0 stolen cpu ticks
   2510972524 pages paged in
   4242777479 pages paged out
       247098 pages swapped in
       808413 pages swapped out
   2725993651 interrupts
   2931953082 CPU context switches
   1542704661 boot time
   3896390041 forks
MemTotal:       131753676 kB
MemFree:         1436288 kB
MemAvailable:   16242472 kB
Buffers:          436808 kB
Cached:          6527820 kB
SwapCached:        24924 kB
Active:         110589888 kB
Inactive:        5185160 kB
Active(anon):   108552768 kB
Inactive(anon):  4440308 kB
Active(file):    2037120 kB
Inactive(file):   744852 kB
Unevictable:           4 kB
Mlocked:               4 kB
SwapTotal:       2097148 kB
SwapFree:        1445072 kB
Dirty:                88 kB
Writeback:             0 kB
AnonPages:      108786708 kB
Mapped:           111648 kB
Shmem:           4182648 kB
Slab:           13029696 kB
SReclaimable:   12818284 kB
SUnreclaim:       211412 kB
KernelStack:      339504 kB
PageTables:       278132 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    67973984 kB
Committed_AS:   148217500 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      482728 kB
VmallocChunk:   34358945788 kB
HardwareCorrupted:     0 kB
AnonHugePages:  98357248 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      433364 kB
DirectMap2M:    49786880 kB
DirectMap1G:    85983232 kB
[root@host ~]#

uname -r
3.10.0-514.10.2.el7.x86_64

CentOS 7.3

答案1

例如,当您运行不同的命令时,“used”会略有不同。 “总计”的差异是一个错误。

freevmstat实际共享代码。它们都显示了 procps 调用的变量kb_main_total。但其中一个命令(与 /proc/meminfo 不一致的命令)使用浮点类型。通常的 32 位浮点数只有 24 位精度。 vmstat.c

static unsigned long unitConvert(unsigned long size)
{
    float cvSize;
    cvSize = (float)size / dataUnit * ((statMode == SLABSTAT) ? 1 : 1024);
    return ((unsigned long)cvSize);
}
$ python
...
>>> from ctypes import c_float
>>> c_float(131753676)
c_float(131753680.0)

相关内容