Optimizing KVM Virtual Machines with Tuned Profiles #
The tuned service on Red Hat-based systems provides pre-configured performance profiles that can significantly improve your VM performance with minimal effort.
In this post, I’ll show you how to optimize your KVM VMs using tuned profiles and automate the entire process with Ansible.
The Playbook #
Since I manage dozens of VMs in my homelab, doing this manually would be tedious. Instead, I use this Ansible playbook to apply tuned optimization to all my VMs:
---
- name: Tuned
hosts: all
become: true
gather_facts: true
vars_files:
- "../group_vars/all/vault.yml"
tasks:
- name: Ensure tuned is installed
ansible.builtin.dnf:
name: tuned
state: present
- name: Ensure tuned service is enabled
ansible.builtin.service:
name: tuned
enabled: true
- name: Ensure tuned service is running
ansible.builtin.service:
name: tuned
state: started
- name: Ensure virtual-guest tuned profile
ansible.builtin.command: tuned-adm profile virtual-guest
changed_when: false
Step-by-step #
Package Installation #
- name: Ensure tuned is installed
ansible.builtin.dnf:
name: tuned
state: present
Installs the tuned package if it’s not already present. Simple stuff.
Service Management #
- name: Ensure tuned service is enabled
ansible.builtin.service:
name: tuned
enabled: true
- name: Ensure tuned service is running
ansible.builtin.service:
name: tuned
state: started
Ensures the tuned service starts automatically on boot and is currently running.
Profile Application #
- name: Ensure virtual-guest tuned profile
ansible.builtin.command: tuned-adm profile virtual-guest
changed_when: false
Applies the virtual-guest profile. The changed_when: false prevents Ansible from always reporting this task as changed, since tuned-adm profile always returns success even if the profile is already active.
You can see all available profiles with:
tuned-adm list
Verifying the Configuration #
After running the playbook, you can verify the tuned configuration:
# Check active profile
tuned-adm active
# See what optimizations are applied
tuned-adm profile_info virtual-guest