Owners of Raspberry Pi 4 (opens in new tab)s with 2GB of RAM, until now green-eyed and furious with envy at 4-8GB owners running full desktop Ubuntu (opens in new tab), can now join Canonical’s party. The trick, as reported by OMG Ubuntu (opens in new tab) based on an Ubuntu Blog (opens in new tab) post, is in the compression.
Like many operating systems, Ubuntu uses a swapfile on a computer’s storage system to hold data that won’t fit in RAM. In the case of the Pi, this is often a Micro SD card, not noted as the speediest medium in terms of either read or write performance, unless you buy the best micro SD cards. Enter zswap, a compression tool that intercepts processes about to be sent to the swapfile, and compresses them. Chances are that the newly crunched data can stay in RAM, and it’s much quicker to decompress it than fetch data from the SD card. This trick can even improve performance on 4GB and 8GB Pi boards, including the Pi 400 (opens in new tab) all-in-one.
The best news is that zswap is already in Ubuntu, there's no need to wait for another release (although it will be enabled by default in 22.04, which should release in April), and a simple one line Bash command is all you need to enable it now.