{"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-19T22:12:36","modified_gmt":"2026-08-19T22:12:36","slug":"vps-swap-space-swappiness-tuning-guide","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/vps-swap-space-swappiness-tuning-guide\/","title":{"rendered":"Swapfile vs zram on a VPS: Setup, Monitoring, and Swappiness"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Swap is the emergency reservoir Linux uses when physical RAM runs out \u2014 and on a VPS it is either a lifesaver or the thing that makes your server feel ten times slower. The difference is not just how much swap you configure, but what kind: a swapfile on disk, a swap partition, or zram compressed RAM. This guide covers creating and enabling each, monitoring real swap pressure, and the swappiness defaults that keep the kernel from leaning on disk unnecessarily.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Swapfile, partition, or zram?<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Type<\/th><th>Speed<\/th><th>Best use case<\/th><\/tr><\/thead><tbody><tr><td>Swapfile<\/td><td>Disk I\/O speed<\/td><td>Default choice on VPSes; easy to create and resize<\/td><\/tr><tr><td>Swap partition<\/td><td>Disk I\/O speed<\/td><td>Only if the provider image already includes one; hard to resize<\/td><\/tr><tr><td>zram<\/td><td>RAM speed (compressed)<\/td><td>Small VPS with tight disk I\/O; bursty memory spikes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A swapfile costs nothing until used and takes minutes to create on any filesystem that supports it (ext4, xfs, btrfs). A partition requires repartitioning the disk, which most VPS control panels make awkward. zram uses a slice of RAM compressed roughly 2\u20134x, so it never touches disk \u2014 at the cost of some CPU and usable RAM.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating a swapfile<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Check existing swap: <code>swapon --show<\/code> (empty output = none) and <code>free -h<\/code>.<\/li>\n<li>Create the file: <code>sudo fallocate -l 2G \/swapfile<\/code>. If <code>fallocate<\/code> fails on your filesystem, use <code>sudo dd if=\/dev\/zero of=\/swapfile bs=1M count=2048 status=progress<\/code>.<\/li>\n<li>Restrict permissions: <code>sudo chmod 600 \/swapfile<\/code> \u2014 world-readable swap can expose credentials that were swapped out.<\/li>\n<li>Format it: <code>sudo mkswap \/swapfile<\/code><\/li>\n<li>Enable it: <code>sudo swapon \/swapfile<\/code><\/li>\n<li>Make it persistent: add <code>\/swapfile none swap sw 0 0<\/code> to <code>\/etc\/fstab<\/code>.<\/li>\n<li>Verify: <code>sudo swapon --show<\/code> and <code>free -h<\/code> \u2014 the Swap line should show your new size.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">How much swap is enough<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The old &#8220;2x RAM&#8221; rule is wrong for VPSes. Swap on a small plan shares disk I\/O with your real workload, so oversized swap turns a memory crisis into a disk crisis. Practical sizing: 1\u20132 GB on plans up to 4 GB RAM \u2014 enough to ride out spikes and keep the OOM killer idle \u2014 and 2\u20134 GB on larger plans for safety. If an application consistently needs more than that, buy more RAM instead: swap is a safety net, not a RAM upgrade.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">zram: compressed swap in RAM<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install: <code>sudo apt install -y zram-tools<\/code> (Debian\/Ubuntu).<\/li>\n<li>Configure <code>\/etc\/default\/zramswap<\/code>: set <code>ALGO=zstd<\/code> and <code>SIZE=1024<\/code> (MiB) \u2014 start at about half your free RAM.<\/li>\n<li>Start it: <code>sudo systemctl enable --now zramswap<\/code><\/li>\n<li>Verify: <code>swapon --show<\/code> should list <code>\/dev\/zram0<\/code>.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">zram shines on small VPSes where a memory spike would otherwise push pages to a shared disk: the &#8220;swap&#8221; stays in RAM, so recovering from a spike is fast. It is a poor fit when you genuinely need more memory than the box has \u2014 for example a database larger than RAM \u2014 because then disk swap is the only option and the right fix is a bigger plan.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Monitoring swap pressure<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>free -h<\/code> \u2014 how much swap is in use. Used swap is not automatically bad; the kernel parks cold pages there.<\/li>\n<li><code>vmstat 1<\/code> \u2014 the <code>si<\/code> and <code>so<\/code> columns show pages swapped in and out per second. Sustained non-zero values mean real pressure and disk-bound thrash.<\/li>\n<li><code>cat \/proc\/pressure\/memory<\/code> \u2014 PSI (pressure stall information): the <code>some avg10<\/code> line shows the percentage of time processes stalled on memory. Above roughly 10% sustained means memory is the bottleneck.<\/li>\n<li><code>swapon --show<\/code> \u2014 which devices are active and their priority.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Rule of thumb: occasional <code>si<\/code>\/<code>so<\/code> activity during a spike is fine. If both columns are continuously non-zero while <code>free<\/code> shows RAM nearly full, you are out of memory and swap is papering over it \u2014 the fix is more RAM or a smaller footprint, not more swap.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Swappiness defaults that matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The kernel&#8217;s <code>vm.swappiness<\/code> parameter (default 60) controls how eagerly the kernel swaps anonymous memory versus reclaiming page cache. On VPSes with disk-backed swap, a high value causes needless disk I\/O; most server workloads run better at 10. Check yours with <code>sysctl vm.swappiness<\/code>. Because a value of 0 does not fully disable swapping (the kernel still swaps to avoid the OOM killer), 1\u201310 is the practical floor for latency-sensitive applications. Deep per-workload tuning of this parameter is its own topic \u2014 the defaults above already keep the kernel from treating your swapfile as a scratch disk.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Configure swap before you need it: an OOM kill during a traffic spike is a 2 a.m. emergency, while a 2 GB swapfile is a two-minute task now. And when you size your next plan, remember that swap depends on fast storage: <a href=\"https:\/\/virtualserversvps.com\/#features\">see the full specs and pricing<\/a> on storage type before you decide, and <a href=\"https:\/\/virtualserversvps.com\/#providers\">compare providers on our comparison table<\/a> \u2014 a plan with NVMe-backed swap recovers from memory spikes far faster than one on shared, slower storage.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Swap is the emergency reservoir Linux uses when physical RAM runs out \u2014 and on a VPS it is either a lifesaver or the thing that makes your server feel&#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":8,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-814","post","type-post","status-publish","format-standard","hentry","category-vps-guides-tutorials"],"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>Swapfile vs zram on a VPS: Setup, Monitoring, and 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=\"Swapfile vs zram on a VPS: Setup, Monitoring, and Swappiness\" \/>\n<meta property=\"og:description\" content=\"Swapfile vs zram on a VPS: Setup, Monitoring, and 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 property=\"article:modified_time\" content=\"2026-08-19T22:12:36+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=\"4 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\":\"Swapfile vs zram on a VPS: Setup, Monitoring, and Swappiness - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-08-06T22:54:12+00:00\",\"dateModified\":\"2026-08-19T22:12:36+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\":\"Swapfile vs zram on a VPS: Setup, Monitoring, and 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":"Swapfile vs zram on a VPS: Setup, Monitoring, and 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":"Swapfile vs zram on a VPS: Setup, Monitoring, and Swappiness","og_description":"Swapfile vs zram on a VPS: Setup, Monitoring, and 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","article_modified_time":"2026-08-19T22:12:36+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"4 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":"Swapfile vs zram on a VPS: Setup, Monitoring, and Swappiness - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-08-06T22:54:12+00:00","dateModified":"2026-08-19T22:12:36+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":"Swapfile vs zram on a VPS: Setup, Monitoring, and 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":2,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/814\/revisions"}],"predecessor-version":[{"id":922,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/814\/revisions\/922"}],"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}]}}