摘要 · Summary
Systems · Technical ReportWindows · Linux · macOS · Android
Executive summary · one-page brief
Swap Is Reclaim Fairness, Not Emergency Memory
Five platforms, one mechanism. Anonymous memory — everything a process allocates — is the only page class a kernel cannot reclaim without somewhere to put it. So a system with no swap has not removed memory pressure; it has redirected all of it onto page cache and executable code, which are then re-read from disk again and again. Every major platform now answers this the same way: compress in RAM first, and touch persistent storage only when compression is exhausted. Windows calls it Memory Compression, macOS a compressor pager, Linux and Android call it ZRAM — but the shape is identical, and the trade is always the same one: CPU cycles bought with capacity. What still separates the five is narrow, and only three things matter.
By the Numbers compression & endurance
- ~40%compressed footprint of a page (Windows 10-era figure)
- 3:1typical Linux ZRAM compression ratio
- 2.4 PBwrites absorbed by the longest-surviving consumer SSD
- 16.4 yrlife of a 600 TBW drive written 100 GB every day
The Only Three Axes That Matter everything else is detail
| Axis | The question it asks | Why it decides the design |
|---|---|---|
| Persistent tier | Does storage-backed swap exist at all? | Some Android implementations only resize ZRAM — there is no second tier to spill into. |
| Hibernation | Can the tier hold a suspend-to-disk image? | The one hard functional dividing line: a compressed RAM tier is cleared at boot, so it never can. |
| Operator reach | How much machinery is exposed? | Windows and macOS are effectively automatic; Linux exposes the knobs; Android exposes a slider. |
What Follows 起 · 承 · 轉 · 合
| Beat | Page | What it covers |
|---|---|---|
| 起 · 承 Context | 2 | The two-tier shape every platform converged on, side by side, and why swap still earns its place. |
| 轉 Pivot | 3 | Where the design holds and where it strains — including which vendor claims survive measurement. |
| 合 Resolution | 4 | The path a page actually takes, the knobs that exist, and what to do on each platform. |
Bottom line
Disabling swap does not avoid disk I/O under memory pressure — it relocates the thrashing from anonymous pages onto page cache and program text, which is usually worse.
Reframe
Sustained swap depth is a sizing signal, not a tuning problem. The fix is more RAM, not more swap.
起承 · Context · Content 1 / 3
起 — Two Tiers, Five Names the shape everyone converged on
Tier one · in RAM
The Compressed Tier
- Windows Memory Compression — Xpress-Huffman, into a store held inside the System process.
- macOS compressor pager — WKdm; what lets Apple ship lower RAM configurations at all.
- Linux ZRAM / zswap — zstd, lzo or lz4, typically around 3:1.
- Android ZRAM — always the first line of defence, before any storage is touched.
Tier two · on storage
The Persistent Tier
- Windows
pagefile.sys; a separateswapfile.sysmoves a suspended app's whole working set in one I/O. - Linux partition or file — functionally equal; the file trades a filesystem mapping for flexibility.
- macOS dynamic swapfiles on a dedicated APFS VM volume since Big Sur.
- Android — an optional UFS swapfile; this is what OEM “extended RAM” actually is.
- Windows
Platform by Platform same mechanism, different exposure
| Technology | Backend | Hibernate | Compressed |
|---|---|---|---|
| Windows pagefile | file on NTFS | separate image | yes — Xpress-Huffman |
| Windows swapfile | file, modern apps only | no | yes — per-app store |
| Linux partition | raw partition | yes | no — pair with zswap |
| Linux swapfile | file on the filesystem | yes, with offset | no — pair with zswap |
| Linux ZRAM | block device in RAM | never | yes — it is the point |
| macOS dynamic swap | APFS VM volume | yes | yes — WKdm |
| Android ZRAM | block device in RAM | never | yes — lz4 / zstd |
| Android extended RAM | swapfile on UFS | no | via ZRAM first |
承 — Why Swap Still Earns Its Place prose left · figures right
File-backed pages can be dropped and re-read; anonymous pages have nowhere to go. Without swap they are simply unreclaimable, so the kernel must take every byte it needs from page cache and program text instead. That is why the strongest argument for swap is not capacity but symmetry: it makes both page classes equally eligible for reclaim, and lets the kernel evict whichever is genuinely colder. The endorsement is institutional, not rhetorical — systemd-oomd's own manual page cites this argument and states swap should be enabled for it to work well, because a swapless system reaches livelock faster and starves the very userspace killer meant to rescue it.
- 2page classes made equally reclaimable
- 4.20+kernel with PSI — pressure visible before the OOM killer
轉 · Pivot · Content 2 / 3
轉 — Where It Holds, Where It Strains four dimensions
| Dimension | Holds | Strains |
|---|---|---|
| Hibernation | a real partition or file can hold the image | a compressed RAM tier is cleared at boot — it can never substitute |
| Flash endurance | six consumer SSDs all outlived their ratings, one to 2.4 PB | low-tier eMMC and sustained server writes still need care |
| Vendor claims | probing the filesystem settles it — some do add a real tier | “8 GB + 8 GB = 16 GB” is marketing, not arithmetic |
| Mixing tiers | each tier is sound used on its own | ZRAM beside disk swap invites LRU inversion |
What the Android Slider Actually Does settled by probing, not by prose
| Behaviour | What changes when you move the slider | Cost |
|---|---|---|
| ZRAM target only | No partition and no swap area change — only how much RAM is given to the compressed tier. | CPU |
| Real storage swap | Free space on the data partition drops by exactly the requested amount, while the ZRAM pool is unchanged. | UFS writes |
| Two names, one thing | Scheduler and memory-optimisation branding is not swap; only the GB slider is. | confusion |
| Below 4 GB RAM | Genuinely useful — more background apps survive instead of being killed and reloaded. | worth it |
| 12 GB RAM and up | Rarely reached in daily use; reviewers report smoother animation with it switched off. | dropped frames |
The Endurance Question, Settled prose left · figures right
The fear that swap will wear out a drive is the most persistent objection, and it is largely answered. In the best-known long-run experiment six consumer SSDs were written until they died: the first failure came past 700 TB, and the last survivor absorbed 2.4 PB — every drive far exceeding its rated endurance. Vendors are explicit that a rated figure marks the end of warranty, not the point of failure. The arithmetic makes it concrete: a 600 TBW drive written 100 GB every single day lasts over sixteen years, and almost nobody writes that much. Two cases still deserve care — low-tier eMMC in budget phones, and servers under sustained heavy write load, which should be specified by daily-write rating rather than capacity.
- 6 / 6drives that outlived their rating
- 2cases that still warrant care
Turning Points chronological
- 2015A long-run endurance experiment ends: every consumer SSD tested outlives its rating, the first failing only past 700 TB.
- 2015Windows 10 inserts Memory Compression between paging activity and the pagefile, roughly halving page writes to disk.
- 2018The reclaim-fairness argument is published, reframing swap from emergency reserve to routine mechanism.
- 2018PSI lands in the kernel, letting userspace act on stall time before the OOM killer ever runs.
- 2020macOS moves swap onto a dedicated hidden APFS volume that shares space dynamically with the system.
- 2020→A mainstream distribution ships ZRAM by default and deliberately as the only swap device, avoiding the inversion that mixing tiers invites.
- 2021→Android OEMs ship “extended RAM” sliders — some resize ZRAM only, others genuinely write to storage.
合 · Resolution · Content 3 / 3
合 — The Path a Page Takes six steps, in order
- 01Residentin RAM
- 02Compressstill in RAM
- 03Spillto disk or UFS
- 04PressurePSI reports stall
- 05Act earlyuserspace OOM
- 06Add RAMthe real fix
The Knobs That Actually Exist Linux · defaults in parentheses
| Knob | What it governs | When to move it |
|---|---|---|
| vm.swappiness (60) | How willingly anonymous memory is swapped out relative to reclaiming page cache. | Raise it above 100 when swap is faster than the filesystem, as with ZRAM. |
| vm.vfs_cache_pressure (100) | How aggressively directory and inode caches are reclaimed against page cache. | Rarely. Setting it to zero invites the out-of-memory killer. |
| vm.watermark_scale_factor (10) | When background reclaim wakes, and how much it frees once awake. | Raise it to keep more memory free on a machine prone to sudden allocation spikes. |
| Android LMKD properties | Free-swap and thrashing thresholds that decide which process is killed, and when. | Root only, and per-device — the in-kernel killer was removed years ago. |
Two Postures, Not Five who decides — the vendor, or you
Windows · macOS
Leave It Alone
- Compression and spill are integrated and automatic; there is no tuning to do.
- Disabling the page file costs crash dumps and lowers the commit ceiling — a bad trade.
- On macOS, disabling swap means weakening system protections; the answer is more RAM.
- Watch the pressure indicator, not the swap figure.
Linux · Android
Choose Deliberately
- Decide the tier first — hibernation or not — then size it.
- Copy-on-write filesystems impose real constraints on a swap file; follow their own procedure.
- Pair pressure monitoring with a userspace killer, or nothing acts until the machine stalls.
- On a phone, read the slider as a background-app dial with a frame-rate cost.
Recommendations by platform
- Windows — leave the pagefile system-managed. Disabling it to reclaim a few GB forfeits crash dumps and can destabilise the machine; SSD wear is not a real consideration.
- Linux — pick one tier, not both. ZRAM at half of RAM with zstd for desktops; a real partition or file at least the size of RAM if you hibernate. Never run ZRAM beside disk swap.
- Linux servers — pair PSI with a userspace OOM daemon. Without one, the kernel killer only fires after the machine has already stalled.
- Android — enable it at 4 GB, disable it at 12 GB. Storage is orders of magnitude slower than RAM, and on a flagship the reported cost is dropped frames.
Where it lands
Ask only three questions: do you need hibernation, are you mixing tiers, and is swap depth telling you to buy RAM? Everything else is detail.