{"id":882,"date":"2026-08-13T23:15:01","date_gmt":"2026-08-13T23:15:01","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=882"},"modified":"2026-08-13T23:15:01","modified_gmt":"2026-08-13T23:15:01","slug":"vps-swap-space-sizing-configuration-guide","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-sizing-configuration-guide\/","title":{"rendered":"Swap Space on a VPS: How Much to Configure and When It Hurts Performance"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Swap is the most misunderstood resource on a small VPS. Configured correctly, it is a safety net that prevents the OOM killer from terminating your database during a traffic spike. Configured as a substitute for RAM, it turns your server into a thrashing disk-bound machine that is slower than the shared hosting you left behind. The old &#8220;2x your RAM&#8221; rule from the 2000s no longer applies to modern VPS workloads, and the right answer depends on your RAM tier, your application, and whether you use zram. This guide covers swap file vs partition, sizing by RAM tier, the swappiness setting, and how to tell when swap is masking a real memory problem. If your provider&#8217;s smallest plan forces constant swap usage, our <a href=\"https:\/\/virtualserversvps.com\/#providers\">provider comparison table<\/a> can help you find one with adequate RAM for the same budget.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What swap actually does<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Swap is disk space that the kernel uses as an overflow for memory pages. When physical RAM fills up, the kernel writes cold pages to swap and reclaims their RAM for active work. Reading a page back from disk is orders of magnitude slower than reading it from RAM (a modern NVMe delivers ~2&nbsp;GB\/s; RAM delivers 20\u201350&nbsp;GB\/s with far lower latency), so the goal is to use swap rarely and temporarily, not continuously.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How much swap: sizing by RAM tier<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Modern sizing guidance depends on total RAM and what the workload is:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>VPS RAM<\/th><th>Recommended swap<\/th><th>Rationale<\/th><\/tr><\/thead><tbody><tr><td>512 MB \u2013 1 GB<\/td><td>1\u20132 GB<\/td><td>Needed as a real overflow; keep swappiness low<\/td><\/tr><tr><td>2 GB<\/td><td>1\u20132 GB<\/td><td>Safety net for spikes; not a RAM substitute<\/td><\/tr><tr><td>4 GB<\/td><td>1\u20132 GB<\/td><td>Mostly for OOM safety during brief peaks<\/td><\/tr><tr><td>8 GB+<\/td><td>0\u20132 GB or zram<\/td><td>Swap rarely helps; consider zram instead<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">These values assume a typical web or database workload. A server running in-memory caches (Redis with <code>maxmemory<\/code> set correctly) should never need disk swap at all.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Swap file vs swap partition<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">On modern Linux, a swap <strong>file<\/strong> is the better default on a VPS. You can create, resize, or remove it without repartitioning the disk, which matters when your provider&#8217;s console does not expose partition tools. A swap <strong>partition<\/strong> survives some edge cases (for example, swap on a separate disk that the root filesystem cannot mount) and is preferred in a few embedded or boot-critical setups, but for a standard VPS the file is simpler and equally fast on SSD\/NVMe. Create a 2&nbsp;GB file with <code>fallocate -l 2G \/swapfile<\/code>, secure it with <code>chmod 600 \/swapfile<\/code>, run <code>mkswap \/swapfile<\/code>, enable it with <code>swapon \/swapfile<\/code>, and add it to <code>\/etc\/fstab<\/code> with the <code>sw<\/code> option so it survives reboots.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Swappiness: the setting everyone argues about<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>vm.swappiness<\/code> (0\u2013100) controls how aggressively the kernel moves anonymous memory pages to swap. The default of 60 is too high for most VPS workloads; it causes the kernel to swap under moderate pressure when it should instead drop clean page cache. Set <code>vm.swappiness = 10<\/code> in <code>\/etc\/sysctl.d\/99-vps.conf<\/code> (<code>sysctl -p<\/code> to apply) for most servers: the kernel keeps working set pages in RAM and only swaps when pressure is genuine. Keep it near 0 on database servers, and consider values of 20\u201340 only on RAM-starved boxes that must stay alive during spikes. Also set <code>vm.vfs_cache_pressure = 50<\/code> if you want the kernel to retain inode\/dentry caches longer under memory pressure.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When swap hurts performance<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Swap becomes a liability in three situations. First, <strong>thrashing<\/strong>: when the working set exceeds RAM, the kernel continuously writes and reads pages, and throughput collapses to disk speed; the server looks &#8220;busy&#8221; but nothing completes. Second, <strong>latency amplification<\/strong>: a single swapped-out page fault can add 10\u2013100&nbsp;ms to a request that would take 1&nbsp;ms in RAM. Third, and most important, <strong>masked problems<\/strong>: if swap usage grows steadily over days, you have a memory leak or an undersized allocation, and adding more swap just postpones the crash while degrading every request. Diagnose with <code>free -h<\/code> (watch the <code>si<\/code>\/<code>so<\/code> columns in <code>vmstat 5<\/code> for active paging) and check <code>dmesg<\/code> for OOM-killer events.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">zram: the modern alternative on small VPS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">zram creates a compressed block device in RAM and uses it as swap. Compression typically gives 2\u20133x effective memory for compressible data, and because it never touches disk, it avoids the latency cliff entirely. It is the right choice on 512&nbsp;MB\u20132&nbsp;GB VPS plans where disk-backed swap would thrash. Set <code>zram0<\/code> to about half your RAM (for example, 1&nbsp;GB on a 2&nbsp;GB VPS) and keep a small disk swap file as a final fallback. The kernel handles the zram-to-disk overflow automatically. Note that zram consumes CPU for compression, so it suits modest workloads better than heavy database loads.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Monitoring and fixing the real problem<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>free -h<\/code> \u2014 total, used, and swap usage at a glance.<\/li>\n<li><code>vmstat 5<\/code> \u2014 <code>si<\/code>\/<code>so<\/code> columns show actual pages swapped in\/out; sustained non-zero values mean real paging.<\/li>\n<li><code>dmesg | grep -i oom<\/code> \u2014 reveals OOM-killer activity that swap should have prevented.<\/li>\n<li><code>systemctl status<\/code> and per-process RSS (<code>ps aux --sort=-rss | head<\/code>) \u2014 find the process that is leaking or over-allocating.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If monitoring shows continuous paging, the fix is more RAM or a smaller workload, not more swap. When your application&#8217;s memory needs outgrow the plan, upgrading RAM on most providers takes minutes; compare RAM-per-dollar across hosts in our <a href=\"https:\/\/virtualserversvps.com\/#providers\">provider comparison table<\/a> before you pay for another month of thrashing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you would rather have a platform where memory sizing and scaling are handled for you, Cloudways manages the underlying VPS and lets you scale RAM vertically in a few clicks without reconfiguring swap yourself. <a href=\"https:\/\/cloudways.com\/en\/?id=2010927&amp;data1=virtualserversvps\" rel=\"noreferrer noopener sponsored\" target=\"_blank\">Start a free Cloudways trial<\/a> and test your workload against properly sized instances.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Swap is the most misunderstood resource on a small VPS. Configured correctly, it is a safety net that prevents the OOM killer from terminating your database during a traffic spike&#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":1,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-882","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>Swap Space on a VPS: How Much to Configure and When It Hurts 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\/vps-swap-space-sizing-configuration-guide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Swap Space on a VPS: How Much to Configure and When It Hurts Performance\" \/>\n<meta property=\"og:description\" content=\"Swap Space on a VPS: How Much to Configure and When It Hurts Performance\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-sizing-configuration-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-13T23:15:01+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\/vps-swap-space-sizing-configuration-guide\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-sizing-configuration-guide\/\",\"name\":\"Swap Space on a VPS: How Much to Configure and When It Hurts Performance - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-08-13T23:15:01+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-sizing-configuration-guide\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-sizing-configuration-guide\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-sizing-configuration-guide\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Swap Space on a VPS: How Much to Configure and When It Hurts 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":"Swap Space on a VPS: How Much to Configure and When It Hurts 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\/vps-swap-space-sizing-configuration-guide\/","og_locale":"en_US","og_type":"article","og_title":"Swap Space on a VPS: How Much to Configure and When It Hurts Performance","og_description":"Swap Space on a VPS: How Much to Configure and When It Hurts Performance","og_url":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-sizing-configuration-guide\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-08-13T23:15:01+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\/vps-swap-space-sizing-configuration-guide\/","url":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-sizing-configuration-guide\/","name":"Swap Space on a VPS: How Much to Configure and When It Hurts Performance - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-08-13T23:15:01+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-sizing-configuration-guide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/vps-swap-space-sizing-configuration-guide\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-sizing-configuration-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Swap Space on a VPS: How Much to Configure and When It Hurts 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\/882","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=882"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/882\/revisions"}],"predecessor-version":[{"id":884,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/882\/revisions\/884"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}