[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
센트OS 7.3
답변1
예를 들어, 다른 명령을 실행하면 "used"가 약간 달라집니다. '합계'의 차이는 오류입니다.
free
그리고 vmstat
실제로 코드를 공유해보세요. 둘 다 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)