Linux:memory and swap 管理

分類:Linux_Base


檢視memory

free -m
              total        used        free      shared  buff/cache   available
Mem:            961         535          81           0         344         252
Swap:          2047         371        1676

clean cache

#pagecache
echo 1 > /proc/sys/vm/drop_caches
#dentries + inodes
echo 2 > /proc/sys/vm/drop_caches
#pagecache + dentries + inodes
echo 3 > /proc/sys/vm/drop_caches

clean swap

# 執行前需確認mem 的空間足夠接收 swap 所釋放出來的空間
swapoff -a
swapon -a

swap 調整開始使用的比例,下例為mem 剩於10% 開始使用

vim /etc/sysctl.conf
vm.swappiness=10
sysctl -p