Xen PVM under VirtualBox

Posted on September 12, 2010 with tags tech.

Most people won’t need this, but for testing things like Debian bug #596009, it is very handy. A few posts on the internet say this doesn’t work, or not reliably, so here is my recipe.

System: VirtualBox from sid (3.2.8), and VMs created with Enable IO APIC, Enable PAE/NX, Enable VT-x/AMD-V (I have an AMD Phenom II 940), and finally Enable Nested Paging. I don’t know if all these are absolutely needed, but with this config the final guest runs nicely for some quick tests.

There are just a few gotchas that I stumbled upon:

  • having CPU hotplug enabled will break Xen, so run vboxmanage modifyvm $VM --cpuhotplug off
  • using virtio NICs softlocks the CPU as soon as any traffic is done; while this is not the default, some people might have it enabled. I’ve tested the Intel server NIC and it works fine
  • I’ve seen one hang when dom0 was assigned more than one CPU, so for best results, even if the whole VirtualBox VM has more than one CPU assigned, restrict dom0 to one (either via maxcpus=1 or via xm vcpus-set 0 1)

If however dom0 hangs, you should activate the first serial port in the VirtualBox config (raw file), and then you can get at least a kernel trace.

As for the pure CPU, speed, the results are interesting; I’ve used openssl speed rsa to do a quick test. Host (non-virtualized):

                  sign    verify    sign/s verify/s
rsa  512 bits 0.000089s 0.000009s  11176.2 116018.4
rsa 1024 bits 0.000422s 0.000024s   2370.9  41914.3
rsa 2048 bits 0.002643s 0.000075s    378.4  13255.5
rsa 4096 bits 0.017623s 0.000272s     56.7   3680.9

And domU guest (double-virtualized, that is):

                  sign    verify    sign/s verify/s slowdown
rsa  512 bits 0.000051s 0.000009s  19620.1 111644.0    3.78%
rsa 1024 bits 0.000390s 0.000026s   2561.1  38929.4    7.13%
rsa 2048 bits 0.002752s 0.000080s    363.4  12566.9    5.20%
rsa 4096 bits 0.018628s 0.000288s     53.7   3474.3    5.62%

So we have less than 10% for pure CPU work, nice. I’m not able to do I/O testing since my VirtualBox machines are using write-back cache, not write-through, so I end with this unrealistic speed:

# dd if=/dev/zero of=big-file bs=1024k count=127 oflag=direct
127+0 records in
127+0 records out
133169152 bytes (133 MB) copied, 1.21597 s, 110 MB/s

So no, this should not be used for any kind of benchmarking; but for testing and debugging issues, it’s a good way to fire up a Xen box without having to change any config or risk breaking your main machine…