查看緩存的命令
free -m
清理緩存的命令
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches
說明:
1>. /proc是一個虛擬文件系統,我們可以通過對它的讀寫操作作為與kernel實體間進行通信的一種手段。也就是說可以通過修改/proc中的文件,來對當前kernel的行為做出調整。也就是說我們可以通過調整/proc/sys/vm/drop_caches來釋放內存。
1>. /proc是一個虛擬文件系統,我們可以通過對它的讀寫操作作為與kernel實體間進行通信的一種手段。也就是說可以通過修改/proc中的文件,來對當前kernel的行為做出調整。也就是說我們可以通過調整/proc/sys/vm/drop_caches來釋放內存。
0 – 不釋放
1 – 釋放頁緩存
2 – 釋放dentries和inodes
3 – 釋放所有緩存
1 – 釋放頁緩存
2 – 釋放dentries和inodes
3 – 釋放所有緩存
數字1是用來清空最近放問過的文件頁面緩存
數字2是用來清空文件節點緩存和目錄項緩存
數字3是用來清空1和2所有內容的緩存。
2>. 關於drop_caches的官方說明如下:
Writing to this file causes the kernel to drop clean caches,dentries and inodes from memory, causing that memory to becomefree.
To free pagecache, use echo 1 > /proc/sys/vm/drop_caches;
to free dentries and inodes, use echo 2 > /proc/sys/vm/drop_caches;
to free pagecache, dentries and inodes, use echo 3 >/proc/sys/vm/drop_caches.
Because this is a non-destructive operation and dirty objects are not freeable, the user should run sync first.
To free pagecache, use echo 1 > /proc/sys/vm/drop_caches;
to free dentries and inodes, use echo 2 > /proc/sys/vm/drop_caches;
to free pagecache, dentries and inodes, use echo 3 >/proc/sys/vm/drop_caches.
Because this is a non-destructive operation and dirty objects are not freeable, the user should run sync first.
3>.
Linux內核會將它最近訪問過的文件頁面緩存在內存中一段時間,這個文件緩存被稱為pagecache。
Inode是linux/unix操作系統中的一種數據結構,包含了各文件相關的一些重要信息。在創建文件系統時,就會同時創建大量的inode。一般inode表會占用文件系統磁盤空間的1%。