最後更新: 2017-01-23
介紹
- memtune
- dommemstat
- dominfo
- setmaxmem
- setmem
memtune (Get or set domain memory parameters)
i.e.
virsh memtune centos6.3
hard_limit : unlimited soft_limit : unlimited swap_hard_limit: unlimited
以下 unit 都是 kilobytes, -1 => unlimited
- --hard-limit <-- The maximum memory the guest can use.
- --soft-limit
- --swap-hard-limit <-- maximum memory plus swap the guest can use
其他 Opts:
- --live
- --config
XML:
<memtune> <hard_limit>131072</hard_limit> <soft_limit>65536</soft_limit> <swap_hard_limit>262144</swap_hard_limit> </memtune>
Prevents the the guest swapping out
XML:
<memoryBacking> <locked/> </memoryBacking>
memory usage (active domain 的 memory 情況)
dommemstat
virsh dommemstat centos6.3
actual 512000 <-- Used memory
swap_in 0
rss 61476 <-- ps aux 時見到的 rss
virsh dominfo centos6.3
Id: - Name: centos6.3 UUID: d161d64e-ccc0-3774-4907-e6be57089a49 OS Type: hvm State: shut off CPU(s): 2 Max memory: 512000 kB <-- setmaxmem Used memory: 512000 kB <-- setmem Persistent: yes Autostart: disable Managed save: no Security model: apparmor Security DOI: 0
setmaxmem 與 setmem
i.e.
setmaxmem centos6.3 --size 700m
- --live # KVM 不支援 live config
- --config # take effect affect next boot
Check Guest 支不支援 ballooning:
# Centos 7
ps aux | grep vballoon
root 443 0.0 0.0 0 0 ? S 16:33 0:00 [vballoon]
setmem (即時改變 guest 的 ram 的 total) <-- perform a memory balloon of a running guest
# setmem unit: kilobytes
i.e. 512 Mbyte
setmem centos6.3 524288
- --live # perform a memory balloon of a running guest (Default, reboot 後無效)
- --config # next boot of a persistent guest
check guest memory usage
free -m
升 ram 前:
total used free shared buff/cache available
Mem: 482 81 338 3 62 296
Swap: 1023 2 1021
升 ram 後: "virsh setmem --size 780m centos7"
total used free shared buff/cache available
Mem: 750 81 606 3 62 564
Swap: 1023 2 1021
* 如果有用 HugePage, 當 VM start 時, HugePage 會根據 "Max memory" 去食走