Enable Cgroup Memory & Swap Limit
* memsw disabled by default
查看 Kernel 是否支援 cgroup swap
D10:
grep CONFIG_MEMCG_SWAP /boot/config-`uname -r`
CONFIG_MEMCG_SWAP=y # CONFIG_MEMCG_SWAP_ENABLED is not set
U14:
grep CONFIG_MEMCG_SWAP /boot/config-`uname -r`
CONFIG_MEMCG_SWAP=y # CONFIG_MEMCG_SWAP_ENABLED is not set
C6:
grep CGROUP_MEM /boot/config-`uname -r`
CONFIG_CGROUP_MEM_RES_CTLR=y CONFIG_CGROUP_MEM_RES_CTLR_SWAP=y
啟用
C7 / C8
grep CONFIG_MEMCG_SWAP /boot/config-*
/boot/config-4.18.0-348.20.1.el8_5.x86_64:CONFIG_MEMCG_SWAP=y
/etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT=" ... cgroup_enable=memory swapaccount=1"
update-grub # C7
grub2-mkconfig > /boot/grub2/grub.cfg # C8
reboot
測試
ls /sys/fs/cgroup/memory | grep memsw
memory.memsw.failcnt memory.memsw.limit_in_bytes memory.memsw.max_usage_in_bytes memory.memsw.usage_in_bytes
# 假設有 vps: lamp 在行
grep swap /sys/fs/cgroup/memory/lxc/lamp/memory.stat
# swapaccount=1 後才有
swap 42004480 # swap usage, in bytes total_swap 42004480
swap 的 pgpgin & pgpgout
grep pgpg /sys/fs/cgroup/memory/lxc/lamp/memory.stat
pgpgin 131322329 pgpgout 131267592 # number of pages paged out of memory
Memory Usage
On Hypervisor
/sys/fs/cgroup/memory/lxc.payload/VPS_NAME
- memory.limit_in_bytes
- memory.memsw.limit_in_bytes
- memory.usage_in_bytes
- memory.memsw.usage_in_bytes
On Guest
cat /proc/swaps
Filename Type Size Used Priority none virtual 1048576 20 0
grep -e MemTotal -e SwapTotal /proc/meminfo
MemTotal: 1048576 kB SwapTotal: 1678332 kB