前后数据对比发现主要增加的是cached数据的统计量,而实际使用的内存1309几乎和之前没有变化。可以大概认为向内存分区中写入的数据实际是增大了cached的统计量。为了进一步说明这个情况,可以释放掉系统的cached数据
root@peter:/run/shm# sync; echo "3" > /proc/sys/vm/drop_caches
root@peter:/run/shm# free -m
total used free shared buffers cached
Mem: 3851 2694 1156 0 0 1401
-/+ buffers/cache: 1292 2558
Swap: 1925 0 1925
由于/run/shm分区中实际存储了1.1G的数据,cached并没有被完全使用,可以说明存放到内存分区的数据实际是在cached的统计数据中。
最后释放掉内存分区的数据并清理系统缓存后的情况如下
root@peter:/run/shm# rm -fr test.img
root@peter:/run/shm# free -m
total used free shared buffers cached
Mem: 3851 1676 2174 0 7 370
-/+ buffers/cache: 1297 2553
Swap: 1925 0 1925
root@peter:/run/shm# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 125G 4.9G 114G 5% /
udev 1.9G 4.0K 1.9G 1% /dev
tmpfs 771M 888K 770M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1.9G 7.4M 1.9G 1% /run/shm
至此,可以发现,在使用内存分区的系统中,实际使用的内存数据,应该是free -m获得使用内存情况加上内存区中的数据量,这才是系统真正使用的内存量。
【总结】
在使用内存文件系统存储数据的系统中,分析内存时要充分的考虑内存文件系统的数据用量,进而准确的给出系统所使用内存的情况,整体把握系统的资源情况,为进一步的系统分析做准备。
