中文

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

AxisThe question it asksWhy it decides the design
Persistent tierDoes storage-backed swap exist at all?Some Android implementations only resize ZRAM — there is no second tier to spill into.
HibernationCan 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 reachHow much machinery is exposed?Windows and macOS are effectively automatic; Linux exposes the knobs; Android exposes a slider.

What Follows 起 · 承 · 轉 · 合

BeatPageWhat it covers
起 · 承 Context2The two-tier shape every platform converged on, side by side, and why swap still earns its place.
轉 Pivot3Where the design holds and where it strains — including which vendor claims survive measurement.
合 Resolution4The 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.

Sources · kernel.org /proc/sys/vm · Microsoft Learn · Red Hat · AOSP LMKD · Btrfs docs · Chris Down, In defence of swap (2018) · TechReport SSD Endurance Experiment (2015)

起 — Two Tiers, Five Names the shape everyone converged on

  • Tier one · in RAM

    The Compressed Tier

    CPU spent to buy capacity

    • 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

    reached only when compression is exhausted

    • Windows pagefile.sys; a separate swapfile.sys moves 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.

Platform by Platform same mechanism, different exposure

TechnologyBackendHibernateCompressed
Windows pagefilefile on NTFSseparate imageyes — Xpress-Huffman
Windows swapfilefile, modern apps onlynoyes — per-app store
Linux partitionraw partitionyesno — pair with zswap
Linux swapfilefile on the filesystemyes, with offsetno — pair with zswap
Linux ZRAMblock device in RAMneveryes — it is the point
macOS dynamic swapAPFS VM volumeyesyes — WKdm
Android ZRAMblock device in RAMneveryes — lz4 / zstd
Android extended RAMswapfile on UFSnovia 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

Sources · Chris Down, In defence of swap · systemd-oomd(8) · kernel.org PSI documentation · Btrfs upstream documentation

轉 — Where It Holds, Where It Strains four dimensions

DimensionHoldsStrains
Hibernationa real partition or file can hold the imagea compressed RAM tier is cleared at boot — it can never substitute
Flash endurancesix consumer SSDs all outlived their ratings, one to 2.4 PBlow-tier eMMC and sustained server writes still need care
Vendor claimsprobing the filesystem settles it — some do add a real tier“8 GB + 8 GB = 16 GB” is marketing, not arithmetic
Mixing tierseach tier is sound used on its ownZRAM beside disk swap invites LRU inversion

What the Android Slider Actually Does settled by probing, not by prose

BehaviourWhat changes when you move the sliderCost
ZRAM target onlyNo partition and no swap area change — only how much RAM is given to the compressed tier.CPU
Real storage swapFree space on the data partition drops by exactly the requested amount, while the ZRAM pool is unchanged.UFS writes
Two names, one thingScheduler and memory-optimisation branding is not swap; only the GB slider is.confusion
Below 4 GB RAMGenuinely useful — more background apps survive instead of being killed and reloaded.worth it
12 GB RAM and upRarely 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

  1. 2015A long-run endurance experiment ends: every consumer SSD tested outlives its rating, the first failing only past 700 TB.
  2. 2015Windows 10 inserts Memory Compression between paging activity and the pagefile, roughly halving page writes to disk.
  3. 2018The reclaim-fairness argument is published, reframing swap from emergency reserve to routine mechanism.
  4. 2018PSI lands in the kernel, letting userspace act on stall time before the OOM killer ever runs.
  5. 2020macOS moves swap onto a dedicated hidden APFS volume that shares space dynamically with the system.
  6. 2020→A mainstream distribution ships ZRAM by default and deliberately as the only swap device, avoiding the inversion that mixing tiers invites.
  7. 2021→Android OEMs ship “extended RAM” sliders — some resize ZRAM only, others genuinely write to storage.

Sources · TechReport SSD Endurance Experiment · Microsoft Learn · Android Authority (adb probe of shipping handsets) · vendor documentation

合 — The Path a Page Takes six steps, in order

  1. 01Residentin RAM
  2. 02Compressstill in RAM
  3. 03Spillto disk or UFS
  4. 04PressurePSI reports stall
  5. 05Act earlyuserspace OOM
  6. 06Add RAMthe real fix

The Knobs That Actually Exist Linux · defaults in parentheses

KnobWhat it governsWhen 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 propertiesFree-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

    the vendor has already chosen

    • 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

    the defaults are not the decision

    • 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.