Centos 5 in VirtualBox – High CPU Usage FIXED

Posted by Steve on October 1st, 2009

CentOS LogoLet me give some background to the problem. You’re running CentOS 5 under VirtualBox, perhaps on OSX Leopard Server or indeed possibly another host operating system. You’ve noticed that even when the guest is utterly idle, the processor on the host is hovering at 50% or above. Or maybe only 20% but really, when the guest is idle, why is VirtualBox using ANY host processor.

I noticed that I don’t have this issue with Ubuntu (can’t remember which version) so I figured it had to be a Linux kernel issue rather than a VirtualBox issue.

After much scouring of Google, and receiving some excellent, but highly convoluted answers such as recompile the guest kernel with CONFIG_NO_HZ=y and CONFIG_HIGH_RES_TIMERS=y (neither of which the kernel with Centos 5 understands) and so I went down the path of recompiling my own CentOS kernel.

But now I have found a very simple answer. Forget about recompiling your own CentOS kernel, you don’t need to. You can simply pass a boot time parameter into the kernel using the grub menu.lst

divider=10

The problem comes because the CentOS kernel is compiled with the┬áCONFIG_HZ_1000=y and┬áCONFIG_HZ=1000 options. This (I’m told) basically means the kernel is trying to service interrupts at a rate of 1000 per second – which is fair and reasonable on normal hardware. But it makes a lot of extra work for a VM which is virtualising those interrupts. Setting the divider to 10 means you drop the amount of time spent generating interrupts and so the VM has less work to do – hence less processor use on the host.

The full line in /boot/grub/menu.lst for my running kernel now looks like this;

kernel /vmlinuz-2.6.18-164.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet divider=10

I’ve also found since making this change that the guest seems a LOT more responsive and snappy. Odd really since the 1000Hz kernels are meant to be snappier. Oh well, Virtualization is a strange art of its own rulemaking and I’m just a user!

Hope that helps someone else.

6 Responses to “Centos 5 in VirtualBox – High CPU Usage FIXED”

  1. [...] to this blog and the way to lower the CPU usage your guest system is [...]

  2. Amazing tip, thanks! I was about to go though the whole rebuilding kernel process and just found your tip!
    Our CentOS5 VM show high guest CPU (especially system) without apparent reason. I’m going to try this parameter. Thanks!

  3. [...] You may experience HIGH CPU issues after boot, but since these boxes are based on linux, you can use the divider=10 centos trick. [...]

  4. Brilliant tip thanks – saved me a lot of time!

  5. I’ve had a very strange problem in my linux VM environment where the Java process takes up 100% of the CPU.

    Initially I thought that the process demanded the need of a CPU so went out a 2nd dual core xeon processor and i see the same issue. The Java process runs stable but all of a sudden during day peaks at 100% and stays that way slowing down the entire environment.

    I wanted to apply this trick but needed more guidance. where abouts do I exactly put this line?

  6. My Centos slows down after running for awhile. Could it be related to this issue? I tried almost everything in VirtualBox, but it did not help.

Leave a Reply