Ubuntu 22.04 LTS to leverage zswap to run on Raspberry Pi 4 with 2GB RAM

Canonical used to recommend Raspberry Pi 4 with at least 4GB RAM to run Ubuntu Desktop, but Ubuntu 22.04 LTS should run more smoothly on the Raspberry Pi 4 2GB as the company has enabled zswap by default to allow the Linux operating system to run better on systems with less memory.

Canonical explains that zswap is essentially a compression tool.

When a process is about to be moved to the swap file, zswap compresses it and checks whether the new, smaller size still needs to be moved or if it can stay in your RAM. It is much quicker to decompress a ‘zswapped’ page than it is to access the swap file so this is a great way of getting more bang for your buck from systems with smaller amounts of RAM.

Raspberry Pi 4 2GB Ubuntu 22.04

The good news is that you don’t even need to wait for Ubuntu 22.04 LTS to come out, since it can be enabled manually in Raspberry Pi 4 as follows:


Or simply edit /boot/firmware/cmdline.txt file, and add the following string to the existing command:


After a reboot, that should even help the performance of Raspberry Pi 4 boards with 4GB and 8GB RAM, but with the 2GB model, some extra steps are needed to enable z3fold allocator & lz4 compression. The commands to run are explained in detail in Ubuntu blog, and in the end, you’ll have loaded a few more modules and your cmdline.txt should have three extra parameters:


There will be nothing to do in Ubuntu 22.04 LTS as those will be enabled by default.

We previously wrote about enabling ZRAM in Ubuntu to improve the performance and reliability of systems low on RAM. So what’s the difference between zram and zswap exactly? I understand zram is like a compressed swap that resides in RAM, while zswap uses both storage and RAM, and only stores the compressed data into the swap file on the storage device, if there’s not enough RAM to hold the data.

That question was also asked on Stackoverflow so we have a more detailed answer (edited for brevity):

zram
Status: Available since Linux 3.14 (March 2014)
Implementation: compressed block device, memory is dynamically allocated as data is stored
Usage: Configure zram block device as a swap device to eliminate need for physical swap defice or swap file

Benefits:

  • Eliminates need for physical swap device.
  • A zram block device can be used for other applications other than swap, anything you might use a block device for conceivably.

Drawbacks:

  • Once a page is stored in zram it will remain there until paged in or invalidated. … zram can not do evict pages out to physical disk.

zswap
Status: Available since Linux 3.11 (September 2013)
Implementation: compressed in-kernel cache for swap pages. In-kernel cache is compressed, the compression algorithm is pluggable using the CryptoAPI and the storage for pages is dynamically allocated. Older pages can be evicted to disk making this a sort of write-behind cache.
Usage: Cache swap pages destined for regular swap devices (or swap files).

Benefits:

  • Integration with swap code (using Frontswap API) allows zswap to choose to store only pages that compress well and handle memory allocation failures, in those cases pages are sent to the backing swap device.
  • Oldest pages in the cache are pushed out to backing swap device to make room for newer pages.

Drawbacks:

  • Needs a physical swap device (or swapfile).

Thanks to Geokon for the tip.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

Radxa Orion O6 Armv9 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
10 Comments
oldest
newest
Boardcon CM3588 Rockchip RK3588 System-on-Module designed for AI and IoT applications