{"id":440,"date":"2026-06-17T11:31:57","date_gmt":"2026-06-17T11:31:57","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=440"},"modified":"2026-06-17T11:31:57","modified_gmt":"2026-06-17T11:31:57","slug":"vps-swap-space-configure-optimize-linux","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux\/","title":{"rendered":"VPS Swap Space: How to Configure and Optimize Swap on Linux VPS"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Swap space acts as emergency overflow memory on a Linux VPS. When your server runs out of physical RAM, the kernel moves inactive memory pages to swap on disk, preventing the Out-Of-Memory (OOM) killer from terminating your applications. Properly configuring swap is especially important on low-RAM VPS plans where memory is tight and workloads can spike unpredictably. <a href=\"https:\/\/virtualserversvps.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Compare VPS plans on our site<\/a> to see which ones offer enough RAM to minimize swap dependency.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Much Swap Should a VPS Have?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The old rule of thumb \u2014 &#8220;swap should be 2\u00d7 RAM&#8221; \u2014 no longer applies to modern VPS environments. SSDs make swap faster than spinning disks, but swap is still orders of magnitude slower than RAM. For Linux VPS servers, use these guidelines:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Physical RAM<\/th><th>Recommended Swap Size<\/th><th>Use Case<\/th><\/tr><\/thead><tbody><tr><td>512 MB \u2013 1 GB<\/td><td>1 GB \u2013 2 GB<\/td><td>Budget VPS, very swap-dependent<\/td><\/tr><tr><td>2 GB<\/td><td>1 GB \u2013 2 GB<\/td><td>General web hosting with occasional spikes<\/td><\/tr><tr><td>4 GB<\/td><td>1 GB \u2013 2 GB<\/td><td>Sufficient RAM for most workloads<\/td><\/tr><tr><td>8 GB+<\/td><td>512 MB \u2013 1 GB<\/td><td>Swap as a safety net only<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If your VPS consistently uses more than 50% of swap, you need more RAM, not more swap. Adding swap space does not fix a RAM shortage \u2014 it only delays the inevitable performance degradation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Checking Current Swap Usage<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before modifying swap, check what is already configured:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Show swap summary\nswapon --show\n\n# Or use free -h for a memory overview\nfree -h\n\n# Check how much swap is actually in use\ncat \/proc\/meminfo | grep -i swap<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These commands tell you whether swap is enabled, how large it is, and how much is being actively used. If <code>swapon --show<\/code> returns nothing, you have no swap configured at all.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating a Swap File on Linux VPS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Modern Linux systems use a swap file (not a swap partition), which is easy to resize. Here is how to add a 2 GB swap file on Ubuntu or Debian:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. Create a 2 GB swap file\nfallocate -l 2G \/swapfile\n\n# 2. Set correct permissions (root only)\nchmod 600 \/swapfile\n\n# 3. Format as swap\nmkswap \/swapfile\n\n# 4. Enable swap\nswapon \/swapfile\n\n# 5. Make permanent (adds to \/etc\/fstab)\necho '\/swapfile none swap sw 0 0' | tee -a \/etc\/fstab<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Verify with <code>swapon --show<\/code> and <code>free -h<\/code>. The new swap should appear in both outputs immediately.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Tuning the Swappiness Parameter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The kernel parameter <code>vm.swappiness<\/code> controls how aggressively the system swaps memory pages. Values range from 0 to 100:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>0<\/strong>: Only swap when absolutely necessary (OOM risk).<\/li>\n<li><strong>10<\/strong>: Good for VPS \u2014 avoids swap unless memory pressure is real.<\/li>\n<li><strong>60<\/strong>: Default \u2014 conservative but may swap unnecessarily on low-RAM VPS.<\/li>\n<li><strong>100<\/strong>: Aggressive swapping \u2014 rarely useful outside embedded systems.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Check your current value with <code>cat \/proc\/sys\/vm\/swappiness<\/code>. Change it temporarily with <code>sysctl vm.swappiness=10<\/code>, or permanently by adding <code>vm.swappiness=10<\/code> to <code>\/etc\/sysctl.conf<\/code> and running <code>sysctl -p<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Resizing or Removing Swap<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To resize an existing swap file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Turn off swap\nswapoff \/swapfile\n\n# Remove old file\nrm \/swapfile\n\n# Create new file with desired size (e.g., 4 GB)\nfallocate -l 4G \/swapfile\nchmod 600 \/swapfile\nmkswap \/swapfile\nswapon \/swapfile<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure you have enough free RAM before running <code>swapoff<\/code> \u2014 all pages currently in swap need to be moved back into physical memory, which can temporarily spike RAM usage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Swap on SSD vs. HDD VPS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If your VPS uses NVMe or SATA SSDs, swap performance is acceptable for occasional use. On HDD-based VPS, swap is painfully slow \u2014 a single random I\/O operation takes ~10 ms on HDD vs. ~0.1 ms on SSD. Avoid relying on swap with HDD storage; upgrade RAM instead. Most modern VPS providers use SSDs exclusively, but it is worth verifying with your provider before purchasing a budget plan.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Proper swap configuration is a simple but impactful optimization for any Linux VPS. Set a reasonable swap size, tune swappiness to 10, and monitor usage with <code>free -h<\/code> during peak traffic. If swap usage stays above 25% consistently, <a href=\"https:\/\/virtualserversvps.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">check out VPS plans on our site<\/a> with more RAM to eliminate the bottleneck entirely.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Swap space acts as emergency overflow memory on a Linux VPS. When your server runs out of physical RAM, the kernel moves inactive memory pages to swap on disk, preventing&#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-440","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 to Configure and Optimize Swap on Linux VPS - 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-configure-optimize-linux\/\" \/>\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 to Configure and Optimize Swap on Linux VPS\" \/>\n<meta property=\"og:description\" content=\"VPS Swap Space: How to Configure and Optimize Swap on Linux VPS\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-06-17T11:31:57+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-configure-optimize-linux\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux\/\",\"name\":\"VPS Swap Space: How to Configure and Optimize Swap on Linux VPS - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-06-17T11:31:57+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"VPS Swap Space: How to Configure and Optimize Swap on Linux VPS\"}]},{\"@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 to Configure and Optimize Swap on Linux VPS - 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-configure-optimize-linux\/","og_locale":"en_US","og_type":"article","og_title":"VPS Swap Space: How to Configure and Optimize Swap on Linux VPS","og_description":"VPS Swap Space: How to Configure and Optimize Swap on Linux VPS","og_url":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-06-17T11:31:57+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-configure-optimize-linux\/","url":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux\/","name":"VPS Swap Space: How to Configure and Optimize Swap on Linux VPS - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-06-17T11:31:57+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-configure-optimize-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"VPS Swap Space: How to Configure and Optimize Swap on Linux VPS"}]},{"@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\/440","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=440"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/440\/revisions"}],"predecessor-version":[{"id":447,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/440\/revisions\/447"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}