{"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-08-19T23:34:31","modified_gmt":"2026-08-19T23:34:31","slug":"tune-linux-memory-swappiness-vps-performance","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/tune-linux-memory-swappiness-vps-performance\/","title":{"rendered":"How to Tune Linux Memory Swappiness for Better VPS Performance"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><code>vm.swappiness<\/code> is a single kernel parameter that many VPS guides tell you to change \u2014 usually to 10 \u2014 without explaining what it actually does or why the default of 60 is a poor fit for servers. It is not a &#8220;percentage of RAM that will be swapped.&#8221; It is a weighting the kernel uses when it must reclaim memory: how willing it is to evict anonymous (process) memory to swap versus dropping file-backed page cache. Get it wrong and you either swap under no real pressure (wasted disk I\/O) or starve the page cache (re-reads from disk). This guide shows how to measure, set, and verify swappiness for typical VPS workloads.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What swappiness actually controls<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When RAM is full, the kernel must reclaim memory from one of two main pools: page cache (clean copies of files on disk \u2014 cheap to drop, but re-reading costs I\/O) and anonymous pages (process heap and stack \u2014 they must be written to swap before the page can be reused, or the process gets killed by the OOM killer). The swappiness value, on a scale of 0 to 100, biases this choice: low values make the kernel prefer dropping page cache and avoid swapping anonymous memory; high values make it more willing to swap.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The default of 60 was chosen for general-purpose desktops. On a server with a fixed workload, 60 makes the kernel swap pages that are cold but not frozen, producing extra disk I\/O for no benefit. One important correction: <code>vm.swappiness=0<\/code> does <em>not<\/em> disable swapping \u2014 the kernel can still swap to avoid OOM. That is why modern practice says use 1 rather than 0 when you want &#8220;as little swapping as possible.&#8221;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Check your current value<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>sysctl vm.swappiness<\/code> \u2014 prints the current value (typically 60)<\/li>\n<li><code>cat \/proc\/sys\/vm\/swappiness<\/code> \u2014 same value, direct from the kernel<\/li>\n<li><code>swapon --show<\/code> \u2014 confirm swap actually exists; with no swap device, swappiness has nothing to act on<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If there is no swap configured, set that up first \u2014 either a swapfile or zram \u2014 before tuning anything. Our <a href=\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-swappiness-tuning-guide\/\">swapfile vs zram setup guide<\/a> covers creation, sizing, and monitoring.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting swappiness persistently<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Apply immediately (until reboot): <code>sudo sysctl -w vm.swappiness=10<\/code><\/li>\n<li>Make it persistent: create <code>\/etc\/sysctl.d\/99-swappiness.conf<\/code> containing <code>vm.swappiness=10<\/code><\/li>\n<li>Reload: <code>sudo sysctl --system<\/code><\/li>\n<li>Verify: <code>sysctl vm.swappiness<\/code> should now print 10<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Sysctl files under <code>\/etc\/sysctl.d\/<\/code> are applied in lexical order and later files win, so the <code>99-<\/code> prefix guarantees your override beats distro defaults.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Which value for which workload<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Workload<\/th><th>Recommended swappiness<\/th><th>Why<\/th><\/tr><\/thead><tbody><tr><td>General web\/app server with adequate RAM<\/td><td>10<\/td><td>Page cache stays useful; disk I\/O minimized<\/td><\/tr><tr><td>Database (MySQL\/PostgreSQL)<\/td><td>1\u201310<\/td><td>Avoids swapping hot buffer-pool pages; 1 \u2248 swap only to avoid OOM<\/td><\/tr><tr><td>Memory-spike apps (build servers, workers)<\/td><td>10\u201330<\/td><td>Lets the kernel park cold pages during bursts without thrashing<\/td><\/tr><tr><td>Tiny VPS (1\u20132 GB RAM) under constant pressure<\/td><td>10\u201320<\/td><td>Compromise; if pressure is sustained, the real fix is more RAM<\/td><\/tr><tr><td>Desktop \/ interactive session<\/td><td>60 (default)<\/td><td>Desktop responsiveness benefits from the stock behavior<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Why lower swappiness helps \u2014 and when it won&#8217;t<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">On a VPS the win is mostly about I\/O. Swap traffic shares your disk with the database, web server, and logs. Lowering swappiness keeps anonymous pages in RAM longer, so the kernel drops page cache instead \u2014 and page cache can be re-populated with one sequential read, while swapped pages cost random I\/O in both directions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The catch: if your server is already under genuine memory pressure \u2014 PSI memory <code>some avg10<\/code> above 10%, or continuously non-zero <code>si<\/code>\/<code>so<\/code> in <code>vmstat 1<\/code> \u2014 swappiness tuning will not save you. You are out of RAM; add RAM or shrink the footprint. Swappiness is a reclaim-policy dial, not a memory multiplier. Before tuning, record a baseline with <code>free -h<\/code>, <code>vmstat 1<\/code>, and <code>cat \/proc\/pressure\/memory<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verifying the change helped<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Record a baseline: <code>si<\/code>\/<code>so<\/code> over 24 hours plus application latency percentiles.<\/li>\n<li>Apply the new value and wait 24\u201348 hours \u2014 reclaim behavior needs time to show up in metrics.<\/li>\n<li>Compare: <code>si<\/code>\/<code>so<\/code> should be lower or unchanged, and page-cache hit ratios (InnoDB buffer pool stats, nginx cache hits) should not regress.<\/li>\n<li>If latency got worse, revert: <code>sudo sysctl -w vm.swappiness=60<\/code> and remove the sysctl.d file.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Do not expect <code>free -h<\/code> to show more available RAM. Swappiness does not free memory \u2014 it changes where reclaimed pages come from.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">cgroups v2 and containers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">On cgroup v2 systems (Ubuntu 22.04+, Debian 12+, most current images), the host-wide <code>vm.swappiness<\/code> applies to the root cgroup. Containers can override it per-cgroup via the <code>memory.swappiness<\/code> file in their cgroup directory. For a plain VPS running services directly on the host, tuning the global value is sufficient; if you run Docker, be aware containers inherit the host value unless you set <code>memory.swappiness<\/code> explicitly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common mistakes<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Tuning swappiness with no swap configured \u2014 the parameter does nothing.<\/li>\n<li>Setting 0 expecting &#8220;no swap ever&#8221; \u2014 the kernel still swaps to avoid OOM; use 1.<\/li>\n<li>Expecting it to fix genuine RAM exhaustion \u2014 measure PSI first.<\/li>\n<li>Copying &#8220;swappiness=10&#8221; without checking the workload \u2014 a memory-spike app may need 30.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Swappiness is one small knob in a larger memory strategy, and the best tuning is buying the right amount of RAM in the first place. <a href=\"https:\/\/virtualserversvps.com\/#features\">See the full specs and pricing<\/a> for memory and storage options, and <a href=\"https:\/\/virtualserversvps.com\/#providers\">compare providers on our comparison table<\/a> so you pick a box with enough headroom that this knob rarely matters.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>vm.swappiness is a single kernel parameter that many VPS guides tell you to change \u2014 usually to 10 \u2014 without explaining what it actually does or why the default of&#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":[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>How to Tune Linux Memory Swappiness for Better VPS Performance - Virtual Servers VPS Blog<\/title>\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=\"How to Tune Linux Memory Swappiness for Better VPS Performance\" \/>\n<meta property=\"og:description\" content=\"How to Tune Linux Memory Swappiness for Better VPS Performance\" \/>\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 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=\"4 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\":\"How to Tune Linux Memory Swappiness for Better VPS Performance - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-08-19T23:34:31+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"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\":\"How to Tune Linux Memory Swappiness for Better VPS Performance\"}]},{\"@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":"How to Tune Linux Memory Swappiness for Better VPS Performance - Virtual Servers VPS Blog","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":"How to Tune Linux Memory Swappiness for Better VPS Performance","og_description":"How to Tune Linux Memory Swappiness for Better VPS Performance","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","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"4 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":"How to Tune Linux Memory Swappiness for Better VPS Performance - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-08-19T23:34:31+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"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":"How to Tune Linux Memory Swappiness for Better VPS Performance"}]},{"@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":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/923\/revisions"}],"predecessor-version":[{"id":926,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/923\/revisions\/926"}],"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}]}}