Ubuntu already supports the 4GB and 8GB memory versions of the Raspberry Pi 4 Model B (supported since Ubuntu 20.10). Now the Ubuntu team plans to lower the hardware barrier for Ubuntu even further by making the upcoming Ubuntu 22.04 LTS version to run on a Raspberry Pi 4 with only 2GB RAM.

image

However, getting a full Linux system like Ubuntu to run properly on a hardware device with too little memory can be difficult, so how does Ubuntu do it? Then we have to mention a Linux kernel feature called zswap.

Before mentioning the zswap feature, let’s talk about Linux’s virtual memory file: the swap file. Any type of Linux system allocates a swap file on the hard disk or SD card, which acts as a kind of overflow for RAM (running memory). When the system runs out of free memory, the swap file caches some pages and frees up memory for active processes, so that the system can continue to work even when it has almost run out of RAM. (As a side note, Win 10 also has a swapfile.sys file on the system disk)

However, the performance of using swap files is not as good as using RAM directly, as access to the hard disk is really slow compared to using memory, so the Zswap feature was introduced in the process.

zswap is essentially a compression tool. When a process is about to be moved inside a swap file, zswap compresses it and checks whether the new compressed page still needs to be moved, or whether it can be kept in RAM. If the compressed page can remain in RAM, it is decompressed when it is accessed again. Decompressing a “zswap” page is much faster than accessing a swap file, so the zswap feature is ideal for low memory hardware devices.

How do I turn on this feature?

Since Ubuntu supports zswap by default, you can run a simple command through the terminal emulator

1
sudo sed -i -e 's/$/zswap.enabled=1/' /boot/firmware/cmdline.txt

Then restart your Raspberry Pi to enable the features.

In fact, zswap is just one of the means of lowering the hardware threshold for Ubuntu, along with a host of other features such as z3fold and lz4 compression, which will be included in the April release of Ubuntu 22.04 and enabled by default on all Raspberry Pi 4 devices.