Tratopedia
繁中
Settings

Text size

Language

Theme

High contrast

Version

v1.230.2

The release this page was built from. It is what the service worker caches under.

Slide deck

Back

Swap Across Five Platforms — Compress First, Spill Later

Turning swap off doesn't cut disk I/O under memory pressure — it shifts the thrashing onto page cache and code, usually worse. Windows, macOS and Android now compress in RAM before touching storage. The toughest tested SSD absorbed 2.4 PB before failing.

  1. Operating Systems · Technical Report

    Swap Is Reclaim Fairness, Not Emergency Memory

    Turning swap off doesn't cut disk I/O under memory pressure — it shifts the thrashing onto page cache and code, usually worse.

    Swap Across Five Platforms1 / 20

  2. What Happened

    By the Numbers

    • ~40%compressed footprint of a page (Windows 10, 2015)
    • 2:1compression ratio the Linux kernel's own docs assume when sizing zram
    • 2.4 PBwrites absorbed by the longest-surviving drive in a 2015 SSD endurance test
    • 16.4 yrlife of a 600 TBW drive written 100 GB every day

    Swap Across Five Platforms2 / 20

  3. What Happened

    The Record, Graded

    StandingWhat
    ConfirmedWindows, macOS and Android all compress inactive memory in RAM before writing anything to persistent storage.
    ConfirmedThe Windows compression store uses the plain XPRESS format — not the Huffman-coded XPRESS_HUFF variant used elsewhere in Windows.
    ConfirmedA Btrfs swapfile has been supported since kernel 5.0, but only on a single-device filesystem, with the file itself uncompressed and unchecksummed.
    Confirmed — the exceptionRed Hat Enterprise Linux's own current guide to creating swap names a partition or a file — no compression step at all.
    Confirmed, device-dependentWhich Android OEM's “extended RAM” toggle touches storage, and which only resizes ZRAM.

    Swap Across Five Platforms3 / 20

  4. Timeline

    Turning Points

    1. 2015A long-run endurance experiment ends: six consumer SSDs are written until they fail; every one outlives its rated endurance, the first 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 merges into the Linux kernel, version 4.20, letting userspace act on stall time before the OOM killer ever runs.

    Swap Across Five Platforms4 / 20

  5. Timeline

    Turning Points

    1. 2019Btrfs gains swapfile support in kernel 5.0, with real constraints: the file must sit on a single-device filesystem and go uncompressed.
    2. 2019macOS's APFS boot layout begins requiring a dedicated, hidden volume to hold swap files, from macOS 10.15 onward.
    3. 2020Fedora begins shipping ZRAM as the sole, default swap device from release 33, dropping disk-based swap even where hibernation would otherwise be possible.
    4. 2021→Android OEMs ship “extended RAM” sliders — some resize ZRAM only, others genuinely write to storage.
    5. 2025An adb-based test of two current flagships settles it: one maker's slider only resizes the compressed tier, the other's genuinely writes to storage.

    Swap Across Five Platforms5 / 20

  6. The Argument

    Why Swap Still Earns Its Place

    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

    Swap Across Five Platforms6 / 20

  7. The Argument

    The Only Three Axes That Matter

    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.

    Swap Across Five Platforms7 / 20

  8. The Argument

    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.

    Swap Across Five Platforms8 / 20

  9. What Others Add

    Two Tiers, Five Names

    • Tier one · in RAM

      The Compressed Tier

      CPU spent to buy capacity

    • Tier two · on storage

      The Persistent Tier

      reached only when compression is exhausted

    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

    Swap Across Five Platforms9 / 20

  10. What Others Add

    Platform by Platform

    TechnologyBackendHibernateCompressed
    Windows pagefilefile on NTFSseparate imageyes — XPRESS, plain
    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 / LZ4
    Android ZRAMblock device in RAMneveryes — lz4, zstd or lzo
    Android extended RAMswapfile on UFSnovia ZRAM first

    Swap Across Five Platforms10 / 20

  11. What Others Add

    Where It Holds, Where It Strains

    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

    Swap Across Five Platforms11 / 20

  12. What Others Add

    What the Android Slider Actually Does

    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; one hands-on test found phones that add storage swap slightly less responsive than ZRAM-only ones, though not noticeably on a 16 GB handset.responsiveness

    Swap Across Five Platforms12 / 20

  13. What Others Add

    The Endurance Question, Settled

    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. A drive maker's own endurance guide says so plainly: most manufacturers end the warranty at the rated figure or the time limit, whichever comes first, and consumer drives keep working well beyond their ratings — the rating is a warranty limit, 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.

    Swap Across Five Platforms13 / 20

  14. What Others Add

    The Knobs That Actually Exist

    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.

    Swap Across Five Platforms14 / 20

  15. What Others Add

    The Knobs That Actually Exist

    KnobWhat it governsWhen to move it
    ro.lmk.swap_free_low_percentage (10)The share of free swap, as a percentage, below which lmkd treats the system as swap-starved.Root only, per device — the in-kernel killer was removed once Linux reached 4.12.
    ro.lmk.psi_complete_stall_ms (700)Milliseconds of complete PSI memory stall — every task blocked at once — that triggers a critical-level kill.Lower thresholds (down to 70ms) ship on low-RAM devices; root only.

    Swap Across Five Platforms15 / 20

  16. Conclusion

    Two Postures, Not Five

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

    Swap Across Five Platforms16 / 20

  17. Conclusion

    Two Postures, Not Five

    • 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 small cost in responsiveness.

    Swap Across Five Platforms17 / 20

  18. Conclusion

    Recommendations

    • 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. Avoid running ZRAM beside disk swap wherever you can: cold pages fill the fast tier and push the working set onto disk.

    Swap Across Five Platforms18 / 20

  19. Conclusion

    Recommendations

    • 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 one reported cost is a slight loss of responsiveness.

    Swap Across Five Platforms19 / 20

  20. Conclusion

    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.

    Not one convention

    “Compress first, spill later” describes Windows, macOS, Android, and a zram-enabled Linux desktop. It does not describe Red Hat Enterprise Linux's own current, documented default, which is a partition or a file with no compression step at all. A server built from that default has no compressed tier to hold ground before storage is touched — which is worth checking before assuming the pattern above applies to it.

    Swap Across Five Platforms20 / 20