{"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-22T22:02:56","modified_gmt":"2026-09-22T22:02:56","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 vs RAM: Diagnosing a VPS Quietly Running 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 &mdash; yet every page takes 300&ndash;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&ndash;5%<\/td><td>0<\/td><td>Healthy<\/td><td>None<\/td><\/tr><tr><td>5&ndash;25%<\/td><td>0<\/td><td>Cold pages parked, never touched<\/td><td>Watch only<\/td><\/tr><tr><td>5&ndash;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 &mdash; typically 0.1&ndash;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&ndash;5&times; 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 &mdash; 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&ndash;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&ndash;2 GB<\/td><td>30&ndash;60<\/td><td>Yes, 512 MB<\/td><\/tr><tr><td>2 GB<\/td><td>2 GB<\/td><td>10&ndash;30<\/td><td>Optional<\/td><\/tr><tr><td>4 GB+<\/td><td>2&ndash;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. If measurement shows you are genuinely short on memory after tuning the working set, compare RAM tiers by price per usable gigabyte on <a href=\"https:\/\/affordablevpsserver.com\/#providers\">the provider comparison table<\/a> rather than jumping a full plan tier on gut feeling.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Swap usage alone tells you nothing. This guide separates harmless cold pages from active thrashing, shows which process is being pushed out, and explains when to tune the working set versus buy more RAM.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2,"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 vs RAM: Diagnosing a VPS Quietly Running Out of Memory - Affordable VPS Server Blog<\/title>\n<meta name=\"description\" content=\"Swap usage alone tells you nothing. This guide separates harmless cold pages from active thrashing, shows which process is being pushed out, and explains when to tune the working set versus buy more RAM.\" \/>\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 vs RAM: Diagnosing a VPS Quietly Running Out of Memory\" \/>\n<meta property=\"og:description\" content=\"Swap vs RAM: Diagnosing a VPS Quietly Running 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 property=\"article:modified_time\" content=\"2026-09-22T22:02:56+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 vs RAM: Diagnosing a VPS Quietly Running Out of Memory - Affordable VPS Server Blog\",\"isPartOf\":{\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/#website\"},\"datePublished\":\"2026-09-15T06:53:55+00:00\",\"dateModified\":\"2026-09-22T22:02:56+00:00\",\"author\":{\"@id\":\"https:\/\/affordablevpsserver.com\/blog\/#\/schema\/person\/685a02c93a3c45030f7427ec928b0df7\"},\"description\":\"Swap usage alone tells you nothing. This guide separates harmless cold pages from active thrashing, shows which process is being pushed out, and explains when to tune the working set versus buy more RAM.\",\"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 vs RAM: Diagnosing a VPS Quietly Running 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 vs RAM: Diagnosing a VPS Quietly Running Out of Memory - Affordable VPS Server Blog","description":"Swap usage alone tells you nothing. This guide separates harmless cold pages from active thrashing, shows which process is being pushed out, and explains when to tune the working set versus buy more RAM.","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 vs RAM: Diagnosing a VPS Quietly Running Out of Memory","og_description":"Swap vs RAM: Diagnosing a VPS Quietly Running 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","article_modified_time":"2026-09-22T22:02:56+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 vs RAM: Diagnosing a VPS Quietly Running Out of Memory - Affordable VPS Server Blog","isPartOf":{"@id":"https:\/\/affordablevpsserver.com\/blog\/#website"},"datePublished":"2026-09-15T06:53:55+00:00","dateModified":"2026-09-22T22:02:56+00:00","author":{"@id":"https:\/\/affordablevpsserver.com\/blog\/#\/schema\/person\/685a02c93a3c45030f7427ec928b0df7"},"description":"Swap usage alone tells you nothing. This guide separates harmless cold pages from active thrashing, shows which process is being pushed out, and explains when to tune the working set versus buy more RAM.","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 vs RAM: Diagnosing a VPS Quietly Running 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":2,"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/posts\/1186\/revisions"}],"predecessor-version":[{"id":1253,"href":"https:\/\/affordablevpsserver.com\/blog\/wp-json\/wp\/v2\/posts\/1186\/revisions\/1253"}],"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}]}}