At Canonical we’re proud to be able to offer a full Ubuntu Desktop experience on the Raspberry 4. Ubuntu Desktop provides everything you need to develop software and even deploy it to Ubuntu Server on devices like the Raspberry Pi Zero 2 W.
However the full desktop environment is quite a lot for the Pi to handle. Up until now, we’ve recommended users stick to models with either 4GB or 8GB of RAM to be confident that it will perform well. One of our goals for the upcoming Ubuntu 22.04 LTS release is to lower that barrier to entry. This means targeting a viable Desktop experience on Raspberry Pi 4 2GB models.
The secret to this optimisation is a Linux kernel feature called zswap. In this blog, we’ll show you how to enable this functionality today and benefit from the upcoming performance boost that will come as standard in 22.04.
To answer that we need to talk about swap files in general.
If you’re running any kind of Linux system, it’s highly likely (and recommended) that you have a swap file allocated on your hard drive or SD card. Swap files act as a kind of overflow for your RAM, caching pages that are rarely used to free up RAM for more active processes. This enables you to keep working even when your system is using almost all of your RAM. However, using swap is less performant than using RAM since accessing your hard drive (or SD card) is slower.
You can read more about swap in the Ubuntu Documentation.
Okay, so where does zswap come in? 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.
Since zswap is supported by default, you can enable it with a simple command.
Enter the following into your terminal:
$ sudo sed -i -e 's/$/ zswap.enabled=1/' /boot/firmware/cmdline.txt
For newer Linux users, this command is basically a shortcut to edit the cmdline.txt file in your boot folder and set the zswap.enabled parameter to ‘True’ (1).
Once you’ve done this you can restart your device and benefit from an increased performance boost!
If you’re not a confident Linux user then you can stop there. The above should already improve performance on your existing 4GB or 8GB Raspberry Pi. But this won’t yet give the smoothest performance on a 2GB device.
For more advanced users, Dave Jones, who leads the Ubuntu Raspberry Pi work at Canonical, has a few additional improvements to share. He’s written a more detailed blog post on how he configured things on his personal blog, but we’ll paraphrase them below.
The two additional improvements we want to implement are:
Enter the following command into your terminal:
$ sudo -i
This will prompt you for your password and put you into root mode where you can enter the following commands:
# echo lz4 >> /etc/initramfs-tools/modules
# echo z3fold >> /etc/initramfs-tools/modules
# update-initramfs -u
This adds lz4 and z3fold modules to your initramfs so that they can be accessed on initialisation. Wait for the update-initramfs process to complete and then type:
# exit
To return to your normal user mode.
Finally we need to add the following commands to your cmdline.txt file similar to before:
$ sudo sed -i -e 's/$/ zswap.compressor=lz4/' /boot/firmware/cmdline.txt
$ sudo sed -i -e 's/$/ zswap.zpool=z3fold/' /boot/firmware/cmdline.txt
Then reboot (you can just type reboot in the terminal).
You can check that the changes have been made correctly by searching for the parameters using grep:
$ grep -R . /sys/module/zswap/parameters
If you’ve configured things correctly then the output should look like this:
/sys/module/zswap/parameters/same_filled_pages_enabled:Y
/sys/module/zswap/parameters/enabled:Y
/sys/module/zswap/parameters/max_pool_percent:20
/sys/module/zswap/parameters/compressor:lz4
/sys/module/zswap/parameters/zpool:z3fold
/sys/module/zswap/parameters/accept_threshold_percent:90
If the above tutorial seemed a little complicated, don’t worry. When Ubuntu 22.04 releases in April, these optimisations will be included by default for all Raspberry Pi 4 devices, including the 400!
However, if you do make these changes and try them out on a 2GB Raspberry Pi 4 we’d love to hear about how much it has improved your performance. Let us know if you feel it delivers a quality Ubuntu Desktop experience for 2GB users.
You can reach out to us on the Raspberry Pi category of the Ubuntu Discourse.
In this article, we will see how to Install Google Cloud BigQuery Python client library…
Nov 15,2024 Wallpaper Contest for Xfce 4.20 open for voting The submission phase for the…
MicroCloud 2.1.0 LTS is now available, expanding the number of Canonical infrastructure solutions with a…
Canonical is thrilled to be joining forces with Dell Technologies at the upcoming Dell Technologies…
In today’s massive private mobile network (PMN) market, one of the most common approaches to…
Welcome to the Ubuntu Weekly Newsletter, Issue 865 for the week of November 3 –…