kvm: set cache type to unsafe if possible, else writeback

We try to set the cache type to unsafe, which is a new kvm feature,
else we set the cache type to writeback. The hope is that these cache
types will perform better on the bots, especially in the case of the
guest trying to flush data to disk.

The CL includes code to determine which version of kvm is running, and
the cache type is chosen based on that.

BUG=chromium-os:20305
TEST=trybot

Change-Id: Icf7dbb8f0056a330282ebeb81d0902b3d54f34c5
Reviewed-on: http://gerrit.chromium.org/gerrit/8360
Reviewed-by: David James <davidjames@chromium.org>
Tested-by: Andrew de los Reyes <adlr@chromium.org>
This commit is contained in:
Andrew de los Reyes 2011-09-27 10:37:28 -07:00 committed by David James
parent faeee5f47c
commit 8e93647f05

View File

@ -37,6 +37,14 @@ function blocking_kill() {
! ps -p ${1} > /dev/null ! ps -p ${1} > /dev/null
} }
function kvm_version_greater_equal() {
local test_version="${1}"
local kvm_version=$(kvm --version | sed -E 's/^.*version ([0-9\.]*) .*$/\1/')
[ $(echo -e "${test_version}\n${kvm_version}" | sort -r -V | head -n 1) = \
$kvm_version ]
}
# $1: Path to the virtual image to start. # $1: Path to the virtual image to start.
function start_kvm() { function start_kvm() {
# Override default pid file. # Override default pid file.
@ -73,6 +81,11 @@ function start_kvm() {
net_option="-net nic,model=e1000" net_option="-net nic,model=e1000"
fi fi
local cache_type="writeback"
if kvm_version_greater_equal "0.14"; then
cache_type="unsafe"
fi
sudo kvm -m 1024 \ sudo kvm -m 1024 \
-vga std \ -vga std \
-pidfile "${KVM_PID_FILE}" \ -pidfile "${KVM_PID_FILE}" \
@ -81,7 +94,7 @@ function start_kvm() {
${nographics} \ ${nographics} \
${snapshot} \ ${snapshot} \
-net user,hostfwd=tcp::${FLAGS_ssh_port}-:22 \ -net user,hostfwd=tcp::${FLAGS_ssh_port}-:22 \
-hda "${1}" -drive "file=${1},index=0,media=disk,cache=${cache_type}"
info "KVM started with pid stored in ${KVM_PID_FILE}" info "KVM started with pid stored in ${KVM_PID_FILE}"
LIVE_VM_IMAGE="${1}" LIVE_VM_IMAGE="${1}"