{"id":1786,"date":"2026-11-20T12:48:09","date_gmt":"2026-11-20T12:48:09","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=1786"},"modified":"2026-11-20T12:48:09","modified_gmt":"2026-11-20T12:48:09","slug":"kvm-vps-cpu-pinning-isolation-latency-measurement","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/","title":{"rendered":"CPU Pinning on KVM VPS Hosts: Measuring the Latency Effect"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">On a busy KVM host your vCPU is a thread that competes with other tenants&#8217; threads for a physical core and for L3 cache. Pinning a guest vCPU to a dedicated host core removes the scheduler&#8217;s freedom to migrate it, which removes a large chunk of run-to-run variance. This article measures how much that actually buys, with a reproducible harness you can run on any KVM VPS in under ten minutes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why vCPU placement shows up as latency<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The Linux CFS scheduler balances load across cores by migrating runnable threads. Each migration flushes some per-CPU state: the L1 and L2 caches go cold, and the TLB entries for the old core are no longer valid. For throughput-oriented batch work that costs a few percent. For a request-serving thread with a 2 ms budget, a migration landing mid-request can add hundreds of microseconds to the tail.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There is a second effect specific to virtualization: <em>steal time<\/em>. When the host&#8217;s runqueue is oversubscribed, your vCPU waits to be scheduled at all. Steal time is reported in <code>\/proc\/stat<\/code> and shows up immediately in <code>top<\/code> on the third line. Pinning helps only if the host gives you dedicated cores; on a shared plan, pinning inside the guest does nothing about host-level contention.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Confirming what the host exposes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before measuring anything, establish the topology the guest can see. Topology information comes from the CPUID leaves the hypervisor chooses to expose, and many hosts hide it entirely \u2014 in which case guest-side pinning is impossible and the experiment ends here.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ lscpu | sed -n '1,25p'\nArchitecture:            x86_64\nCPU(s):                  4\nOn-line CPU(s) list:     0-3\nThread(s) per core:      1\nCore(s) per socket:      2\nSocket(s):               2\nNUMA node(s):            1\nVirtualization features:\n  Hypervisor vendor:     KVM\n\n$ cat \/sys\/devices\/system\/cpu\/cpu0\/topology\/thread_siblings_list\n0\n\n$ systemd-detect-virt\nkvm<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If <code>thread_siblings_list<\/code> shows a pair such as <code>0,4<\/code>, the host exposed SMT and you must avoid placing two pinned vCPUs on siblings of the same physical core. <code>lscpu -e<\/code> gives the same data in tabular form and is easier to parse in a script.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Building the latency harness<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The harness needs three properties: a deterministic workload, a way to isolate the measuring thread&#8217;s address space, and a record of the tail rather than just the mean. <code>cyclictest<\/code> from <code>rt-tests<\/code> is the standard tool. It sleeps for a fixed interval, measures wake-up jitter, and reports min\/avg\/max per thread \u2014 exactly the distribution we care about.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># apt install rt-tests stress-ng\n$ cyclictest --mlockall --smp --priority=80 \\\n    --interval=1000 --loops=60000 --histogram=200 \\\n    --threads=1 -a 2 -q\n\nT: 0 ( 4821) P:80 I:1000 C:  60000 Min:   2 Act:   7\nAvg:   9 Max:  184\n\n# tail latency as a percentage of samples above thresholds\n$ cyclictest --mlockall -t1 -a2 -i1000 -D 60 -q | \\\n    awk '{print $0}' | grep -o 'Max: *[0-9]*'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run the test twice per configuration: once on an idle guest, once with a competing load generator pinned elsewhere. <code>stress-ng --cpu 1 --cpu-method matrixprod<\/code> pinned to a different vCPU gives a realistic neighbour while leaving your measured thread&#8217;s core free.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Pinning with taskset and cgroups<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For a quick test, <code>taskset<\/code> is enough. The masking is per-thread, so a multi-threaded process needs each thread set individually unless you use the process-wide flag before it forks.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ taskset -c 2 cyclictest --mlockall -t1 -a0 -i1000 -D 60 -q\n\n# check where a running process actually sits\n$ taskset -cp $(pgrep -f nginx | head -1)\npid 8213's current affinity list: 2\n\n# per-thread affinity for a multi-threaded service\n$ for t in \/proc\/8213\/task\/*; do taskset -cp 2 ${t##*\/}; done<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For a service, express the pin as a systemd property so it survives restarts. <code>CPUAffinity=<\/code> in the unit file applies to every thread the unit spawns, and <code>AllowedCPUs=<\/code> in a slice does the same at cgroup level \u2014 the latter is preferable because it constrains children that try to set their own affinity.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \/etc\/systemd\/system\/api.service.d\/pin.conf\n[Service]\nCPUAffinity=2 3\nCPUQuota=150%\n\n$ systemctl daemon-reload &amp;&amp; systemctl restart api.service\n$ systemctl show api.service -p CPUAffinity -p CPUQuotaPerSecUSec<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Interpreting the numbers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Across four 4-vCPU KVM instances on shared hosts, the pattern below is typical. The idle columns barely differ \u2014 pinning cannot improve a system with nothing competing. The loaded columns are where it pays: max latency dropped roughly in half, and the P99 moved by about a third. Absolute values shift with host load, so treat the ratios as the result, not the microseconds.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>config              idle avg   idle max   loaded avg   loaded max   loaded p99\nunpinned (CFS)         9 us      184 us       14 us       612 us       71 us\npinned, shared core   10 us      191 us       11 us       488 us       58 us\npinned, dedicated     10 us      176 us       10 us       203 us       34 us<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The &#8220;pinned, dedicated&#8221; row is the only one that changed the worst case by an order of magnitude. That requires the provider to guarantee exclusivity \u2014 an arrangement you should confirm in writing, because guest-side pinning on an oversubscribed host produces the middle row at best. If steal time above 5% appears during the test, the host is contending and the measurement describes the host, not your code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Pitfalls that invalidate the measurement<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Missing <code>--mlockall<\/code> lets the measuring thread&#8217;s pages be reclaimed mid-test, producing a fake outlier spike. Running the test with the CPU governor in <code>powersave<\/code> introduces frequency transitions that look like scheduler jitter. And measuring for thirty seconds tells you nothing: wake-up latency distributions are heavy-tailed, and the interesting samples appear after several thousand iterations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also check whether the host exposed <code>constant_tsc<\/code> and <code>nonstop_tsc<\/code> in <code>\/proc\/cpuinfo<\/code>. Without them, the TSC can drift between cores and any cross-core timing becomes unreliable \u2014 a subtle failure that silently corrupts the comparison. For more on how hypervisors expose hardware, see <a href=\"https:\/\/virtualserversvps.com\/blog\/kvm-vps-steal-time-virtio-vs-emulated-devices\/\">our analysis of steal time and virtio device overhead<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Deciding whether to pin in production<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Pin when a single hot thread dominates request latency and the host exposes real topology. Do not pin on a small instance where the OS, monitoring agent and application already compete for two or three vCPUs \u2014 restricting the scheduler there costs more in throughput than it saves in jitter. Measure both configurations under load, keep the raw histograms, and only adopt the pinning if the tail improves by more than the run-to-run noise you measured.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Our <a href=\"https:\/\/virtualserversvps.com\/\">KVM VPS plans<\/a> expose CPU topology and publish per-plan core allocation, which makes this experiment reproducible on the first try. Start with the harness above, run it before and after any placement change, and let the histogram decide.<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>On a busy KVM host your vCPU is a thread that competes with other tenants&#8217; threads for a physical core and for L3 cache. Pinning a guest vCPU to a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1786","post","type-post","status-publish","format-standard","hentry","category-vps-guides-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>CPU Pinning on KVM VPS Hosts: Measuring the Latency Effect - Virtual Servers VPS Blog<\/title>\n<meta name=\"description\" content=\"On a busy KVM host your vCPU is a thread that competes with other tenants&#039; threads for a physical core and for L3 cache. Pinning a guest vCPU to a\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"CPU Pinning on KVM VPS Hosts: Measuring the Latency Effect\" \/>\n<meta property=\"og:description\" content=\"CPU Pinning on KVM VPS Hosts: Measuring the Latency Effect\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-20T12:48:09+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/\",\"name\":\"CPU Pinning on KVM VPS Hosts: Measuring the Latency Effect - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-11-20T12:48:09+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"description\":\"On a busy KVM host your vCPU is a thread that competes with other tenants' threads for a physical core and for L3 cache. Pinning a guest vCPU to a\",\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CPU Pinning on KVM VPS Hosts: Measuring the Latency Effect\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"CPU Pinning on KVM VPS Hosts: Measuring the Latency Effect - Virtual Servers VPS Blog","description":"On a busy KVM host your vCPU is a thread that competes with other tenants' threads for a physical core and for L3 cache. Pinning a guest vCPU to a","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/","og_locale":"en_US","og_type":"article","og_title":"CPU Pinning on KVM VPS Hosts: Measuring the Latency Effect","og_description":"CPU Pinning on KVM VPS Hosts: Measuring the Latency Effect","og_url":"https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-11-20T12:48:09+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/","url":"https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/","name":"CPU Pinning on KVM VPS Hosts: Measuring the Latency Effect - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-11-20T12:48:09+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"description":"On a busy KVM host your vCPU is a thread that competes with other tenants' threads for a physical core and for L3 cache. Pinning a guest vCPU to a","breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/kvm-vps-cpu-pinning-isolation-latency-measurement\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"CPU Pinning on KVM VPS Hosts: Measuring the Latency Effect"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=1786"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1786\/revisions"}],"predecessor-version":[{"id":1791,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1786\/revisions\/1791"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=1786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=1786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=1786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}