Quick Tune for Virtual Linux Guests

Hi folks,

Today I’d like to show you a quick way of tuning your Linux-based virtual machines using the “tuned-adm” command. This command should work with any distribution of Linux on any virtualization platform. Before I show you how to use the command though, I’d like to provide you with an explanation of what is going on under the covers.

The first thing to remember when you’re dealing with virtual machines is that all of your hardware is, well, virtual. That is to say that setting ‘hdparms’ on the virtual disk or telling a CPU to switch to power saving mode is all wasted effort and resources. The other thing that you might want to remember is that swap space on a virtual disk is slower than swap on a real disk.

With that in mind, “tuned-adm” handles both power saving features as well as swappiness. The power saving pieces is straightforward enough, but maybe you’re less familiar with swappiness. Swappiness” refers to how the Linux kernel handles the balance of physical memory (RAM) and swap memory (swap partition on disk). If you remember your computer science basics, RAM is much fast than disk, but disk swap is handy for certain applications.

Linux swappiness is configured as a number between “0” and “100”, where “0” only allows swapping to avoid an out of memory condition, as in “no swap for you!”, and “100” is akin to molasses in sub-zero temperatures. (BTW,  the default for RHEL is “60”.)

Like any other performance tuning activity, you’re going to want to try it in a test environment first, not production.

So,  what does the tuned-adm command actually do under the covers? Allow me to illuminate you on the simplicity that is ‘tuned’ and ‘ktune’. Tuned is a daemon that monitors different areas of a system and can change things automatically. Ktune is a profile framework that can be used to tune the kernel (sysctl parameters) for specific workloads.

Assuming that you have already installed the ‘tuned’ package, change to the /etc/tuned-profiles/virtual-guest directory (that’s the path for RHEL and Fedora). If you peek at the ‘tuned.conf’ file, you’ll note that all of the power saving is disabled for hardware. If you then peek at the ‘sysctl.ktune’ file, you’ll see that it drops the swappiness to “30” and also adjusts a few other things as well.

As a side note, the tuned-adm command can also change the profile for your desktop, your laptop, your server, etc. It’s not just for virtual machines; see the other profiles available under /etc/tune-profiles. And for even more info, check out the explanations given by Red Hat.

Ok, enough talk, let’s get tuning. First off, lets see the state of things before we enable any profile at all:

[root@JonVM virtual-guest]# tuned-adm active
Current active profile: default
Service tuned: enabled, stopped
Service ktune: enabled, stopped

Note that in this case, “default” means no profile has been loaded, and that both tuned and ktune are not running. Let’s change that by assigning our virtual guest profile:

[root@JonVM virtual-guest]# tuned-adm profile virtual-guest
Switching to profile 'virtual-guest'
Applying ktune sysctl settings:
/etc/ktune.d/tunedadm.conf:                                [  OK  ]
Calling '/etc/ktune.d/tunedadm.sh start':                  [  OK  ]
Applying sysctl settings from /etc/sysctl.conf
Applying deadline elevator: dm-0 dm-1 sda                  [  OK  ]
Starting tuned:                                            [  OK  ]

Boom! With one command, we disabled all of the power saving features that are wasted on a virtual machine and adjusted some kernel tunables that benefit our VM. And that’s really all there is to it. I hope you can add this to your bag of tricks.

Hope this helps,

Captain KVM

Agree? Disagree? Something to add to the conversation?