下面是free的运行结果,一共有4行。为了方便说明,我们加上了列号。这样可以把free的输出看成一个二维数组FO(Free Output)。例如:
FO[2][1] = 999212
1 2 3 4 5 6
1 total used free shared buffers cached
2 Mem: 999212 967476 31736 0 50668 223000
3 -/+ buffers/cache: 693808 305404
4 Swap: 2048276 154524 1893752
· 999212KB(缺省时free的单位为KB)物理内存,即FO[2][1];
· 在这些物理内存中有967476KB(即FO[2][2])被使用了;
· 还用31736KB(即FO[2][3])是可用的;
· FO[2][1] = FO[2][2] + FO[2][3]
· A buffer is something that has yet to be "written" to disk.
· A cache is something that has been "read" from the disk and stored for later use.
· 释放掉被系统cache占用的数据;
echo 3 >/proc/sys/vm/drop_caches
· 读一个大文件,并记录时间;
· 关闭该文件;
· 重读这个大文件,并记录时间;
· 对于FO[3][2],即-buffers/cache,表示一个应用程序认为系统被用掉多少内存;
· 对于FO[3][3],即+buffers/cache,表示一个应用程序认为系统还有多少内存;
· FO[3][2] = FO[2][2] - FO[2][5] - FO[2][6]
· FO[3][3] = FO[2][3] + FO[2][5] + FO[2][6]