{"id":1585,"date":"2026-11-02T22:38:11","date_gmt":"2026-11-02T22:38:11","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=1585"},"modified":"2026-11-02T22:38:11","modified_gmt":"2026-11-02T22:38:11","slug":"zswap-zbud-zstd-compressed-swap-memory-vps","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/zswap-zbud-zstd-compressed-swap-memory-vps\/","title":{"rendered":"zswap Compressed Swap on a VPS: zbud vs zstd and How to Measure It"},"content":{"rendered":"<div style=\"padding:20px\">\n<p>Swap on a VPS has a bad reputation, and on spinning disks or network-attached storage that reputation is deserved. Compressed swap changes the arithmetic entirely: instead of writing evicted anonymous pages to a block device, zswap intercepts them before they reach the disk, compresses them into a RAM pool, and only writes to swap when that pool is full. On a small instance with a fast CPU and a slow disk, this can turn a latency cliff into a gentle slope. This guide covers how zswap works, how to choose between its zbud and zstd compressors, and how to measure whether it is actually helping on your workload. For broader memory-tuning context, the <a href=\"https:\/\/virtualserversvps.com\/\">memory management reference on this site<\/a> is a useful companion.<\/p>\n<h2>Where zswap sits in the write path<\/h2>\n<p>When the kernel decides to reclaim an anonymous page, zswap first checks whether the swap device is a rotational disk or slow device. If it is, the page is compressed and stored in a RAM-backed pool. Only if the pool hits its limit does zswap write out the least-recently-used compressed pages to the real swap device, where they stay in compressed form.<\/p>\n<p>The consequence is a two-tier swap: a fast in-RAM tier absorbing most of the traffic, and a slow disk tier acting as overflow. For workloads that touch a modest working set periodically &mdash; a database cache warming cycle, a build process with a large heap &mdash; the RAM tier absorbs nearly all of it.<\/p>\n<p>This differs from zram, which creates a compressed block device and replaces the swap target entirely, with no disk backing and therefore no overflow. On a VPS with a modest swap file, zswap is usually the better fit.<\/p>\n<h2>Prerequisites and how to check<\/h2>\n<p>zswap needs a swap device configured and the kernel module available. Most mainline kernels include it, but vendor kernels vary.<\/p>\n<pre><code>grep -i zswap \/boot\/config-$(uname -r)\nls \/sys\/module\/zswap\/parameters\/\ncat \/sys\/module\/zswap\/parameters\/enabled\ncat \/sys\/module\/zswap\/parameters\/compressor<\/code><\/pre>\n<p>If the parameters directory exists, the module is available and can be enabled at runtime. Enable it at boot rather than only at runtime, and confirm after the next restart that it took effect.<\/p>\n<h2>Choosing a compressor: zbud versus zstd<\/h2>\n<p>The compressor determines both the compression ratio and the CPU cost per page. zbud is the oldest option and is deliberately simple: it stores pages in small buddy pairs and only compresses if the result fits in a single page. Its CPU cost is negligible, but it stores many pages uncompressed.<\/p>\n<p>zstd compresses every page, achieving ratios in the region of 2:1 to 3:1 on typical application memory, at a moderate CPU cost. On a modern vCPU this is a few percent of one core under typical reclaim load.<\/p>\n<p>lz4 is the middle option: near-zbud CPU cost with better ratios, and the sensible default for most VPS workloads.<\/p>\n<table>\n<thead>\n<tr>\n<th>Compressor<\/th>\n<th>Typical ratio<\/th>\n<th>CPU cost<\/th>\n<th>Best for<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>zbud<\/td>\n<td>1.2&ndash;1.6:1<\/td>\n<td>Very low<\/td>\n<td>CPU-constrained instances<\/td>\n<\/tr>\n<tr>\n<td>lz4<\/td>\n<td>2:1<\/td>\n<td>Low<\/td>\n<td>General default<\/td>\n<\/tr>\n<tr>\n<td>lzo-rle<\/td>\n<td>2:1<\/td>\n<td>Low&ndash;moderate<\/td>\n<td>Legacy, still common<\/td>\n<\/tr>\n<tr>\n<td>zstd<\/td>\n<td>2.5&ndash;3:1<\/td>\n<td>Moderate<\/td>\n<td>Severe memory pressure<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Sizing the pool and the acceptance threshold<\/h2>\n<p>The pool limit defaults to a small fraction of RAM. On a 4 GB instance, that leaves most of the benefit untapped. Set it to roughly 15&ndash;25% of total RAM, which is enough to hold the compressed form of a large fraction of swap-resident pages without competing with the page cache.<\/p>\n<pre><code>echo zstd &gt; \/sys\/module\/zswap\/parameters\/compressor\necho 20 &gt; \/sys\/module\/zswap\/parameters\/max_pool_percent\necho Y &gt; \/sys\/module\/zswap\/parameters\/enabled<\/code><\/pre>\n<p>The <code>accept_threshold_percent<\/code> parameter controls which pages are stored at all: pages whose compressed size exceeds a fraction of the original are written straight to disk instead. Leaving it near the default is fine for zstd; raising it slightly lets more pages into the pool at the cost of using RAM on poorly compressible data.<\/p>\n<h2>Measuring whether it works<\/h2>\n<p>The critical counters live in the debug filesystem. <code>pool_total_size<\/code> tells you how much RAM the pool occupies and <code>stored_pages<\/code> how many pages are compressed there. The ratio of pages written to disk versus pages stored is the real indicator of effectiveness.<\/p>\n<pre><code>grep -E \"pool_total_size|stored_pages|pool_limit_hit|written_back_pages\" \/sys\/kernel\/debug\/zswap\/*\ncat \/proc\/vmstat | grep -E \"pswpout|pgmajfault\"<\/code><\/pre>\n<p>If <code>written_back_pages<\/code> stays near zero while <code>stored_pages<\/code> climbs, the RAM tier is absorbing the traffic as intended. If <code>pool_limit_hit<\/code> grows steadily, the pool is too small and pages are being forced out to disk &mdash; but at least they leave in compressed form, so the disk write volume is still reduced.<\/p>\n<p>Compare <code>pswpout<\/code> with and without zswap enabled for the same workload. A well-tuned configuration on a memory-constrained instance typically cuts swap-out volume by 60&ndash;80%, with the remainder being pages that were evicted from the pool.<\/p>\n<h2>The latency question<\/h2>\n<p>Compressed swap is not free. A page fault that hits the zswap pool costs a decompression, which is on the order of microseconds, contrasted with a disk read at hundreds of microseconds for local NVMe and milliseconds for a network volume. The difference is not subtle, and it is why zswap changes the behaviour of memory-constrained workloads so dramatically.<\/p>\n<p>The measurement that matters is page-fault latency, not throughput. Use <code>perf<\/code> or the fault counters in <code>\/proc\/vmstat<\/code> alongside a workload that touches more anonymous memory than the instance has.<\/p>\n<pre><code>perf stat -e page-faults,major-faults -a sleep 60\nawk '\/pgmajfault\/ {print $2}' \/proc\/vmstat<\/code><\/pre>\n<h2>Interaction with databases and the OOM killer<\/h2>\n<p>Databases generally perform worse when their buffer pool spills, and compressed swap does not change that: the fix is a bigger instance or a smaller buffer pool, not swap tuning. Where zswap helps is with application-tier processes whose memory grows in bursts &mdash; JVM heaps, PHP-FPM children, build jobs.<\/p>\n<p>It also buys the OOM killer some headroom: more time to reclaim before it decides to kill, which turns a hard out-of-memory event into a period of degraded performance.<\/p>\n<p>Keep <code>vm.swappiness<\/code> at a moderate value of roughly 60. Very low values suppress swapping and leave zswap with nothing to do.<\/p>\n<h2>A reasonable configuration to start from<\/h2>\n<p>Enable zswap with lz4, set the pool to 20% of RAM, keep the acceptance threshold default, and ensure swappiness is at the kernel default. Measure swap-out volume and major fault rate for a week, then try zstd if the pool is consistently full. On a small instance with slow storage, the change is often the difference between a workload that stays responsive under memory pressure and one that stalls for seconds at a time.<\/p>\n<p>As with every kernel tuning change, keep a note of what you configured, why, and what the counters looked like before the change. That record is what makes the next adjustment a measurement rather than a guess. For more memory and swap tuning experiments, see the <a href=\"https:\/\/virtualserversvps.com\/\">kernel tuning guides on virtualserversvps.com<\/a>.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Swap on a VPS has a bad reputation, and on spinning disks or network-attached storage that reputation is deserved. Compressed swap changes the arithmetic entirely: instead of writing evicted anonymous&#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":[1],"tags":[],"class_list":["post-1585","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>zswap Compressed Swap on a VPS: zbud vs zstd and How to Measure It - Virtual Servers VPS Blog<\/title>\n<meta name=\"description\" content=\"Swap on a VPS has a bad reputation, and on spinning disks or network-attached storage that reputation is deserved. Compressed swap changes the arithmetic\" \/>\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\/zswap-zbud-zstd-compressed-swap-memory-vps\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"zswap Compressed Swap on a VPS: zbud vs zstd and How to Measure It\" \/>\n<meta property=\"og:description\" content=\"zswap Compressed Swap on a VPS: zbud vs zstd and How to Measure It\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/zswap-zbud-zstd-compressed-swap-memory-vps\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-02T22:38:11+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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/zswap-zbud-zstd-compressed-swap-memory-vps\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/zswap-zbud-zstd-compressed-swap-memory-vps\/\",\"name\":\"zswap Compressed Swap on a VPS: zbud vs zstd and How to Measure It - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-11-02T22:38:11+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"description\":\"Swap on a VPS has a bad reputation, and on spinning disks or network-attached storage that reputation is deserved. Compressed swap changes the arithmetic\",\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/zswap-zbud-zstd-compressed-swap-memory-vps\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/zswap-zbud-zstd-compressed-swap-memory-vps\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/zswap-zbud-zstd-compressed-swap-memory-vps\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"zswap Compressed Swap on a VPS: zbud vs zstd and How to Measure It\"}]},{\"@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":"zswap Compressed Swap on a VPS: zbud vs zstd and How to Measure It - Virtual Servers VPS Blog","description":"Swap on a VPS has a bad reputation, and on spinning disks or network-attached storage that reputation is deserved. Compressed swap changes the arithmetic","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\/zswap-zbud-zstd-compressed-swap-memory-vps\/","og_locale":"en_US","og_type":"article","og_title":"zswap Compressed Swap on a VPS: zbud vs zstd and How to Measure It","og_description":"zswap Compressed Swap on a VPS: zbud vs zstd and How to Measure It","og_url":"https:\/\/virtualserversvps.com\/blog\/zswap-zbud-zstd-compressed-swap-memory-vps\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-11-02T22:38:11+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/zswap-zbud-zstd-compressed-swap-memory-vps\/","url":"https:\/\/virtualserversvps.com\/blog\/zswap-zbud-zstd-compressed-swap-memory-vps\/","name":"zswap Compressed Swap on a VPS: zbud vs zstd and How to Measure It - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-11-02T22:38:11+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"description":"Swap on a VPS has a bad reputation, and on spinning disks or network-attached storage that reputation is deserved. Compressed swap changes the arithmetic","breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/zswap-zbud-zstd-compressed-swap-memory-vps\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/zswap-zbud-zstd-compressed-swap-memory-vps\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/zswap-zbud-zstd-compressed-swap-memory-vps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"zswap Compressed Swap on a VPS: zbud vs zstd and How to Measure It"}]},{"@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\/1585","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=1585"}],"version-history":[{"count":2,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1585\/revisions"}],"predecessor-version":[{"id":1587,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1585\/revisions\/1587"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=1585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=1585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=1585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}