{"id":814,"date":"2026-08-06T22:54:12","date_gmt":"2026-08-06T22:54:12","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=814"},"modified":"2026-08-06T22:54:12","modified_gmt":"2026-08-06T22:54:12","slug":"vps-swap-space-swappiness-tuning-guide","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-swappiness-tuning-guide\/","title":{"rendered":"VPS Swap Space: How Much You Need and How to Tune Swappiness"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Swap is disk space the kernel uses when physical RAM is full \u2014 an emergency reservoir that prevents the OOM killer from terminating your processes. Used well, swap saves a MySQL server from being killed during a memory spike. Used badly, it turns an NVMe SSD into slow pretend-RAM and tanks performance. This guide explains how much swap a VPS actually needs and how to tune swappiness and cache pressure for your specific workload.<\/p>\n\n<p class=\"wp-block-paragraph\">The right swap size depends on your RAM, workload, and disk type \u2014 and the same logic applies when you choose the VPS itself. If you are planning a memory-hungry deployment, <a href=\"https:\/\/virtualserversvps.com\/#providers\">compare VPS plans side by side<\/a> in our comparison table to match RAM and storage to the job before you start tuning.<\/p>\n\n<h2 class=\"wp-block-heading\">When Swap Helps (and When It Hurts)<\/h2>\n\n<p class=\"wp-block-paragraph\">Swap helps when a process briefly exceeds available RAM: the kernel pages out cold data, the process survives, and the spike passes. It hurts when the system relies on swap continuously, because every access to a swapped page costs disk latency \u2014 thousands of times slower than RAM. The goal of tuning is to keep swap as an insurance policy, never as part of the working set.<\/p>\n\n<h2 class=\"wp-block-heading\">How Much Swap Do You Need?<\/h2>\n\n<p class=\"wp-block-paragraph\">For modern VPS workloads the old \u201c2x RAM\u201d rule is outdated. On SSD-backed VPS instances a useful baseline is:<\/p>\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>VPS RAM<\/th><th>Recommended swap (SSD\/NVMe)<\/th><\/tr><\/thead><tbody><tr><td>2 GB or less<\/td><td>1\u20132 GB<\/td><\/tr><tr><td>4 GB<\/td><td>2\u20134 GB<\/td><\/tr><tr><td>8 GB<\/td><td>2\u20134 GB<\/td><\/tr><tr><td>16 GB or more<\/td><td>0\u20134 GB (OOM insurance only)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n<p class=\"wp-block-paragraph\">For database servers, prefer extra RAM over extra swap. For bursty web workloads, keep 1\u20132 GB of swap to absorb traffic spikes without killing PHP-FPM workers.<\/p>\n\n<h2 class=\"wp-block-heading\">Swapfile or Swap Partition?<\/h2>\n\n<p class=\"wp-block-paragraph\">A swapfile is easier to create, resize, and remove, and modern kernels handle it just as efficiently as a partition. A dedicated swap partition was the traditional choice on spinning disks. On a VPS, use a swapfile \u2014 you avoid repartitioning the virtual disk entirely, and resizing later is a two-minute job.<\/p>\n\n<h2 class=\"wp-block-heading\">Creating a Swapfile<\/h2>\n\n<p class=\"wp-block-paragraph\">Create and enable a 2 GB swapfile on Ubuntu or Debian:<\/p>\n\n<pre class=\"wp-block-code\"><code>sudo fallocate -l 2G \/swapfile\nsudo chmod 600 \/swapfile\nsudo mkswap \/swapfile\nsudo swapon \/swapfile<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Make it permanent in <code>\/etc\/fstab<\/code>:<\/p>\n\n<pre class=\"wp-block-code\"><code>\/swapfile none swap sw 0 0<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">Verify with:<\/p>\n\n<pre class=\"wp-block-code\"><code>swapon --show\nfree -h<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">Tuning Swappiness<\/h2>\n\n<p class=\"wp-block-paragraph\"><code>swappiness<\/code> (0\u2013100) controls how eagerly the kernel moves pages to swap. The default of 60 is too aggressive for most servers. Typical values:<\/p>\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>vm.swappiness<\/th><th>Effect<\/th><\/tr><\/thead><tbody><tr><td>0\u201310<\/td><td>Swap only to avoid OOM; keeps processes in RAM<\/td><\/tr><tr><td>10\u201330<\/td><td>Good default for web and database servers<\/td><\/tr><tr><td>60<\/td><td>Kernel default; too eager on most VPSes<\/td><\/tr><tr><td>100<\/td><td>Aggressive swapping; not recommended on SSD<\/td><\/tr><\/tbody><\/table><\/figure>\n\n<p class=\"wp-block-paragraph\">Set it for the running system and persist it across reboots:<\/p>\n\n<pre class=\"wp-block-code\"><code>sudo sysctl vm.swappiness=10\necho 'vm.swappiness=10' | sudo tee \/etc\/sysctl.d\/99-swap.conf\nsudo sysctl --system<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">Tuning vm.vfs_cache_pressure<\/h2>\n\n<p class=\"wp-block-paragraph\">The kernel also caches directory and inode metadata. <code>vfs_cache_pressure<\/code> (default 100) controls how quickly that cache is reclaimed: values above 100 reclaim it more aggressively, values below 100 keep it longer. For file-heavy workloads on a server with spare RAM, 50 is a reasonable starting point:<\/p>\n\n<pre class=\"wp-block-code\"><code>echo 'vm.vfs_cache_pressure=50' | sudo tee -a \/etc\/sysctl.d\/99-swap.conf\nsudo sysctl --system<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">SSD Wear and Other Caveats<\/h2>\n\n<p class=\"wp-block-paragraph\">Every swap write wears the flash cells on an SSD. With swappiness at 10 and swap sized as insurance, the write amplification is negligible \u2014 the real risk is a misconfigured server that swaps constantly. Detect that with:<\/p>\n\n<pre class=\"wp-block-code\"><code>vmstat 2   # watch the si and so columns<\/code><\/pre>\n\n<p class=\"wp-block-paragraph\">If <code>si<\/code>\/<code>so<\/code> are consistently non-zero, you need more RAM, not more swap. Also avoid placing swap on the same disk as a busy database when possible, and do not combine zram and a swapfile without understanding how they interact \u2014 running both can double the memory pressure you are trying to relieve.<\/p>\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n<p class=\"wp-block-paragraph\">Swap is cheap insurance: size it modestly, keep swappiness low, and treat constant swapping as a signal to buy more RAM. A 1\u20132 GB swapfile with <code>vm.swappiness=10<\/code> handles traffic spikes on most VPS workloads without turning your SSD into a bottleneck. If you are sizing a new server, check the <a href=\"https:\/\/virtualserversvps.com\/#providers\">full specs and pricing<\/a> in our comparison table and favor instances with enough RAM to make swap a fallback rather than a necessity.<\/p>","protected":false},"excerpt":{"rendered":"<p>Swap is disk space the kernel uses when physical RAM is full \u2014 an emergency reservoir that prevents the OOM killer from terminating your processes. Used well, swap saves 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":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-814","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>VPS Swap Space: How Much You Need and How to Tune Swappiness - 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-swappiness-tuning-guide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"VPS Swap Space: How Much You Need and How to Tune Swappiness\" \/>\n<meta property=\"og:description\" content=\"VPS Swap Space: How Much You Need and How to Tune Swappiness\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-swappiness-tuning-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-06T22:54:12+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\/vps-swap-space-swappiness-tuning-guide\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-swappiness-tuning-guide\/\",\"name\":\"VPS Swap Space: How Much You Need and How to Tune Swappiness - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-08-06T22:54:12+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-swappiness-tuning-guide\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-swappiness-tuning-guide\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-swappiness-tuning-guide\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"VPS Swap Space: How Much You Need and How to Tune Swappiness\"}]},{\"@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":"VPS Swap Space: How Much You Need and How to Tune Swappiness - 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-swappiness-tuning-guide\/","og_locale":"en_US","og_type":"article","og_title":"VPS Swap Space: How Much You Need and How to Tune Swappiness","og_description":"VPS Swap Space: How Much You Need and How to Tune Swappiness","og_url":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-swappiness-tuning-guide\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-08-06T22:54:12+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\/vps-swap-space-swappiness-tuning-guide\/","url":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-swappiness-tuning-guide\/","name":"VPS Swap Space: How Much You Need and How to Tune Swappiness - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-08-06T22:54:12+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-swappiness-tuning-guide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/vps-swap-space-swappiness-tuning-guide\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-swappiness-tuning-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"VPS Swap Space: How Much You Need and How to Tune Swappiness"}]},{"@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\/814","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=814"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/814\/revisions"}],"predecessor-version":[{"id":815,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/814\/revisions\/815"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}