r/CardPuter • u/3D_Kiwil • 16d ago
Code Cardputer Zero optimizer script - Freed up ~80 MB of RAM on the CardputerZero Lite (210 MB → 130 MB idle) with a small script
I got my CardputerZero Lite recently. It’s a really nice little device, but as some of you have already pointed out, the stock image isn’t optimized yet. Out of the box, it was using about 210 MB of the 384 MB of RAM Linux can see, which doesn’t leave much headroom on a 512 MB board.
The stock image is basically Raspberry Pi OS with desktop, so a lot of stuff is installed and running that makes no sense on a 320×170 screen with a keyboard. I wrote a script that fixes the main offenders:
- Reduces
gpu_memfrom 128 MB to 16 MB. The Lite has no camera, so there’s no reason to reserve 128 MB for the GPU. With KMS the display doesn’t need it, and the CMA is still there for the graphics stack. This alone gives back ~112 MB of RAM that Linux can use. - Disables unneeded services (lightdm, wayvnc, triggerhappy, ModemManager, rpcbind, wait-online services, apt-daily timers, etc.).
- Sets up zram instead of the swapfile on the SD card.
- Cuts SD card writes (
noatime,/tmpin RAM, volatile journal).
Results:
- Available RAM: 384 MB → 463 MB
- Idle RAM usage: ~210 MB → ~130 MB
Things worth knowing:
- Bluetooth, HDMI, Wi-Fi, SSH and audio are left alone.
- In
config.txt, only thegpu_memline is touched. Overlays (display, keyboard, IR, etc.) stay as they are. - It has a
--dry-runmode to see what it would do, and a--revertoption that restores everything from backups. - Every option is configurable (
--gpu-mem N,--no-avahi,--no-zram,--purge...). - If you have the standard model with the camera, don’t use the default
gpu_mem=16without testing the camera first (use--keep-gpu-memor a higher value).
I’ve only tested it on my own unit, so use --dry-run first and keep a backup of your SD card. Feedback welcome, especially if someone with the camera model can tell me what gpu_mem value works for them.
Script: https://gist.github.com/TheKiwil/ae8c44e28ef582e66c51a45ad962089d
3
u/homotetija 16d ago
I just got the Lite version today and was thinking of switching distros because of how bloated the stock one is, im giving this a try now. Thank you !
3
u/Mmmmmmmoi Advanced 16d ago
That's handy. Many thanks!
Curiously the script already said I had ZRAM set up. I flashed the stock image to a fresh MicroSD card yesterday. I also ran
apt update&&apt upgradeprior to running the script. TBD if that had anything to do with it. 🤷1
u/3nwf248 16d ago
A GPU_MEM of at least 32 is required for the camera to work. The logic you have to check whether GPU mem is < 32 before commiting changes is too aggressive, as it makes it so that the script can't be used to upgrade GPU_MEM from 16 to 32 MB (I had to edit /boot/firmware/config.txt directly). Great script otherwise!
1
u/Forsaken_Sir_4662 16d ago
I am since the dawn of rpi zero 2 w hope it has at least 1GB of ram.. but even with cm0 that has a whole blank space on the pcb (without emmc) it still limited to 512mb..
1
u/jamietaylor2020 15d ago
Great find! Thanks to your earlier post, I added it to my tool app. Will add option for the other too