ZimaOS 1.8 Photos fills RAM via /tmp with large libraries – workaround (previews on disk + resource limits)
Setup: ZimaBoard 2 (16 GB RAM), ZimaOS 1.8.0, ~100,000 photos on a NAS share, Pi-hole and Nextcloud AIO on the same box.
Why
Photos writes its previews to /tmp/zimaos-mds-gallery-preview. On ZimaOS /tmp is a tmpfs, so it lives in RAM (50 % of RAM). The folder grows by ~80 KB per photo and is never trimmed. Within three days it held 6 GB / 75,000 files: RAM and swap were full, the CPU was busy swapping, and everything on the box stalled. My Pi-hole on the same box answered DNS in 1–12 s or timed out, so the whole house had “slow internet”. Photos is not a Docker app, so it doesn’t show up in docker stats.
Check your own box:
df -h /tmp
sudo du -sh /tmp/zimaos-mds-gallery-preview
free -h
Quick relief
sudo systemctl stop zimaos-photos-ai-worker.service zimaos-photos.service
sudo find /tmp/zimaos-mds-gallery-preview -mindepth 1 -delete
Permanent workaround
This keeps Photos running, but puts the previews on disk and limits its CPU and RAM. Replace /media/YourDisk with a disk that has room (100k previews ≈ 8 GB). Run as root:
CACHE=/media/YourDisk/AppData/photos-preview-cache
TARGET=/tmp/zimaos-mds-gallery-preview
# Wait for the disk (systemd retries), then bind-mount the preview folder onto it
BIND="grep -q ' /media/YourDisk ' /proc/mounts || exit 1; mkdir -p $TARGET $CACHE; grep -q ' $TARGET ' /proc/mounts || mount --bind $CACHE $TARGET"
mkdir -p "$CACHE"
mkdir -p /etc/systemd/system/zimaos-photos.service.d
cat > /etc/systemd/system/zimaos-photos.service.d/limits.conf <<EOF
[Service]
ExecStartPre=+/bin/sh -c "$BIND"
Nice=19
CPUWeight=10
MemoryHigh=3584M
MemoryMax=5G
EOF
mkdir -p /etc/systemd/system/zimaos-photos-ai-worker.service.d
cat > /etc/systemd/system/zimaos-photos-ai-worker.service.d/limits.conf <<EOF
[Service]
ExecStartPre=+/bin/sh -c "$BIND"
Nice=19
EOF
mkdir -p /etc/systemd/system/zimaos-photos.slice.d
cat > /etc/systemd/system/zimaos-photos.slice.d/limits.conf <<EOF
[Slice]
CPUWeight=10
CPUQuota=150%
MemoryHigh=2560M
MemoryMax=3G
EOF
systemctl daemon-reload
systemctl restart zimaos-photos.service
Why these settings:
- Bind mount: previews go to disk instead of RAM. Both services set it up, because the AI worker starts first.
- No CPU cap on
zimaos-photos.service: it also runs the Manticore search database. A 1-core cap throttled it so hard that the gallery showed “No matching photos”.Nice=19+CPUWeight=10is enough: it only gets CPU nobody else needs. - Memory 3.5 GB soft / 5 GB hard: with
MemoryHigh=2Gthe cgroup was throttled 29,000+ times and the rebuild crawled. - Cap on the parent
zimaos-photos.slice: the AI and media slices are its children. Photos overrides limits onzimaos-photos-media.sliceat startup, but leaves the parent alone.
Verify:
grep gallery-preview /proc/mounts # must show your disk, not tmpfs
grep high /sys/fs/cgroup/system.slice/zimaos-photos.service/memory.events /sys/fs/cgroup/zimaos.slice/zimaos-photos.slice/memory.events # should barely grow
To undo: delete the three limits.conf files, then systemctl daemon-reload and restart Photos.
If Photos breaks after the memory crash
“This feature is temporarily unavailable”: journalctl -u zimaos-photos.service showed Manticore failing on a missing binlog file (binlog.0000: No such file or directory). Moving the binlog files aside fixed it; the data itself is kept:
sudo systemctl stop zimaos-photos.service
sudo mkdir -p /media/ZimaOS-HD/AppData/photos/manticore/binlog-defect
sudo mv /media/ZimaOS-HD/AppData/photos/manticore/binlog/binlog.* /media/ZimaOS-HD/AppData/photos/manticore/binlog-defect/
sudo systemctl start zimaos-photos.service
Empty gallery, and a “Welcome to ZimaOS Photos / Start” screen in a private window: Photos had lost its setup record (the table photo_schema_meta was empty). First make a backup of AppData/photos/manticore (stop Photos, then cp -a --reflink=auto), then click Start. It reused the existing index (“Importing · 97,488”) and started rebuilding.
Findings so far
- RAM in use went from 13 GB + 5.1 GB full swap to ~6 GB. Pi-hole answers in ~3 ms again.
- Previews now land on disk (8,000+ files and growing), and
/tmpno longer fills up. - After the recovery, Photos re-checks everything: 97,488
photo_ai_repairjobs queued, plus a gallery rebuild. The Month view refills gradually; the Year view and the map (14,966 of 21,687 geotagged photos) are still catching up. Expect this to take a while.
To IceWhale
Please store previews on persistent storage instead of /tmp, cap the cache, and add pause/throttle controls for indexing. A feature that can take down a whole NAS within days should be safe by default, or clearly marked as beta, before it ships to everyone.