Linux – How to decrease the CPU usage when running Virtual Box

cpucpu usagelinuxperformancevirtualbox

I am facing an issue with 100% CPU usage under my system when running VirtualBox. Here are some further details:

My System Information:

CPU 1 name: Intel(R) Pentium(R) Dual CPU T2310 @ 1.46GHz
CPU 1 level 1 cache size: 32K Data cache. 32K Instruction cache.

CPU 1 level 2 cache size: 1024K Unified cache.
CPU 1 Mips: 2926.20
CPU 2 name: Intel(R) Pentium(R) Dual CPU T2310 @ 1.46GHz
CPU 2 level 1 cache size: 32K Data cache. 32K Instruction cache.

CPU 2 level 2 cache size: 1024K Unified cache.

CPU 2 Mips: 2925.96
64 bit CPU? Yes!
Total memory: 2.0 GB
Total swap: 6141 MBytes


My Operating System Information:

Kubuntu OS version: 11.04
Kernel version: 2.6.38-8-generic
Kernel arch: i686
Default shell: /bin/bash


My Virtual Box Settings:

OS Type: Windows XP
Video Memory: 32 MB
Acceleration: 3D
Base Memory: 512 MB

The Problem Details:

Well, each time I run Windows XP from my VirtualBox, I see the CPU usage at almost 100%. I experience a slow system even if no programs were running on my hosted Windows XP version.

I was wondering if there is a way for me to play with the settings so I can slightly enhance the performance. My PC is relatively fast under my Linux operating system. I need to know if there are some tips that I may follow when configuring the settings of my VirtualBox so i can achieve better results.

Any suggestions/ideas are highly appreciated!

Best Answer

Elaborating on my comment above the T2310 lacks Virtualization extensions (VT-x) as per your CPU datasheet at http://ark.intel.com/Product.aspx?id=32431

From this Wikipedia article, there are three basic things that will be causing a measurable degradation in performance of the VM (and therefore an increase in CPU usage on the host:

  • Binary translation is used to rewrite certain instructions, like POPF, that would otherwise fail silently or behave differently when executed above ring 0 making the classic trap-and-emulate virtualization impossible. To improve performance, the translated basic blocks need to be cached in a coherent way that detects code patching (used in VxDs for instance), the reuse of pages by the guest OS, or even self-modifying code.

  • A number of key data structures used by a processor need to be shadowed. Because most operating systems use paged virtual memory, and granting the guest OS direct access to the MMU would mean loss of control by the virtualization manager, some of the work of the x86 MMU needs to be duplicated in software for the guest OS using a technique known as shadow page tables. This involves denying the guest OS any access to the actual page table entries by trapping access attempts and emulating them instead in software.

  • I/O device emulation: Unsupported devices on the guest OS must be emulated by a device emulator that runs in the host OS.

A guest operating system has a large overheard for operations that require the use of privileged instructions that are required and typically these overheads are heavily mitigated by the use of Intels VT-x and AMDs AMD-V virtualisation extensions. Your processor lacks these extensions and so all the work of capture and emulation will cause some performance loss.

My recomendations would be:

  • To give the virtual machine as much memory as it needs to minimise the amount of paging that needs to be done, perhaps 1GB or more depending on your workloads.

  • Disable the 3D acceleration as all the calls to the 3D driver may well have to be pushed through the emulation layer and so may be expensive on your processor.

  • Install the Virtualbox Guest Additions for your guest operating system as these will use drivers that better support the virtual environment.

  • Reduce the screen resolution and graphical options in your guest operating system.

  • Keep network (internet) access to a reasonable level, heavily network bound virtual machines are expensive even with VT-x and benefit from VT-d (Virtualization Technology for Directed I/O) as well, which is also not supported by your processor.

Related Question