我想在 Ubuntu 20.04 中使用 KSM 来实现 qemu VM 之间的内存共享。我的安装ksmtuned
如下:
$ sudo apt install ksmtuned
但是我发现KSM并没有起作用,systemctl
如下图所示:
$ systemctl status ksm.service
● ksm.service - Kernel Samepage Merging
Loaded: loaded (/lib/systemd/system/ksm.service; enabled; vendor preset: enabled)
Active: active (exited) since Mon 2021-07-12 22:44:16 CST; 2min 39s ago
Process: 661 ExecStart=/usr/sbin/ksmctl start (code=exited, status=0/SUCCESS)
Main PID: 661 (code=exited, status=0/SUCCESS)
7月 12 22:44:16 qhx-u20 systemd[1]: Starting Kernel Samepage Merging...
7月 12 22:44:16 qhx-u20 systemd[1]: Finished Kernel Samepage Merging.
$ systemctl status ksmtuned.service
● ksmtuned.service - Kernel Samepage Merging (KSM) Tuning Daemon
Loaded: loaded (/lib/systemd/system/ksmtuned.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-07-12 22:44:16 CST; 4min 54s ago
Process: 701 ExecStart=/usr/sbin/ksmtuned (code=exited, status=0/SUCCESS)
Main PID: 711 (ksmtuned)
Tasks: 2 (limit: 14194)
Memory: 2.9M
CGroup: /system.slice/ksmtuned.service
├─ 711 /bin/bash /usr/sbin/ksmtuned
└─2394 sleep 60
7月 12 22:44:16 qhx-u20 systemd[1]: Starting Kernel Samepage Merging (KSM) Tuning Daemon...
7月 12 22:44:16 qhx-u20 systemd[1]: Started Kernel Samepage Merging (KSM) Tuning Daemon.
中的值/sys/kernel/mm/ksm
包括:
$ grep . /sys/kernel/mm/ksm/*
/sys/kernel/mm/ksm/full_scans:0
/sys/kernel/mm/ksm/max_page_sharing:256
/sys/kernel/mm/ksm/merge_across_nodes:1
/sys/kernel/mm/ksm/pages_shared:0
/sys/kernel/mm/ksm/pages_sharing:0
/sys/kernel/mm/ksm/pages_to_scan:100
/sys/kernel/mm/ksm/pages_unshared:0
/sys/kernel/mm/ksm/pages_volatile:0
/sys/kernel/mm/ksm/run:0
/sys/kernel/mm/ksm/sleep_millisecs:200
/sys/kernel/mm/ksm/stable_node_chains:0
/sys/kernel/mm/ksm/stable_node_chains_prune_millisecs:2000
/sys/kernel/mm/ksm/stable_node_dups:0
/sys/kernel/mm/ksm/use_zero_pages:0
我尝试使用两者ksmctl start
来echo 1 > /sys/kernel/mm/ksm/run
启动 KSM,但失败了。
谁能告诉我为什么或如何在 Ubuntu 20.04 中正确使用 KSM?
答案1
最终,我找到了答案。
根据Redhat 的 KSM 文档其中,KSM 由服务管理ksmtuned
,其配置文件为/etc/ksmtuned.conf
。您需要更改此文件中的值才能激活 KSM,具体为KSM_THRES_COEF
和KSM_THRES_CONST
。