virsh --connect qemu:///system qemu-monitor-command --domain NAME --hmp 'balloon 512'
# Wait for the balloon driver to release some memory
sleep 2
virsh --connect qemu:///system qemu-monitor-command --domain NAME --hmp 'balloon 4096'
或者,作为适当的脚本:
#!/bin/bash
set -eu
domain=$1
# How many MB to temporarily reduce the guest memory to; don't set this too
# low or the OOM killer will start killing.
reduced_memory=$2
hmp() {
virsh --connect qemu:///system qemu-monitor-command --domain "$domain" --hmp "$1"
}
original_memory=$(hmp "info balloon" | grep = | cut -d '=' -f 2)
hmp "balloon $reduced_memory" > /dev/null
# Wait for the balloon driver to release some memory before setting it back
sleep 2
hmp "balloon $original_memory" > /dev/null
像这样的东西似乎有效:首先减少来宾可用的内存量,然后(可选)将其恢复到原始设置。
或者,作为适当的脚本: