Updated to Karmic the other day, and all is well and good with the world, but VirtualBox is determined to use a heap of CPU time even when the guest OS is idling. This sucks, and from what I’ve read is related to CPU affinity.
I tried changing the affinity from 3 down to 1 with sudo taskset -p 1 31540 from the terminal, where 31540 was the PID (Process ID) of VirtualBox at the time – and did it work? Um, no…
After some further reading I found a quirky, but totally working
– Create a new virtual machine, call it “Dummy” or something
– Assign it as little resources as you can, like 4MB RAM, use a 10MB HD image etc
– Start this dummy virtual machine, skipping any virtual hard drive formatting
– That’s it! Just leave the dummy machine running at the screen saying “FATAL: No bootable medium found! System halted”
With the dummy machine running, VirtualBox sorts out its own processor affinity properly, and the CPU usage of your actual VM guest drops waaaaaaay down and becomes snappy & responsive again.
Update: This problem’s been recurring for me (as you can see in the comments below), but I think I’ve cracked it: With an XP guest running on a single core of a Core 2 Duo, if I run the following command in bash I can get the CPU usage down to negligible levels:
echo 2 > /proc/sys/kernel/perf_counter_paranoid
If this works for you and you want it to be applied at every boot, just edit the file /etc/sysctl.conf and add the line kernel.perf_counter_paranoid = 2 at the bottom.
Additional Information: Although perf_counter_paranoid 2 seems to work reasonably well – we can still do a bit better. With an XP guest, once you’ve set XP to use multiple processors, it’s going to keep trying to use multiple processors, even if you’ve told VB to only allow it access to a single CPU. To fix this you can grab yourself a copy of of HALu and change your XP CPU setup from ACPI Multiprocessor PC to ACPI Uniprocessor PC. With that in place, CPU usage for your linux host drops down a little further, and doesn’t ramp back up too far under minimal guest load. Or you could just use the dummy VM… FFFFFFUUUUUUUUUUUUUUUUUUU…. =P