Ubuntu 22.04 is the first release of Ubuntu that works well on the Raspberry Pi 4 without any lag or stutter. Most of the credit for this goes to the work done on the Mesa drivers over the last year by Igalia. The 2D graphics support and Vulkan 3D support for the Pi 4 are currently in great shape and continue to pick up improvements.
This article provides a few tips to improve the performance further.
1. Disable Zswap and Enable Zram
Ubuntu 22.04 enables the use of Zswap by default. Zswap works similarly to Zram but requires a swap file stored on disk. If you have the 4GB or 8GB model of Pi 4 you can disable Zswap, and enable Zram instead, to get slightly better performance.
Zswap is built into the Linux kernel while Zram is available as an optional kernel module. Run the following command to install the Zram kernel module.
sudo apt install -y linux-modules-extra-raspi
To configure Zram we have 2 packages to choose from:
zram-configDeveloped by Canonical. Simple to use but lacks configuration options.
zram-toolsSimilar to Zram-config. Provides a configuration file to select the compression algorithm, threshold, size and priority.
zram-tools. Don’t install both.
Run the following command to install
zram-tools (and remove
zram-config if installed)
sudo apt install -y zram-tools sudo apt autoremove --purge -y zram-config
Edit the configuration file as shown below:
sudo gedit /etc/default/zramswap
The Zram priority is set to 100. The system will always use Zram first before using the swap file.
Zswap and Zram should not be used together. Run the command below to disable Zswap:
sudo sed -i -e 's/zswap.enabled=1/zswap.enabled=0/' /boot/firmware/cmdline.txt
Reboot the system for the changes to take effect.
After reboot, you can check the Zram usage with the following command:
2. Overclock if you have fan and heat sinks
If you have a heat-sink and a fan attached to the Pi 4 you can overclock the CPU and GPU for a nice 25% boost in performance without any downsides.
Don’t try this without a heat sink and fan though. Overclocking your Pi without a fan will result in worse performance, as the Pi will throttle constantly to stay below the 80° C temperature limit.
sudo gedit /boot/firmware/config.txt
Paste the following lines at the end:
over_voltage=6 arm_freq=2000 gpu_freq=750
dtoverlay=vc4-fkms-v3d to overclock the system successfully. The Full KMS overlay (
vc4-kms-v3d) is not suitable for overclocking. Using the firmware overlay (
vc4-fkms-v3d) allows the system to be properly overclocked.
Save the file and reboot for changes to take effect.
3. Convert the file system to BTRFS
The official pre-installed Ubuntu image uses the EXT4 filesystem by default. You can convert the filesystem to BTRFS to take advantage of the in-built compression features. Using compression can reduce the disk usage by up to 60% without any noticeable impact on CPU usage. It also improves storage performance, since less data needs to be read and written to the SD Card. BTRFS also supports filesystem snapshots that allow you to roll back the system to a previous state in case of issues.
There are tutorials online for converting the filesystem to BTRFS. After converting the filesystem you also need to make some changes to the system configuration, to ensure that it continues to boot successfully after installing kernel updates in the future.
The filesystem can be converted easily using FlashIt.
- Start FlashIt and select the Convert Filesystem action from the main window.
- Select the SD Card (or USB drive) that has the official Ubuntu 22.04 image installed on it. This must be a fresh system, and the initial system setup should have been completed.
- Select the filesystem as BTRFS and click on Convert. The conversion will take about 10 minutes to complete.
- Insert the converted SD Card or USB drive into the Pi4 and boot from it. The system is ready to use.
4. Switch to local mirrors for faster system updates
Switching to a local mirror will max out your internet connection and download package updates as fast as possible. There are many ways to select and use the fastest mirrors. We will install and use Nala.
Nala is a prettier frontend for APT that makes it easier to install packages from the command line. It has the same syntax as apt. Run the below command to install Nala from its official repository.
wget -O - https://teejeetech.com/scripts/jammy/install_nala | bash
Run the command
sudo nala fetch to search for the fastest mirrors in your geographic region. When prompted for a choice enter
1 2 and hit Enter. It will use the first two fastest mirrors in your region.
5. Use Google’s DNS Servers for Faster Internet
Many ISPs have slow DNS servers that cause delays and timeouts when loading web pages. For a faster internet experience, change your WiFi settings to switch to Google’s DNS servers.
Enter the values
188.8.131.52, 184.108.40.206 in the DNS field of the IPv4 tab.
Enter the values
2001:4860:4860::8888, 2001:4860:4860::8844 in the DNS field of the IPv6 tab.
Disconnect and reconnect the WiFi connection to see changes.