The newly available Raspberry Pi Zero 2 is a nice boost for the Raspberry Pi Zero family which is often used for smaller and headless applications. Due to the fact that the new Raspberry Pi Zero 2 keeps having only 512 MiB RAM, DietPi is a great choice with its small default memory footprint. This article describes how to use the limited RAM on your Raspberry Pi Zero family efficiently for your applications.
(By SparkFun Electronics – https://www.sparkfun.com/products/18713, CC BY 2.0, https://commons.wikimedia.org/w/index.php?curid=111936085)
There are several comparisons which give an overview about the differences between the Raspberry Pi Zero and the Raspberry Pi Zero 2. Some examples:
- CNX Software: “Raspberry Pi Zero 2 W and Zero W features comparison“
- Hackster: “Raspberry Pi Zero 2 W Review — Hands-on with the Fastest Zero Ever“
- Hackaday: “The Pi Zero 2 W Is The Most Efficient Pi“
- IT Info: “Raspberry Pi Zero 2 W vs Raspberry Pi Zero W: Welche Upgrades bringt es?“
- Buyzero: “Alles rund um Raspberry Pi Zero 2 W – inklusive FAQ und Tipps“
Some of the available postings in the Internet complain that the RAM was not increased (e.g. to 1 GiB) and that this does not fit to the CPU performance boost of the Raspberry Pi Zero 2.
How to use your RAM efficiently on your Raspberry Pi Zero / Zero 2
There are three main directions of impact we want to propose:
- Use DietPi as a lightweight Debian based distribution
- Stay at 32-bit OS instead going to 64-bit OS
- Prefer an ARMv7 image to ARMv6 if using 32-bit OS (if your Raspberry Pi hardware supports this)
DietPi basically has a small RAM footprint
The first thing is to use as few RAM as possible with your base OS installation. DietPi was especially optimized to achieve a small RAM footprint in your system. Compared to the well known Raspbian OS lite, the RAM amount of DietPi is only
- 58 % (64-bit OS version) resp.
- 72 % (32-bit OS version)
of the RAM Raspbian OS lite uses (see also there).
As a result, the DietPi base system optimises the use of the limited RAM of your Pi.
32-bit fits better for smaller appliances
Since Bullseye, the ratio of 64-bit Debian kernel versions compared to 32-bit Debian kernel versions raise more and more. The DietPi usage over the last 3 months shows this:
Larger RAM addressing of 64-bit – useless for Pi Zero
Basically, 64-bit OS kernels resp. 64-bit processes (programs) can address a larger memory (16 Exabytes) compared to 32-bit programs (4 GiB). On a Raspberry Pi Zero resp. Raspberry Pi Zero 2 only 512 MiB RAM is available. As a result, there is no need for a larger addressing capability.
In smaller appliances like the Raspberry Pi Zero (or generally Linux systems with less than 2 GiB RAM memory) there is no need to switch to a 64-bit system caused by the larger addressing feature.
Larger code size of 64-bit – consumes more RAM
Furthermore 64-bit code (kernels resp. programs) has the drawback of larger memory consumption. This can be essential when operating on a small RAM layout.
Looking on the OS base system: In case of a Raspbian OS Lite system, the 64-bit version increases RAM memory consumption to 206 % compared to the 32-bit version. Using DietPi, the increase is less but still to 162 %.
This shows that using a 32-bit OS version should be the better choice for these types of smaller applications. Notice: More bits are not always better.
64-bit code may run quicker – depends on the application
There were some examinations/benchmarks of 64-bit to 32-bit on the Pi. Some examples:
- CNX Software, Jean-Luc Aufranc: “Raspberry Pi 4 Benchmarked with 32-bit and 64-bit Debian OS“
- Matteo Croce: “Why you should run a 64 bit OS on your Raspberry Pi4“
- Raspberry Tips: “Raspberry Pi OS 64-bit vs 32-bit (Which One To Install?)“
- Phoronix, Michael Larabel: “Further Investigating The Raspberry Pi 32-bit vs. 64-bit Performance“
The conclusions given, express, that a performance boost of 64-bit depends on the application (e.g. networking, firewalling, cryptography). In these more rare situations, a 64-bit system supersedes the 32-bit system. But in most applications 32-bit should be sufficient.
Differences in images: ARMv7 to ARMv6
DietPi provides two different 32-bit images for the Raspberry Pi Zero 2: An ARMv6 image based on Raspbian and an ARMv7 image based on Debian.
The ARMv7 image provides smaller and in some cases better performing binaries, the Debian repository gets updates slightly earlier and provides backports. There are no compatibility benefits of the ARMv6 image over the ARMv7 image known.
What is a smaller RAM usage good for?
The benefits of using less RAM with your OS base system are generally:
- Your applications on the system may use more RAM before the system comes to its limit
- Your system may run quicker due to more RAM cache available.
htop output of a DietPi base system where you can see the RAM usage:
In the header you see the
Mem line on the top right corner. The colours show
You can see that the used memory (green lines) is very small and that there is quite some space left for applications and RAM based caching (yellow lines). The latter may speed up your system.
Additional benefits OF RUNNING DIETPI on the Raspberry Pi Zero
In addition to the RAM optimization, DietPi brings a couple of key features:
- The default active SSH access makes a headless configuration easy from the start – This is a scenario typically enabled for Raspberry Pi Zero / Zero 2. In this way you have access to the SBC without graphical user interface.
- The textual graphic configuration interface (i.e.
dietpi-softwareand more tools) can be executed from a terminal session (e.g. PuTTY). The tools give you an easy to use option to install more than 200 software packages just with a few keyboard inputs – see the full software list.
On a Raspberry Pi Zero / Zero 2 with its small RAM typically no graphical user interface runs, i.e. it is often used headless not to burden the RAM usage by the base system too hard. Little RAM usage should be the prior goal compared to quicker 64-bit runtime performance.
So, the conclusion within the boundaries explained above can be given in short:
Use the ARMv7 32-bit DietPi image on your Raspberry Pi Zero 2 to achieve best overall performance.Download the ARMv7 Raspberry Pi Bullseye Image