logoalt Hacker News

JohnBootyyesterday at 1:59 AM1 replyview on HN

Windows 10+ and Linux also have memory compression, though I don't know how the implementations compare.

Although, I guess Windows 3.1 and 95 users enjoyed it first thanks to this extremely high quality third-party implementation!

https://en.wikipedia.org/wiki/SoftRAM


Replies

alwillisyesterday at 5:54 PM

> Windows 10+ and Linux also have memory compression, though I don't know how the implementations compare.

A combination of Apple's Unified Memory Architecture (UMA) and hardware-accelerated instructions (SIMD/NEON) makes RAM compression on Macs very efficient. Because the storage controller is integrated into the SoC, the bandwidth is high enough that the transition between "Compressed RAM" and "Swap" is very smooth.

And because the CPU and GPU share the same memory, there are no wasted cycles moving data between VRAM and System RAM.

Apple uses WKDM (Wilson-Kaplan Direct Mapping), a specialized, high-speed compression algorithm designed specifically for in-memory data. WKDM is "architecturally aware"—it was built to compress the specific types of data structures found in a computer's RAM, such as pointers, integers, and memory addresses. WKDM treats RAM like a collection of 64-bit integers and pointers; and it's designed to fit entirely in L1/L2 cache [1]. This shipped in MacOS 10.9 Mavericks in 2013.

Windows/Linux treat RAM like a stream of bytes (similar to how you’d compress a .zip file) so it’s not as efficient. The vast majority of Windows and Linux machines don't have unified memory or storage controllers connected to their processors.

Because of this, Apple can often compress a page of memory using fewer CPU cycles than Windows or Linux, which is why M-series Macs can be so aggressive with compression without you ever noticing a "hitch" in the UI.

The fallback algorithm is their LZFSE algorithm, which is like "Zlib-level compression with 2x-3x the speed and efficiency". LZFSE achieves a nearly identical compression ratio but uses Finite State Entropy (FSE) coding, which allows it to decompress data significantly faster while using much less battery power.

LZFSE is optimized for the ARM NEON instruction set to minimize "wake time" for the CPU, making it arguably the more "green" choice for mobile devices [2].

It's safe to say that neither Windows nor Linux has the combination of hardware and software optimizations that Apple has when it comes to RAM compression.

[1]: Compressed Memory compresses the least recently used data residing in memory using the WKDM algorithm, which not only frees up memory but also reduces the amount of swapping going in the background. Not only is this faster than swapping to disk (even to SSDs), but Apple also claims it saves power -- essentially, that compressing data in memory uses less power than writing data to disk without compressing it. -- https://www.osnews.com/story/27121/os-x-109-mavericks/#:~:te...

[2]: https://lyncd.com/2015/09/lossless-compression-innovation/