C1V Hosting

KVM VPS tuning: disk speed and network performance

Measure first, then change one setting at a time. On KVM the largest gains come from the hypervisor side (virtio disk and network, cache=none, multiqueue). Inside the guest, use the none I/O scheduler on virtio disks, mount with noatime, enable fstrim.timer and raise TCP buffers only for high-bandwidth, high-latency links.

On this page
  1. Summary of the settings
  2. Measure before you tune
  3. Hypervisor side: virtio, cache and iothread
  4. Guest side: scheduler, rotational flag and mount options
  5. Memory and writeback settings
  6. Network: virtio-net, multiqueue and offloads
  7. TCP buffers and congestion control
  8. Frequently asked questions

Updated

At a glance

  • Benchmark with fio and iperf3 before and after
  • Hypervisor: virtio, cache=none, iothread, multiqueue
  • Guest: scheduler none, noatime, fstrim.timer
  • Persist changes in sysctl.d and udev, not rc.local

Summary of the settings

SettingWhereEffectCaution
virtio disk and NICHypervisorParavirtual drivers instead of emulated hardwareWindows guests need the virtio drivers installed
cache=none, io=nativeHypervisorAvoids double caching, steadier latencyWriteback is faster but can lose recent writes on a host crash
Scheduler noneGuestLess overhead on fast virtual disksMeasure; keep mq-deadline if it tests better
noatime, fstrim.timerGuestFewer metadata writes, regular discardnoatime can affect tools that rely on access time
vm.swappiness, vfs_cache_pressureGuestKeeps more cache and less swapTune to the workload
virtio-net queuesBothSpreads network load over several vCPUsOnly helps with several vCPUs and parallel flows
TCP buffers, BBRGuestHigher throughput on long, fast pathsLittle effect on short local links

Measure before you tune

Without numbers you cannot tell whether a change helped. Install the tools and record a baseline:

sudo apt-get install fio sysstat iperf3

# random 4k read/write, bypassing the page cache
fio --name=randrw --filename=/root/fio.test --size=1G --bs=4k --rw=randrw --rwmixread=70     --iodepth=32 --ioengine=libaio --direct=1 --runtime=30 --time_based --group_reporting
rm /root/fio.test

# watch utilization and latency while it runs
iostat -x 1

For the network, run iperf3 -s on one machine and iperf3 -c SERVER -P 4 on the other. Keep the results next to the date and the change you made.

Hypervisor side: virtio, cache and iothread

This part applies only if you control the hypervisor, for example your own Proxmox or libvirt host. On a VPS from a provider these options are set by the provider, so ask what the platform uses.

Use paravirtual devices: virtio-blk or virtio-scsi for disks and virtio-net for the network card. In Proxmox VE:

qm set 100 --scsihw virtio-scsi-single
qm set 100 --scsi0 local-lvm:vm-100-disk-0,cache=none,discard=on,iothread=1,ssd=1

In libvirt, the disk driver line looks like this:

<driver name='qemu' type='raw' cache='none' io='native' discard='unmap'/>

cache=none bypasses the host page cache, which avoids caching the same data twice and gives steadier latency. writeback can be faster but recent writes may be lost if the host crashes. An iothread moves disk I/O off the main QEMU thread.

Guest side: scheduler, rotational flag and mount options

Check what the guest sees:

lsblk -d -o NAME,ROTA,TYPE,SIZE
cat /sys/block/vda/queue/scheduler

On kernels 5.0 and later the multi-queue block layer is the only one and the scheduler is called none, not noop (the name used in older guides). On a virtual disk backed by NVMe or SSD, none is normally the right choice. To set it and keep it across reboots, use a udev rule instead of /etc/rc.local:

echo none | sudo tee /sys/block/vda/queue/scheduler

# /etc/udev/rules.d/60-io-scheduler.rules
ACTION=="add|change", KERNEL=="vd[a-z]", ATTR{queue/scheduler}="none", ATTR{queue/rotational}="0"

Use sd[a-z] in the rule if your disk is presented as a SCSI device. Then reduce metadata writes with noatime in /etc/fstab and apply it without rebooting:

UUID=xxxx-xxxx  /  ext4  defaults,noatime  0  1

sudo mount -o remount,noatime /

Trim unused blocks regularly instead of mounting with discard:

sudo fstrim -av
sudo systemctl enable --now fstrim.timer

Older tuning lists also suggest mounting with nobarrier (or barrier=0 on ext4). We do not recommend it: disabling write barriers risks filesystem corruption after a power loss or crash, and the option has been removed or deprecated in recent kernels for some filesystems.

Memory and writeback settings

Put your changes in a file under /etc/sysctl.d/ rather than appending to /etc/sysctl.conf:

# /etc/sysctl.d/99-vps-tuning.conf
vm.swappiness = 10
vm.vfs_cache_pressure = 50

Apply it with sudo sysctl --system. A lower vm.swappiness makes the kernel prefer dropping cache to swapping application memory, and a lower vm.vfs_cache_pressure keeps directory and inode caches longer. Debian defaults are 60 and 100. Values such as 5 are used in some guides, but very low swappiness is not right for every workload, so test with your own load.

Network: virtio-net, multiqueue and offloads

Use the virtio network model. If the guest has several vCPUs, enable multiqueue so that packets are handled on more than one core. In Proxmox VE add queues=4 to the network device:

qm set 100 --net0 virtio,bridge=vmbr0,queues=4

Then enable the queues inside the guest and check the offload features:

ethtool -l eth0
sudo ethtool -L eth0 combined 4
ethtool -k eth0 | grep -E 'segmentation|gro|checksum'

Leave checksum, TSO, GSO and GRO offloads enabled on virtio-net unless you are diagnosing a specific problem. The interface may not be called eth0; check with ip link.

TCP buffers and congestion control

Default buffers are fine for short paths. For long, fast paths (for example a transfer between countries at 1 Gbps) larger buffers allow the connection to fill the pipe:

# /etc/sysctl.d/99-net-tuning.conf
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr

BBR needs the tcp_bbr module. Check the available algorithms with sysctl net.ipv4.tcp_available_congestion_control; if bbr is missing, run sudo modprobe tcp_bbr and add tcp_bbr to /etc/modules-load.d/bbr.conf. Apply everything with sudo sysctl --system, then repeat the iperf3 test and compare.

Frequently asked questions

Why is the scheduler called none and not noop?

Since Linux 5.0 only the multi-queue block layer exists, and its "no scheduler" mode is named none. The noop name belonged to the old single-queue layer.

Is cache=none always the best cache mode?

It is a safe default for steady latency and it avoids double caching. writeback can be faster for some workloads but can lose recent writes if the host crashes, so test and decide per VM.

Should I use discard in fstab or fstrim.timer?

A weekly fstrim through fstrim.timer is usually enough and avoids the cost of discarding on every delete. Enable it with systemctl enable --now fstrim.timer.

Can I change these hypervisor options on a VPS?

Usually not: the provider configures the virtual hardware. The guest-side settings (scheduler, mount options, sysctl) are yours to change.

Do larger TCP buffers always help?

No. They matter on high-bandwidth, high-latency paths. On a local or short path the defaults are normally enough, so check with iperf3 before keeping the change.

C1V Hosting is a brand of Lumanex S.r.l., Rome, Italy.