{"id":923,"date":"2026-08-19T23:34:31","date_gmt":"2026-08-19T23:34:31","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=923"},"modified":"2026-10-03T22:05:00","modified_gmt":"2026-10-03T22:05:00","slug":"tune-linux-memory-swappiness-vps-performance","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/tune-linux-memory-swappiness-vps-performance\/","title":{"rendered":"vm.swappiness on a VPS: What the Kernel Actually Does and How to Measure It"},"content":{"rendered":"<p class=\"wp-block-paragraph\"><code>vm.swappiness<\/code> is the single kernel knob most VPS guides tell you to set to 10 and then forget. That advice is not wrong, but it is cargo-cult: it explains the value, not the mechanism. Swappiness is a relative reclaim weight, not a percentage of RAM. Understanding what it biases lets you choose a value for your workload instead of copying one from a forum post. This guide covers the reclaim model, how to measure the effect under real pressure, and how to verify the change actually took effect.<\/p>\n<h2 class=\"wp-block-heading\">The reclaim decision swappiness controls<\/h2>\n<p class=\"wp-block-paragraph\">When free memory runs short, the kernel reclaims from two pools. File-backed page cache is cheap to discard &mdash; it is a clean copy of something already on disk, but re-reading it later costs I\/O. Anonymous pages (heap and stack) cannot simply be dropped; they must be written to swap first, or the process dies under the OOM killer. Swappiness on a 0&#8211;100 scale biases that choice. Low values push the kernel toward dropping clean cache before touching anonymous memory. High values make the kernel more willing to swap. The default of 60 was tuned for desktop interactivity, where a burst of swapping beats re-reading application binaries. A fixed server workload has different economics.<\/p>\n<h2 class=\"wp-block-heading\">Why 60 is usually wrong on a server<\/h2>\n<p class=\"wp-block-paragraph\">On a VPS you typically know which pages matter. A database with a large resident working set does not want that working set paged out to satisfy a filesystem scan. A web front-end with a warm page cache would rather keep cached assets than push long-idle PHP workers into swap. The server-tuned value of 10 tells the kernel: only swap once reclaim from cache has been exhausted. That is the right default for most VPS roles. The exceptions are workloads with a genuinely cold, large anonymous footprint &mdash; batch jobs and idle daemons &mdash; where letting some of it swap frees cache for hot data.<\/p>\n<h2 class=\"wp-block-heading\">Set and persist the value<\/h2>\n<p class=\"wp-block-paragraph\">Change it at runtime for a test, then persist it:<\/p>\n<pre class=\"wp-block-code\"><code>sysctl -w vm.swappiness=10\necho 'vm.swappiness=10' | sudo tee \/etc\/sysctl.d\/99-swappiness.conf\nsysctl --system<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Confirm the running value rather than trusting the file: <code>cat \/proc\/sys\/vm\/swappiness<\/code>. A container may mask or override the host value, so verify inside the workload namespace if you run one.<\/p>\n<h2 class=\"wp-block-heading\">Measure the effect instead of guessing<\/h2>\n<p class=\"wp-block-paragraph\">The right way to validate any swappiness change is to watch swap-in rate during steady-state load, not total swap used. Swap that filled once and never moves again is harmless; continuous swap-in is what causes latency spikes. Track it:<\/p>\n<pre class=\"wp-block-code\"><code>vmstat 1 10        # si\/so columns: swap-in and swap-out per second\ngrep -E 'pswpin|pswpout' \/proc\/vmstat<\/code><\/pre>\n<p class=\"wp-block-paragraph\">A healthy tuned server shows <code>si<\/code> and <code>so<\/code> near zero after warm-up. Persistent nonzero swap-out under moderate load means the anonymous working set exceeds RAM and no swappiness value will save you &mdash; you need more memory or a smaller working set. Pair the measurement with PSI to see whether memory pressure, not swap, is the bottleneck:<\/p>\n<pre class=\"wp-block-code\"><code>cat \/proc\/pressure\/memory<\/code><\/pre>\n<h2 class=\"wp-block-heading\">The zero-swappiness myth<\/h2>\n<p class=\"wp-block-paragraph\">A persistent piece of advice claims <code>vm.swappiness=0<\/code> disables swapping entirely. It does not. On modern kernels 0 means swap is used only to avoid an out-of-memory condition &mdash; an emergency valve, not a wall. If you set 0 and the anonymous working set still exceeds RAM, the kernel swaps anyway (or OOM-kills); you have removed the gradual, graceful reclaim that could have bought you time. A value of 0 is defensible for a latency-critical database where any swap-in is unacceptable and you have sized RAM with margin; it is a poor default for a general web host, where the occasional cold page swapping out is cheaper than an OOM kill. Choose 0 only with monitoring in place to alert on <code>pswpin<\/code> the moment it moves.<\/p>\n<h2 class=\"wp-block-heading\">Page cache versus swap on shared storage<\/h2>\n<p class=\"wp-block-paragraph\">The decisive factor is often the backing device, not the number. On a VPS with a shared NVMe swap file, a swap-in is a random read that competes with every other tenant&rsquo;s database I\/O on the same physical device &mdash; latency is unpredictable and can spike into the tens of milliseconds. Dropping a clean page-cache entry costs nothing but a future re-read, which on the same device is equally priced. This asymmetry is why the answer is workload-specific: if your hot data lives on that device anyway, keeping cache and avoiding swap is a wash, so lean low. If your working set is small and fits in RAM, swappiness barely matters because reclaim rarely runs. Measure <code>\/proc\/vmstat<\/code> over a full day before deciding you have a swap problem at all.<\/p>\n<h2 class=\"wp-block-heading\">Interactions you should not ignore<\/h2>\n<p class=\"wp-block-paragraph\">Swappiness does not act alone. <code>vm.min_free_kbytes<\/code> controls the reserve the kernel keeps to satisfy atomic allocations &mdash; too low and you get allocation stalls before reclaim even starts. If you run zram, the &#8220;swap&#8221; device is compressed RAM, so swap-in is much cheaper and a higher swappiness can be defensible. On a swap file hosted on shared NVMe, swap-out competes with database I\/O, which is precisely why the low-swappiness default exists. When you are sizing a plan to leave enough headroom to avoid swapping altogether, our <a href=\"https:\/\/virtualserversvps.com\/\">VPS comparison page<\/a> breaks down RAM-per-dollar and disk type per tier. If you are still deciding between instance sizes, the same page covers which configurations include dedicated CPU and NVMe versus shared storage. With <a href=\"https:\/\/virtualserversvps.com\/\">performance VPS plans<\/a> you can compare which tiers ship with enough RAM and NVMe to make the low-swappiness default comfortable. The one-line rule: default to 10, raise it only when the anonymous working set is deliberately cold, and lower it further only after proving swap-in is negligible.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>vm.swappiness is the single kernel knob most VPS guides tell you to set to 10 and then forget. That advice is not wrong, but it is cargo-cult: it explains the&#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":8,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-923","post","type-post","status-publish","format-standard","hentry","category-performance-optimization"],"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>vm.swappiness on a VPS: What the Kernel Actually Does and How to Measure It - Virtual Servers VPS Blog<\/title>\n<meta name=\"description\" content=\"vm.swappiness is the single kernel knob most VPS guides tell you to set to 10 and then forget. That advice is not wrong, but it is cargo-cult: it explains\" \/>\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\/tune-linux-memory-swappiness-vps-performance\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"vm.swappiness on a VPS: What the Kernel Actually Does and How to Measure It\" \/>\n<meta property=\"og:description\" content=\"vm.swappiness on a VPS: What the Kernel Actually Does and How to Measure It\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/tune-linux-memory-swappiness-vps-performance\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-19T23:34:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-03T22:05:00+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\/tune-linux-memory-swappiness-vps-performance\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/tune-linux-memory-swappiness-vps-performance\/\",\"name\":\"vm.swappiness on a VPS: What the Kernel Actually Does and How to Measure It - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-08-19T23:34:31+00:00\",\"dateModified\":\"2026-10-03T22:05:00+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"description\":\"vm.swappiness is the single kernel knob most VPS guides tell you to set to 10 and then forget. That advice is not wrong, but it is cargo-cult: it explains\",\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/tune-linux-memory-swappiness-vps-performance\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/tune-linux-memory-swappiness-vps-performance\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/tune-linux-memory-swappiness-vps-performance\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"vm.swappiness on a VPS: What the Kernel Actually Does and How to Measure It\"}]},{\"@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":"vm.swappiness on a VPS: What the Kernel Actually Does and How to Measure It - Virtual Servers VPS Blog","description":"vm.swappiness is the single kernel knob most VPS guides tell you to set to 10 and then forget. That advice is not wrong, but it is cargo-cult: it explains","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\/tune-linux-memory-swappiness-vps-performance\/","og_locale":"en_US","og_type":"article","og_title":"vm.swappiness on a VPS: What the Kernel Actually Does and How to Measure It","og_description":"vm.swappiness on a VPS: What the Kernel Actually Does and How to Measure It","og_url":"https:\/\/virtualserversvps.com\/blog\/tune-linux-memory-swappiness-vps-performance\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-08-19T23:34:31+00:00","article_modified_time":"2026-10-03T22:05:00+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\/tune-linux-memory-swappiness-vps-performance\/","url":"https:\/\/virtualserversvps.com\/blog\/tune-linux-memory-swappiness-vps-performance\/","name":"vm.swappiness on a VPS: What the Kernel Actually Does and How to Measure It - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-08-19T23:34:31+00:00","dateModified":"2026-10-03T22:05:00+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"description":"vm.swappiness is the single kernel knob most VPS guides tell you to set to 10 and then forget. That advice is not wrong, but it is cargo-cult: it explains","breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/tune-linux-memory-swappiness-vps-performance\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/tune-linux-memory-swappiness-vps-performance\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/tune-linux-memory-swappiness-vps-performance\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"vm.swappiness on a VPS: What the Kernel Actually Does and How to Measure It"}]},{"@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\/923","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=923"}],"version-history":[{"count":3,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/923\/revisions"}],"predecessor-version":[{"id":1288,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/923\/revisions\/1288"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}