{"id":1271,"date":"2026-10-02T02:00:09","date_gmt":"2026-10-02T02:00:09","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=1271"},"modified":"2026-10-02T02:00:09","modified_gmt":"2026-10-02T02:00:09","slug":"tuning-linux-swap-nvme-vps-without-latency-spikes","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/tuning-linux-swap-nvme-vps-without-latency-spikes\/","title":{"rendered":"Tuning Linux Swap on an NVMe VPS Without Causing Latency Spikes"},"content":{"rendered":"<div style=\"padding:20px\">\n\n<p class=\"wp-block-paragraph\">Swap has a bad reputation on servers, and mostly for good reason: if a workload actively pages to a slow disk, latency explodes. But swap is not inherently harmful. On an NVMe-backed VPS, a small, correctly configured swapfile can absorb bursty memory spikes, keep the OOM killer away, and preserve cache for hot data. This guide walks through configuring swap so it helps rather than hurts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When swap helps on an NVMe VPS<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Short-lived memory spikes above the RAM ceiling that would otherwise trigger the OOM killer.<\/li><li>Cold anonymous pages that are rarely touched and can live on disk harmlessly.<\/li><li>Predictable graceful degradation during traffic bursts instead of abrupt process death.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">When swap hurts: sustained pressure where the working set genuinely exceeds RAM. In that case you are not swapping occasionally, you are thrashing, and no amount of NVMe speed fixes a workload that does not fit. The correct fix is more memory, not more swap. If that describes your situation, right-sizing the instance is the real solution, and our <a href=\"https:\/\/virtualserversvps.com\/\">VPS comparison<\/a> helps identify a tier with adequate RAM.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuring a swapfile<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>fallocate -l 2G \/swapfile\nchmod 600 \/swapfile\nmkswap \/swapfile\nswapon \/swapfile\n\n# persist\necho '\/swapfile none swap sw 0 0' &gt;&gt; \/etc\/fstab\n\n# verify\nswapon --show\nfree -h<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Size is workload-dependent. A common starting point is equal to RAM for small instances under 2GB, and half of RAM above that. The goal is headroom for spikes, not a second main memory tier.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Tuning swappiness for NVMe<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>vm.swappiness<\/code> controls how eagerly the kernel reclaims anonymous pages versus page cache. The default of 60 is tuned for desktop responsiveness, not servers. On a VPS with fast NVMe, a moderate value keeps the OOM killer away without excessive paging.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>swappiness<\/th><th>Behavior<\/th><th>Use case<\/th><\/tr><\/thead><tbody><tr><td>0<\/td><td>Nearly avoids swap until OOM<\/td><td>Latency-critical, RAM-rich<\/td><\/tr><tr><td>10<\/td><td>Swaps only under real pressure<\/td><td>Typical VPS server default<\/td><\/tr><tr><td>60<\/td><td>Balanced, desktop-tuned<\/td><td>Interactive desktops<\/td><\/tr><tr><td>100<\/td><td>Aggressive<\/td><td>Rarely appropriate<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># runtime\nsysctl vm.swappiness=10\n\n# persistent\necho 'vm.swappiness=10' &gt; \/etc\/sysctl.d\/99-swap.conf\nsysctl --system<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Also consider <code>vm.vfs_cache_pressure<\/code> if you notice inode and dentry caches being evicted too aggressively under pressure; a lower value (say 50) retains them longer.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Measuring whether swap is hurting you<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The signal that matters is swap-in rate, not swap utilization. A system using 800MB of swap but never swapping back in is fine. A system swapping in tens of MB per second is thrashing. Watch <code>si<\/code> and <code>so<\/code> in <code>vmstat<\/code> over time.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vmstat 1 20\n# si\/so near 0  -&gt; swap is dormant, fine\n# si\/so sustained &gt; few hundred KB\/s -&gt; active paging, investigate\n\n# per-process swap\nfor f in \/proc\/*\/status; do awk \\\n  '\/^Name\/{n=$2}\/^VmSwap\/{if($2&gt;0)print n,$2\"kB\"}' \"$f\"; \\\ndone | sort -k2 -n | tail<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Persistent swap-in under load tells you the working set does not fit. Mitigate by reducing memory consumers or moving to a larger instance. The technical companion is the <a href=\"https:\/\/virtualserversvps.com\/\">managed vs unmanaged breakdown<\/a>, useful when deciding whether to hand tuning and monitoring off to a provider.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Guarding against swap-induced latency spikes<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Place the swapfile on NVMe, never on a network or SATA volume.<\/li><li>Keep swappiness low (10) so warm pages stay in RAM.<\/li><li>Pin latency-critical services with cgroup memory limits so they cannot be evicted wholesale.<\/li><li>Monitor <code>si<\/code>\/<code>so<\/code> alerts rather than swap occupancy.<\/li><\/ul>\n<!-- \/wp:post-content -->\n\n<!-- wp:paragraph -->\n<p>Swap is a safety buffer, not a performance feature. Configure it deliberately, keep it dormant under normal load, and treat any sustained swap-in as a memory-sizing signal. Done that way, it prevents OOM kills without reintroducing the latency problems that gave swap its bad name.<\/p>\n<!-- \/wp:paragraph -->\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Swap has a bad reputation on servers, and mostly for good reason: if a workload actively pages to a slow disk, latency explodes. But swap is not inherently harmful. On&#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":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1271","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>Tuning Linux Swap on an NVMe VPS Without Causing Latency Spikes - Virtual Servers VPS Blog<\/title>\n<meta name=\"description\" content=\"Swap has a bad reputation on servers, and mostly for good reason: if a workload actively pages to a slow disk, latency explodes. But swap is not\" \/>\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\/tuning-linux-swap-nvme-vps-without-latency-spikes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tuning Linux Swap on an NVMe VPS Without Causing Latency Spikes\" \/>\n<meta property=\"og:description\" content=\"Tuning Linux Swap on an NVMe VPS Without Causing Latency Spikes\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/tuning-linux-swap-nvme-vps-without-latency-spikes\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-02T02:00: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=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/tuning-linux-swap-nvme-vps-without-latency-spikes\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/tuning-linux-swap-nvme-vps-without-latency-spikes\/\",\"name\":\"Tuning Linux Swap on an NVMe VPS Without Causing Latency Spikes - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-10-02T02:00:09+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"description\":\"Swap has a bad reputation on servers, and mostly for good reason: if a workload actively pages to a slow disk, latency explodes. But swap is not\",\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/tuning-linux-swap-nvme-vps-without-latency-spikes\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/tuning-linux-swap-nvme-vps-without-latency-spikes\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/tuning-linux-swap-nvme-vps-without-latency-spikes\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tuning Linux Swap on an NVMe VPS Without Causing Latency Spikes\"}]},{\"@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":"Tuning Linux Swap on an NVMe VPS Without Causing Latency Spikes - Virtual Servers VPS Blog","description":"Swap has a bad reputation on servers, and mostly for good reason: if a workload actively pages to a slow disk, latency explodes. But swap is not","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\/tuning-linux-swap-nvme-vps-without-latency-spikes\/","og_locale":"en_US","og_type":"article","og_title":"Tuning Linux Swap on an NVMe VPS Without Causing Latency Spikes","og_description":"Tuning Linux Swap on an NVMe VPS Without Causing Latency Spikes","og_url":"https:\/\/virtualserversvps.com\/blog\/tuning-linux-swap-nvme-vps-without-latency-spikes\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-10-02T02:00:09+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/tuning-linux-swap-nvme-vps-without-latency-spikes\/","url":"https:\/\/virtualserversvps.com\/blog\/tuning-linux-swap-nvme-vps-without-latency-spikes\/","name":"Tuning Linux Swap on an NVMe VPS Without Causing Latency Spikes - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-10-02T02:00:09+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"description":"Swap has a bad reputation on servers, and mostly for good reason: if a workload actively pages to a slow disk, latency explodes. But swap is not","breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/tuning-linux-swap-nvme-vps-without-latency-spikes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/tuning-linux-swap-nvme-vps-without-latency-spikes\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/tuning-linux-swap-nvme-vps-without-latency-spikes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Tuning Linux Swap on an NVMe VPS Without Causing Latency Spikes"}]},{"@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\/1271","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=1271"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1271\/revisions"}],"predecessor-version":[{"id":1272,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1271\/revisions\/1272"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=1271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=1271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=1271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}