Speeding up your Linux Guests

With the clock ticking over to a new decade, now would seem to be a good time for a quick blog on timer interrupts in guests and how you can speed up your guests, while also lightening the load on your host, with the judicious use of a bit of guest configuration.

All operating systems make use of a system clock which ticks at a particular frequency. Common Linux distributions use kernels which drive the clock at 100Hz, 250Hz or 1000Hz. You can find out what your Linux kernel is configured for using this command:

grep CONFIG_HZ /boot/config-<kernel>

where kernel is the version of Linux you're running. The result of this command on my Oracle Enterprise Linux installation looks like this:

[root@localhost grub]# grep CONFIG_HZ /boot/config-2.6.18-164.el5
# CONFIG_HZ_100 is not set
# CONFIG_HZ_250 is not set
CONFIG_HZ_1000=y
CONFIG_HZ=1000

...which tells me that my kernel is configured to use a 1000Hz clock tick.

In a virtualized environment this means that there will be lots of context switches as the host schedules the guest to deal with clock ticks which don't do very much.  And this will become most visible by seeing a relatively high host cpu usage even when the guest is idle. (Note that the exact behaviour also depends on the host system. For example, the same OEL vm runs comfortably on my Mac host, but my Windows host gets very busy running it.)

If you see an idle Linux guest which is configured for a 1000Hz clock using up lots of host cpu cycles, you may want to reduce the clock frequency using the boot time parameter "divider=10". You can do this by adding the parameter manually as the grub boot loader starts, or by editing the grub configuration file as follows:

  1. Edit /boot/grub/grub.conf
  2. Duplicate the existing Title section, and rename it (this means you can choose at boot time which config to use)
  3. Add the "divider=10" parameter as follows:
 kernel /vmlinuz-2.6.18-164.el5 ro root=/dev/VolGroup01/LogVol00 rhgb quiet divider=10

Here is what my complete grub.conf looks like now:

Grub.conf

This results in fewer context switches, a lighter host load (as measured by Window Task Manager) and faster guest execution. For example, the speed to boot my OEL vm (on a Windows 7 host) dropped from 115 seconds to 80 seconds which, according to my calculations, is a 30% increase in performance. Not bad for a simple bit of configuration ;-)

-FB 

Comments:

I just wanted to thank you for writing this. My VM was chomping on my CPU pretty hard even while guest was "idle". All the other sources indicated that a recompile of the kernel would be necessary. You saved me a ton of trouble.

Posted by Adam Hawkes on February 10, 2010 at 01:03 PM GMT #

I did the test on my OEL / Virtual Box machine running on a MacBook Pro host.

Using default kernel config it boots in 3'04"
Using "divider=10" it boots in 2'41"

It is a roughly 12% increase - not as spectacular as your but not so bad indeed.

Measured from the kernel load (after the grub prompt) to the X login window. Oracle XE is loaded at startup time.

Posted by Sébastien Stormacq on March 03, 2010 at 01:34 AM GMT #

Thx yet again - I have used your blog before to solve VBox problems, but lost the address. This helped me solve a problem with slow running Centos5.5. All the other blogs just said '...add divider=10...' but didn't actually say how or where. You're the only one to actually show me how. I'm not a total newbie, but sometimes instructions need to be explicit, and yours are.

Interestingly the CONFIG_HZ is still returning 1000, but the problem with high host CPU utilization has gone...???

Thx again

Posted by Robert on September 05, 2010 at 03:29 PM BST #

This seems like a generic fix to get VirtualBox to behave nicer to the host. Question is why VirtualBox (or the guest additions) can't fix this for us? I have both VMware Fusion and Parallels on my Mac and VBox is in most cases the bigger cpu hog. This fix takes care of some of the overhead though.

/Mikael

Posted by Mikael Fransson on January 17, 2011 at 07:50 PM GMT #

Thanks! This helped speed up my system tons! I only have 1Gb of RAM and virtual machines took there toll on my system. Thanks!

Posted by guest on July 03, 2011 at 06:48 AM BST #

Hi,

Yes this works! Thank you.
However, it seems toe work the second time after boot.
The first time after boot it did not work.

Cheers,
Ian.

Posted by guest on December 21, 2011 at 06:16 AM GMT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Fat Bloke

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today