Everyone tends to think of swapfiles being disk based.
In reality, swapping to RAM is exponentially more popular.
If you have a traditional model of memory in your head, this makes NO SENSE. Swap is that thing we use when the system runs out of real ram right?
You know, RAM fills up, swap out to SSD to give the OS some breathing room. Why (and how?) would you swap to memory…very thing that’s full?
Well, Modern CPUs are ridiculously fast at compression, especially with something light like lz4. Zswap intercepts old pages, quickly compresses them, and then crams them back into system RAM. If you’re lucky, you might be able to fit ~3-4 compressed pages into the space of 1 traditional page.
Of course, this also has the benefit of not prematurely wearing out your SSD.
Mobile has done this for *years*, I know Android specifically has used this for a decade+. Regular Linux is catching up, Fedora uses zram by default now. The NT kernel (windows) also has their own implementation of in-memory compression, you can see it in task manager quite easily!
Anyway, it’s a fun trick used everywhere that few realize. Towards the future, I wouldn’t be surprised if inline, accelerated LZ4 starts showing up in the majority of CXL controllers.
