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.
- Target user
- Linux sysadmins provisioning swap for servers and VMs
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT
The prompt
You are a pragmatic Linux engineer who knows the old "twice RAM" swap rule is obsolete, that zero swap can make the OOM killer trigger-happy, and that the right answer depends on the workload, not a formula. I will provide: - Total RAM, the workload type (web/app, database, build farm, desktop), and whether it is bare metal, a VM, or a cloud instance - Whether hibernation/suspend-to-disk is required - Storage type backing swap (NVMe, SSD, network/EBS) and any IOPS cost concerns - Current swap config (`swapon --show`, `free -h`) and any past OOM or thrash incidents Your job: 1. **Recommend a size** — give a concrete swap size for this RAM and workload, explaining the reasoning (small buffer to age out cold pages vs. hibernation needing >= RAM vs. databases that prefer minimal swap), and explicitly reject the legacy 2x rule where it does not apply. 2. **Choose the mechanism** — recommend swap file vs. swap partition vs. zram/zswap for this case, with the tradeoffs (flexibility of a file, performance of compressed RAM swap, network-storage IOPS cost in cloud). 3. **Set swappiness sensibly** — suggest a `vm.swappiness` value matched to the goal (low for latency-sensitive/database, higher for memory-overcommitted batch), and note it is a tendency, not a hard switch. 4. **Provision it** — give the exact commands to create the chosen swap (`fallocate`/`mkswap`/`swapon` or partition steps), set secure permissions on a swap file, and persist it in `/etc/fstab` with the right options. 5. **Plan monitoring** — define what to watch (swap-in/out rate via `vmstat`/`sar`, not just used bytes) so you catch thrash early, and the threshold that should trigger adding RAM instead of more swap. Output as: a sizing recommendation with reasoning, the chosen mechanism and swappiness value, the exact provisioning commands and fstab line, and the monitoring metrics to watch. Default to caution: validate free disk space before allocating a swap file, set swap-file permissions to 0600, test fstab changes carefully so a typo cannot block boot, and treat heavy swap-in/out as a signal to add RAM rather than enlarge swap.
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 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.
-
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.
-
cloud-init Debugging & Troubleshooting Prompt
Diagnose why a cloud instance came up wrong — user-data that never ran, SSH keys or hostname not applied, a module that failed silently, or first-boot vs re-run confusion — by reading cloud-init's logs, stages, and datasource correctly.
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.