{"id":1186,"date":"2026-09-15T06:53:55","date_gmt":"2026-09-15T06:53:55","guid":{"rendered":"https:\/\/affordablevpsserver.com\/blog\/?p=1186"},"modified":"2026-09-15T06:53:55","modified_gmt":"2026-09-15T06:53:55","slug":"vps-swap-file-hiding-real-memory-shortage","status":"publish","type":"post","link":"https:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/","title":{"rendered":"Swap File or More RAM? Diagnosing a VPS That Is Quietly Out of Memory"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A 2 GB VPS with a 2 GB swap file will appear healthy for months. Uptime is fine, monitoring shows no crashes, and the site loads &#8212; yet every page takes 300&#8211;900 ms longer than it should. That pattern is a memory shortage being absorbed by swap rather than reported as an incident. The table below separates normal swap use from the kind that means you are under-provisioned.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Swap used<\/th><th>Swap I\/O rate<\/th><th>Interpretation<\/th><th>Action<\/th><\/tr><\/thead><tbody><tr><td>0&#8211;5%<\/td><td>0<\/td><td>Healthy<\/td><td>None<\/td><\/tr><tr><td>5&#8211;25%<\/td><td>0<\/td><td>Cold pages parked, never touched<\/td><td>Watch only<\/td><\/tr><tr><td>5&#8211;25%<\/td><td>Sustained &gt;100 KB\/s<\/td><td>Working set exceeds RAM<\/td><td>Find the consumer, then size up<\/td><\/tr><tr><td>&gt;50%<\/td><td>Any<\/td><td>Active thrashing<\/td><td>Upgrade RAM this week<\/td><\/tr><tr><td>100%<\/td><td>High<\/td><td>OOM kills imminent<\/td><td>Upgrade now<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The distinction that matters is <em>used<\/em> versus <em>actively moving<\/em>. Swap pages that were written once and never read again cost nothing. Swap pages being read back under load cost disk latency on every request &#8212; typically 0.1&#8211;1 ms on NVMe and far worse on network-attached storage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Measure Swap Activity, Not Swap Usage<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. How much is used at all\nfree -m | awk 'NR==3{printf \"swap used: %s MB of %s MB\\n\", $3, $2}'\n\n# 2. Is it actually moving? (run under real load)\nvmstat 5 12 | awk 'NR&gt;2{print \"si:\",$7\" so:\",$8\" KB\/s\"}'\n\n# 3. Which processes were swapped out\nfor pid in $(ls \/proc | grep -E '^[0-9]+$'); do\n  awk '\/VmSwap\/{if($2&gt;1000) print $2\" kB\", \"PID \"'$pid'}' \/proc\/$pid\/status 2&gt;\/dev\/null\ndone | sort -rn | head -10\n\n# 4. Per-device swap I\/O\nsar -W 1 5 2&gt;\/dev\/null || cat \/proc\/vmstat | grep -E 'pswp(in|out)'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Step 3 is the one most people skip. It tells you <em>which<\/em> process is being pushed out. If PHP-FPM workers dominate the list, the pool is too large. If MySQL dominates, the buffer pool is competing with the OS. If a single app worker dominates and grows over days, you have a leak that no RAM tier will fix permanently.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Distinguish Swap Latency From Server Latency<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm swap is the actual culprit before buying anything:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Compare TTFB cold versus warm.<\/strong> If the first request after a quiet period is 2&#8211;5&#215; slower than later ones, pages are being faulted back from swap. The measurement method is covered in our <a href=\"https:\/\/affordablevpsserver.com\/\">latency and TTFB analysis guide<\/a>.<\/li><li><strong>Check disk read latency during traffic.<\/strong> Swap-ins show up as elevated <code>await<\/code> on the swap device in <code>iostat -x<\/code>.<\/li><li><strong>Look at application-level p99.<\/strong> Swap affects tail latency first. A p99 that drifts while p50 stays flat is the classic signature.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Three Temporary Fixes, Ranked<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Reduce the working set (best).<\/strong> Cut PHP-FPM <code>pm.max_children<\/code>, lower <code>innodb_buffer_pool_size<\/code>, cap journald, prune Docker images. This buys real headroom without changing the bill.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># PHP-FPM: size the pool to measured concurrency, not to RAM\/40\npm = dynamic\npm.max_children = 8      # ~8 x 50 MB = 400 MB\npm.start_servers = 3\npm.min_spare_servers = 2\npm.max_spare_servers = 4\n\n# MySQL: leave room for the OS and web tier\n[mysqld]\ninnodb_buffer_pool_size = 512M<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. Tune swappiness down (temporary).<\/strong> Setting <code>vm.swappiness=10<\/code> makes the kernel prefer dropping page cache over swapping application memory. It reduces churn but does not create capacity &#8212; it only delays the symptom.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. Move swap to faster storage or add zram (temporary).<\/strong> Compressed RAM swap (<code>zram<\/code>) can absorb 200&#8211;400 MB of cold pages using far less physical memory than plain swap, and it is much faster than disk. It is a genuine stopgap for a small VPS, though it still consumes the RAM it is trying to save.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sizing Swap Correctly First<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before diagnosing, confirm the swap file itself is not the problem. A common misconfiguration is a swap file created with the wrong permissions or on a filesystem that does not support it well, which produces slow swap even at low utilization.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Installed RAM<\/th><th>Recommended swap<\/th><th>Swappiness<\/th><th>zram worth it?<\/th><\/tr><\/thead><tbody><tr><td>512 MB<\/td><td>1 GB<\/td><td>60<\/td><td>Yes, 256 MB<\/td><\/tr><tr><td>1 GB<\/td><td>1&#8211;2 GB<\/td><td>30&#8211;60<\/td><td>Yes, 512 MB<\/td><\/tr><tr><td>2 GB<\/td><td>2 GB<\/td><td>10&#8211;30<\/td><td>Optional<\/td><\/tr><tr><td>4 GB+<\/td><td>2&#8211;4 GB<\/td><td>10<\/td><td>No<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># Verify the swap file is correct\nswapon --show\nls -l \/swapfile        # expect -rw------- root root, mode 600\nfilefrag -v \/swapfile | head -3   # check for fragmentation\n\n# Fixed-size swapfile, no fragmentation\nsudo swapoff \/swapfile\nsudo fallocate -l 2G \/swapfile\nsudo chmod 600 \/swapfile\nsudo mkswap \/swapfile\nsudo swapon \/swapfile<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The highest swappiness values belong on the smallest servers, because at 512 MB the alternative to swapping is an OOM kill. On a 4 GB server, swap is a crash cushion and nothing more, so swappiness of 10 keeps the kernel from parking live pages there.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When to Stop Tuning and Change the Tier<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Sustained swap throughput above 100 KB\/s after reducing the working set<\/li><li>Available memory below 10% during normal (not peak) hours<\/li><li>p99 latency more than 3&#215; p50 with no application change<\/li><li>Any OOM kill in the journal, regardless of frequency<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Two or more of those means the tier is wrong. One means a specific process needs fixing. Our <a href=\"https:\/\/affordablevpsserver.com\/\">plan comparison with per-tier pricing<\/a> makes the arithmetic explicit: if the next RAM tier costs $3\/month and a swap-driven latency regression costs you conversions, the upgrade is the cheaper option on almost any metric.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Swap is a cushion, not a substitute for capacity. Keep it configured &#8212; a VPS with no swap dies harder when it hits the wall &#8212; but never let it absorb a shortage that a $3 tier change would remove. InterServer&#8217;s flat renewal pricing keeps that upgrade cost predictable year over year: <a href=\"https:\/\/www.interserver.net\/vps?id=1067793\" rel=\"noreferrer noopener sponsored\" target=\"_blank\">check InterServer&#8217;s VPS tiers<\/a>. For a workload with seasonal peaks, <a href=\"https:\/\/www.vultr.com\/?ref=9805352-9J\" rel=\"noreferrer noopener sponsored\" target=\"_blank\">Vultr&#8217;s hourly resizing<\/a> lets you run a bigger tier through the busy month and drop back afterwards.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A 2 GB VPS with a 2 GB swap file will appear healthy for months. Uptime is fine, monitoring shows no crashes, and the site loads &#8212; yet every page takes 300&#8211;900 ms longer than it should. That pattern is a memory shortage being absorbed by swap rather than reported as an incident. The table [&hellip;]<\/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":[2,4],"tags":[],"class_list":["post-1186","post","type-post","status-publish","format-standard","hentry","category-budget-vps-guides","category-cost-optimization-tips"],"blocksy_meta":[],"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 File or More RAM? Diagnosing a VPS That Is Quietly Out of Memory - Affordable VPS Server 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:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Swap File or More RAM? Diagnosing a VPS That Is Quietly Out of Memory\" \/>\n<meta property=\"og:description\" content=\"Swap File or More RAM? Diagnosing a VPS That Is Quietly Out of Memory\" \/>\n<meta property=\"og:url\" content=\"https:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/\" \/>\n<meta property=\"og:site_name\" content=\"Affordable VPS Server Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-15T06:53:55+00:00\" \/>\n<meta name=\"author\" content=\"Affordable-Vps-Server-Author\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Affordable-Vps-Server-Author\" \/>\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:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/\",\"url\":\"https:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/\",\"name\":\"Swap File or More RAM? Diagnosing a VPS That Is Quietly Out of Memory - Affordable VPS Server Blog\",\"isPartOf\":{\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/#website\"},\"datePublished\":\"2026-09-15T06:53:55+00:00\",\"author\":{\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/#\/schema\/person\/685a02c93a3c45030f7427ec928b0df7\"},\"breadcrumb\":{\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/affordablevpsserver.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Swap File or More RAM? Diagnosing a VPS That Is Quietly Out of Memory\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/#website\",\"url\":\"https:\/\/affordablevpsserver.com\/blog\/\",\"name\":\"Affordable VPS Server Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/affordablevpsserver.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/#\/schema\/person\/685a02c93a3c45030f7427ec928b0df7\",\"name\":\"Affordable-Vps-Server-Author\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8fa20973a7dd04621d396c26ba26b5c5e6c19595583335121958527393f6f95e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8fa20973a7dd04621d396c26ba26b5c5e6c19595583335121958527393f6f95e?s=96&d=mm&r=g\",\"caption\":\"Affordable-Vps-Server-Author\"},\"sameAs\":[\"https:\/\/affordablevpsserver.com\/blog\"],\"url\":\"https:\/\/affordablevpsserver.com\/blog\/author\/affordablevpsserver\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Swap File or More RAM? Diagnosing a VPS That Is Quietly Out of Memory - Affordable VPS Server 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:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/","og_locale":"en_US","og_type":"article","og_title":"Swap File or More RAM? Diagnosing a VPS That Is Quietly Out of Memory","og_description":"Swap File or More RAM? Diagnosing a VPS That Is Quietly Out of Memory","og_url":"https:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/","og_site_name":"Affordable VPS Server Blog","article_published_time":"2026-09-15T06:53:55+00:00","author":"Affordable-Vps-Server-Author","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Affordable-Vps-Server-Author","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/","url":"https:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/","name":"Swap File or More RAM? Diagnosing a VPS That Is Quietly Out of Memory - Affordable VPS Server Blog","isPartOf":{"@id":"https:\/\/affordablevpsserver.com\/blog\/#website"},"datePublished":"2026-09-15T06:53:55+00:00","author":{"@id":"https:\/\/affordablevpsserver.com\/blog\/#\/schema\/person\/685a02c93a3c45030f7427ec928b0df7"},"breadcrumb":{"@id":"https:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/affordablevpsserver.com\/blog\/vps-swap-file-hiding-real-memory-shortage\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/affordablevpsserver.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Swap File or More RAM? Diagnosing a VPS That Is Quietly Out of Memory"}]},{"@type":"WebSite","@id":"https:\/\/affordablevpsserver.com\/blog\/#website","url":"https:\/\/affordablevpsserver.com\/blog\/","name":"Affordable VPS Server Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/affordablevpsserver.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/affordablevpsserver.com\/blog\/#\/schema\/person\/685a02c93a3c45030f7427ec928b0df7","name":"Affordable-Vps-Server-Author","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/affordablevpsserver.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8fa20973a7dd04621d396c26ba26b5c5e6c19595583335121958527393f6f95e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8fa20973a7dd04621d396c26ba26b5c5e6c19595583335121958527393f6f95e?s=96&d=mm&r=g","caption":"Affordable-Vps-Server-Author"},"sameAs":["https:\/\/affordablevpsserver.com\/blog"],"url":"https:\/\/affordablevpsserver.com\/blog\/author\/affordablevpsserver\/"}]}},"_links":{"self":[{"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/posts\/1186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/comments?post=1186"}],"version-history":[{"count":1,"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/posts\/1186\/revisions"}],"predecessor-version":[{"id":1191,"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/posts\/1186\/revisions\/1191"}],"wp:attachment":[{"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/media?parent=1186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/categories?post=1186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/tags?post=1186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}