4 ms·
> For everything else, swap usage on Apple machines works so well that RAM might as well not exist. You and I disagree on this part so strenuously I don’t fore
by SllX 7mo ago
> For everything else, swap usage on Apple machines works so well that RAM might as well not exist.
You and I disagree on this part so strenuously I don’t foresee a middle ground. Swap still absolutely sucks no matter how fast the SSD is, and the SSDs or probably the SSD controller are much slower than what’s in other Apple Silicon Macs.
- alwillis 7mo ago> Swap still absolutely sucks no matter how fast the SSD People always forget that Apple does realtime compression on data that's in RAM allowing more things to fit in RAM; it also effectively increases the bandwidth of the SSD.
- JohnBooty 7mo agoWindows 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 https://en.wikipedia.org/wiki/SoftRAM
- alwillis 7mo ago> 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/#:~:text=Compressed%20Memory%20compresses,without%20compressing%20it. https://www.osnews.com/story/27121/os-x-109-mavericks/#:~:te... [2]: https://lyncd.com/2015/09/lossless-compression-innovation/ https://lyncd.com/2015/09/lossless-compression-innovation/
- astrange 7mo agoLZ4 not LZFSE. > Windows/Linux treat RAM like a stream of bytes (similar to how you’d compress a .zip file) so it’s not as efficient. That doesn't really follow. There are faster and slower compression algorithms no matter what, and 64-bit integers are kind of a waste of memory much of the time. Also, unified memory has tradeoffs. The GPU improvements are real but it mostly means more pressured on memory, not less.
- rbliss 7mo agoVery cool, thanks for the detail. This leads me to wonder....why haven't Windows and Linux done any similar optimizations? I assume they do lots of hardware optimizations in all sorts of places, but this seems pretty core.
- st3fan 7mo agoIt is an old trick https://apple.fandom.com/wiki/RAM_Doubler https://apple.fandom.com/wiki/RAM_Doubler
- alwillis 7mo agoRAM Doubler was a third-party application in the days when a top-of-the-line Mac had 128MB of RAM, with a 40Mhz processor. The level 2 cache was 256 bytes. That's not in the same universe as hardware compression on a 6-core, 64-bit ARM processor with cores that can run at 4GHz.
- SllX 7mo agoNobody forgot anything, and I certainly didn’t. You can tell when you hit swap, and it doesn’t matter what Mac OS X is designed to do, when you hit swap, you hit swap. When you’re hitting swap a lot, you’re hitting swap a lot.
- alwillis 7mo ago> You can tell when you hit swap, and it doesn’t matter what Mac OS X is designed to do, when you hit swap, you hit swap. When you’re hitting swap a lot, you’re hitting swap a lot. I have a 16GB M1 Pro machine from 2021 with 200 GB/s memory bandwidth; I can't tell when it's hitting swap, even with tons of browser tabs open, 3 or 4 terminal sessions, and several apps running. I often run two browsers with dozens of tabs open and there's no noticeable lag. YMMV. On an my old Intel Mac, it was pretty obvious.
- JohnBooty 7mo agoRight, I mean even a fast SSD has an order of magnitude less throughput, and 2-3 orders of magnitude higher latency from RAM. No dispute there. If you are doing random access across 16GB of data and your machine only has 8GB of physical RAM, you're in the pain zone. OTOH, if you are using multiple RAM-heavy apps that aren't actively hammering that RAM (e.g. an instance of Photoshop that is using 10GB but is just idling or whatever) then MacOS and their stupid fast SSDs handle that pretty seamlessly. Most use cases are probably somewhere in the middle.
- SllX 7mo agoBrowser use on the modern web is enough to put you in swap territory early and often on 8GB of RAM. My much more RAM efficient M2 iPad Pro with the non-desktop OS and 8GB of RAM frequently has to page out apps I had open two minutes ago if I’m doing anything with the web and like one or two other applications. This things eventual replacement in like 4 or 5 years is going to need twice or thrice the RAM for me to consider it an upgrade.