🛠 Survivre avec 512 Mo : zram, swap compressé et services légers
Objectives
512 MB of DDR3 shared with the Mali-400 GPU: this is the ceiling for the BPI-M2 Zero, and the reference review that ran Geekbench 5 on the board had to enable zram and push it to 350 MB to complete the measurement. zram creates a compressed swap block in RAM: you gain bytes without wearing out the microSD (the board's only storage, even more precious here than elsewhere). You will set up zram properly, lighten the services, and verify that the board handles a real load.
Hardware
- BPI-M2 Zero running Armbian (some Armbian images already ship with a zram service: check before stacking)
- Console (SSH, CON3, or OTG)
- No additional cards: everything happens in RAM
Complete code
# 1) État des lieux : y a-t-il déjà un swap ? (ne pas doubler les dispositifs)
free -h && swapon --show && lsmod | grep zram
# 2) Créer un zram de 384 Mo en LZ4 et l'activer comme swap
sudo modprobe zram
echo lz4 | sudo tee /sys/block/zram0/comp_algorithm
sudo zramctl /dev/zram0 --size 384M
sudo mkswap /dev/zram0 && sudo swapon /dev/zram0
# 3) Le rendre résistant au reboot via un service systemd
sudo tee /etc/systemd/system/zram-swap.service >/dev/null <<'EOF'
[Unit]
Before=swap.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c 'modprobe zram && echo lz4 > /sys/block/zram0/comp_algorithm && zramctl /dev/zram0 --size 384M && mkswap /dev/zram0 && swapon /dev/zram0'
ExecStop=/bin/sh -c 'swapoff /dev/zram0 && zramctl /dev/zram0 --reset'
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable --now zram-swap.service
# 4) Alléger : désactiver ce qui est inutile sur un rôle précis
systemctl list-unit-files --state=enabled | head -30
sudo systemctl disable --now bluetooth # si le BT ne sert pas
# 5) Épreuve de feu
sudo apt install -y stress-ng && stress-ng --vm 2 --vm-bytes 200M --timeout 60s
free -h && dmesg | tail # aucun OOM-killer sur sshd
Expected verification
swapon --show lists /dev/zram0 (high priority, no file on the SD); during stress-ng, swap fills up but the SSH session remains alive and dmesg does not report the OOM-killer; zramctl displays the actual compression ratio (often 3 to 4×).
Common errors
- Stacking a classic swap file on the microSD in addition to zram: card wear and SD 4k latency ruin the experience.
- Setting zram to 512 MB: decompression itself consumes RAM; 350 to 400 MB is the order of magnitude that allowed large benchmarks on this board.
- Running a full desktop on 512 MB: stick to server/headless images.
- Forgetting that the GPU eats from the same memory stick: after video usage, available memory drops.
- Hiding the OOM-killer:
sshdis killed first, followed by a silent panic — keepvm.swappinessmoderate and monitordmesg.
Other tutorials for this board
- Flasher Armbian et premier boot du BPI-M2 Zero
- LED et bouton avec libgpiod sur le port 40 broches
- Wi-Fi AP6212 : le piège de l'antenne U.FL non fournie
- Console série sur USB-OTG : dépanner sans réseau ni câble UART
- Activer le bus SPI0 et piloter un petit écran TFT
- Câbler l'Ethernet 10/100 EMAC avec le carrier Zero-EPHY
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash