Dark's Code Dump

Possibly useful

Realtime SRCDS in Libvirt/KVM guest

This post explains how to achieve a high quality TF2 SRCDS server, or indeed any realtime process, inside a KVM guest. You must control the host machine, it is not possible to provide a high quality gameserver with a VPS.

The trick to completely lag-free SRCDS under systemd on bare metal is the following settings:

(You don't even need a realtime kernel, this is enough to let you hammer the machine with various other non-realtime workloads / heavy IO and simultaneously have silky smooth SRCDS.)


This alone is not enough inside a KVM guest, as the KVM process must also be realtime scheduled, and you have a second kernel abstracting things somewhat.

Starting with a default config from virt-install, add to your libvirt config, merging sections as necessary, and add/remove vcpusched items based on your number of threads:


    <vcpusched vcpus='0' scheduler='rr' priority='30'/>
    <vcpusched vcpus='1' scheduler='rr' priority='30'/>
    <vcpusched vcpus='2' scheduler='rr' priority='30'/>
    <vcpusched vcpus='3' scheduler='rr' priority='30'/>
    <vcpusched vcpus='4' scheduler='rr' priority='30'/>
    <vcpusched vcpus='5' scheduler='rr' priority='30'/>
    <vcpusched vcpus='6' scheduler='rr' priority='30'/>
    <vcpusched vcpus='7' scheduler='rr' priority='30'/>
    <iothreadsched iothreads='1' scheduler='rr' priority='30'/>

    <pmu state='off'/>

  <cpu mode='host-passthrough' check='none' migratable='off'>
    <feature policy='require' name='tsc-deadline'/>

  <controller type='usb' index='0' model='none'/>

  <memballoon model='none'/>


  • nosharepages because some other guide said these were bad for realtime, but they probably aren't being used anyway on a modern system due to security concerns...
  • locked because paging is bad for realtime
  • cputune/iothreads to replicate the same realtime scheduling on the qemu process
  • tsc-deadline to avoid the fake Doctor Who grade timing used by KVM normally and pass through the native tsc
  • pmu state='off', usb model='none', memballoon model='none' - blindly following other recommendations to turn these off for realtime workloads

Apply the above systemd config on your SRCDS systemd services within the guest if you haven't already.

Finally, for a small extra improvement, install a realtime kernel within the guest. Debian offers the linux-image-rt-amd64 package for this. Installing a realtime kernel on the host is probably a step too far.

Other guides recommend huge pages, but these are reasonably automatic these days, I don't think you need to bother configuring manual 1G huge pages. Likewise core affinities, probably a step too far, schedulers are pretty smart.

Leave a Reply