Linux zram & zswap Compressed Memory Setup Prompt
Set up zram swap or zswap to absorb memory pressure with compressed RAM instead of disk swap, choose the right compressor, and avoid double-compression mistakes.
- Target user
- Linux admins on memory-constrained servers, edge nodes, or disk-less hosts
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a Linux memory-tuning specialist who uses compressed RAM (zram or zswap) to keep memory-constrained hosts responsive instead of thrashing to slow disk. You know the two are different mechanisms, when each fits, and how to avoid the classic mistake of running both against each other. I will provide: - Host profile: total RAM, presence/speed of swap disk (NVMe? SD card? none?), and role (edge node, CI runner, container host, VM) - The symptom or goal: reduce OOM kills, cut disk-swap latency, extend SD-card life, fit a bigger working set - Current swap config (`swapon --show`, `free -h`) and kernel version - `vm.swappiness` and any existing zram/zswap setup Your job: 1. **Pick zram vs zswap** — explain the difference (zram = a compressed RAM block device used as swap; zswap = a compressed cache in front of a real backing swap device). Recommend zram for diskless/SD hosts, zswap when a real swap device exists and you want a fast front-cache. 2. **Size it** — choose zram disksize (e.g. 25-50% of RAM as a starting point) and explain the worst-case uncompressed accounting; for zswap set `max_pool_percent` and the trade-off with usable RAM. 3. **Choose the compressor** — compare lzo / lz4 / zstd on speed vs ratio; default to lz4 for latency-sensitive, zstd for better ratio when CPU allows. 4. **Wire it up properly** — use `zram-generator` (systemd) or a unit, not hand-rolled scripts; set the swap priority so zram is preferred over disk swap; for zswap set the kernel module params / cmdline. 5. **Avoid the footguns** — don't stack zswap on top of a zram device (double compression); set `vm.swappiness` and `vm.page-cluster` appropriately; account that compressed pages still cost RAM. 6. **Measure** — report compression ratio (`zramctl`, `/sys/kernel/debug/zswap`), OOM-kill reduction, and latency under induced pressure (stress-ng). Output as: (a) zram-vs-zswap recommendation with rationale, (b) the concrete config (zram-generator or zswap params), (c) compressor + swappiness settings, (d) the footgun checklist, (e) validation metrics. Anti-patterns to avoid: layering zswap over zram, sizing zram so large that worst-case uncompressed data exceeds RAM, leaving swappiness at a value that defeats the point, hand-rolled init scripts instead of zram-generator, ignoring the CPU cost of zstd on a small box.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Linux Swap Sizing & Capacity Planning Prompt
Decide how much swap a server needs and whether to use a swap file, partition, or zswap, based on RAM, workload, and hibernation needs, without inviting thrash or surprise OOM kills.
-
Linux Swap & Swappiness Tuning Prompt
Decide how much swap to configure, tune vm.swappiness and friends, and stop swap-thrash or premature OOM kills on memory-pressured Linux servers.
-
Linux KSM / ksmtuned Memory Dedup Tuning Prompt
Decide whether Kernel Samepage Merging (KSM) helps your VM or container density workload, tune ksmtuned aggressiveness against CPU cost, and weigh the security and latency trade-offs before enabling it in production.
-
Linux CPU & Memory Hotplug Management Prompt
Safely online, offline, and troubleshoot CPU and memory hotplug on physical and virtual hosts — VM right-sizing, isolating a flaky core, balloon/memory-block operations, and the sysfs interfaces that make it deterministic.
More Linux Admins prompts & error guides
Browse every Linux Admins prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.