From 8e93647f050f78ffa8a8aa674694269aefbb12c5 Mon Sep 17 00:00:00 2001 From: Andrew de los Reyes Date: Tue, 27 Sep 2011 10:37:28 -0700 Subject: [PATCH] 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 Tested-by: Andrew de los Reyes --- lib/cros_vm_lib.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/cros_vm_lib.sh b/lib/cros_vm_lib.sh index 248a9112d8..6a7fd78213 100644 --- a/lib/cros_vm_lib.sh +++ b/lib/cros_vm_lib.sh @@ -37,6 +37,14 @@ function blocking_kill() { ! 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. function start_kvm() { # Override default pid file. @@ -73,6 +81,11 @@ function start_kvm() { net_option="-net nic,model=e1000" fi + local cache_type="writeback" + if kvm_version_greater_equal "0.14"; then + cache_type="unsafe" + fi + sudo kvm -m 1024 \ -vga std \ -pidfile "${KVM_PID_FILE}" \ @@ -81,7 +94,7 @@ function start_kvm() { ${nographics} \ ${snapshot} \ -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}" LIVE_VM_IMAGE="${1}"