I came across this article talking about CRAM being much more efficient RAM compression than ZRAM. I wonder if this could be implemented in PureOS for the Librem 5. I suppose that depends on what upstream Debian does.
I couldn’t work out whether this relies on any CPU architectural features that might be specific to x86 or, if available on ARM, specific to later ARM models.
Here is more info on the work Gregory Price at Meta is doing to implement CRAM in Linux. It appears to be architecture-agnostic.
This may be the only time in my life that I say this, but thank you Meta.
I had to laugh at this part where Price talks about a human outrunning a bear:
Compressed RAM has a serious design issue: Its capacity a lie.
A compression device reports more capacity than it physically has.
If workloads write faster than the OS can reclaim from the device,
we run out of real backing store and corrupt data or crash.
I call this problem: "Trying to Out Run A Bear"
I.e. This is only stable as long as we stay ahead of the pressure.
We don't want to design a system where stability depends on outrunning
a bear - I am slow and do not know where to acquire bear spray.
Fun fact: Grizzly bears have a top-speed of 56-64 km/h.
Unfun Fact: Humans typically top out at ~24 km/h.
This MVP takes a conservative position:
all compressed memory is mapped read-only.
- Folios reach the private node only via reclaim (demotion)
- migrate_to implements custom demotion with backpressure.
- fixup_migration_pte write-protects PTEs on arrival.
- wrprotect hooks prevent silent upgrades
- handle_fault promotes folios back to DRAM on write.
- free_folio scrubs stale data before buddy free.
Because pages are read-only, writes can never cause runaway
compression ratio loss behind the allocator's back. Every write
goes through handle_fault, which promotes the folio to DRAM first.
The device only ever sees net compression (demotion in) and explicit
decompression (promotion out via fault or reclaim), and has a much
wider timeframe to respond to poor compression scenarios.
That means there's no bear to out run. The bears are safely asleep in
their bear den, and even if they show up we have a bear-proof cage.
The backpressure system is our bear-proof cage: the driver reports real
device utilization (generalized via watermark_boost on the private
node's zone), and CRAM throttles demotion when capacity is tight.
CRAM requires special hardware … but that hardware is independent of the CPU architecture. It will not be on normal desktops for some time.
Specifically, the requirement is Compute Express Link memory modules. See About CXL® - Compute Express Link
Not to be confused with C-RAM that protects against incoming drones, rockets, and mortar systems. (It is also “special” hardware.)