← Back to blog

The Shared-Memory Leak Hiding in Pi-hole's FTL

Brandon Schaefer··Updated November 24, 2026·5 min read·

An apt-get run getting OOM-killed looked like nothing to do with DNS - until a look at /dev/shm showed FTL quietly holding onto hundreds of megabytes it never gives back.

Table of contents

A routine apt-get run on one of my Pi-hole boxes got killed by the kernel's OOM reaper. Nothing about that run touched DNS, and the box wasn't under any unusual load - a plain package upgrade, on a small container that normally has memory to spare. The instinct is to go look at whatever apt was doing. The actual answer was sitting somewhere apt never touches: /dev/shm.

A symptom with no obvious cause

The failure mode gives you almost nothing to go on. apt-get dies partway through, dmesg shows a straightforward out-of-memory kill, and the process it killed has no relationship to DNS, FTL, or anything Pi-hole related - it's just the unlucky process using memory at the moment the kernel decided something had to go. On a container with a small, fixed memory budget, that's enough to send you looking at the wrong layer entirely: package sizes, apt's own cache, whatever else happened to be running.

The box wasn't actually short on disk, and nothing in its process list looked unusual in a ps aux sense - pihole-FTL doesn't show up as a memory hog there, because the memory it's holding isn't counted against its own RSS the way a normal leak would be.

Finding the actual culprit

The tell is df -h /dev/shm. On the box that had been running for weeks without a restart, shared memory usage sat at roughly 410MB out of a 512MB container - the overwhelming majority of the box's entire memory budget, gone before apt ever asked for a single page. On a nearly-identical instance that happened to have been restarted recently, the same check showed about 15MB. Same software, same role, same configuration - the only real difference was uptime.

That gap is the whole story. Nothing was misconfigured, and nothing was actually broken in the sense of a crash or an error - FTL was doing exactly what it's designed to do. It just never gives any of that memory back on its own.

Why FTL does this

pihole-FTL keeps its working state - the query log, the domains and clients tables, and a string cache for the values it has to look up repeatedly - in shared-memory segments under /dev/shm rather than in its own private heap. That's a reasonable design choice on its own: shared memory is what lets FTL's own CLI tools and web interface read live query data without going through FTL's main process for every request. The part that turns it into a slow leak is that none of those segments compact. The query log grows with every request, the domains/clients tables grow with every new domain or client FTL has ever seen, and the string cache grows with every distinct string it's had to intern - and none of it shrinks back down as entries age out or stop being relevant. A restart is the only thing that frees any of it, because a restart is the only point at which those segments get reallocated from scratch.

None of this shows up as a conventional memory leak, because it isn't one in the usual sense - there's no unbounded allocation inside a single request, no missing free() call. It's bounded only by how long the process has been running and how much DNS traffic it's seen in that time, which on a long-lived, low-maintenance box is effectively unbounded.

The fix: restart on a schedule, not a config knob

FTL does expose some of the knobs you'd reach for first - a maximum query-log retention window, cache size limits - and tuning those down helps slow the growth, but doesn't stop it, because the domains/clients tables and string cache aren't governed by the same retention settings as the query log itself. Chasing every individual cache's eviction behavior turns into tuning several independently-aging data structures against each other, for a problem that a restart solves completely and for free. So instead of fighting FTL's internals, the fix here is a plain systemd oneshot wired to a weekly timer, rolled into the shared Ansible role every instance already uses:

ini
# /etc/systemd/system/pihole-ftl-restart.service
[Unit]
Description=Restart pihole-FTL to reclaim accumulated shared memory
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart pihole-FTL
ini
# /etc/systemd/system/pihole-ftl-restart.timer
[Unit]
Description=Weekly restart of pihole-FTL (shm growth mitigation)

[Timer]
OnCalendar=Sun 04:00
RandomizedDelaySec=1800
Persistent=true

[Install]
WantedBy=timers.target

The 30-minute RandomizedDelaySec matters more than it looks like it should. Every instance running this role shares the exact same OnCalendar schedule, and without the jitter they'd all restart in the same second - which, for a network where more than one of them is a DNS resolver clients can fall back to, means dropping every fallback at once instead of staggering them. The randomized delay spreads the actual restart moment across a half-hour window so each box's brief instant of unavailability lands at a different time than its neighbors'.

FTL comes back up in a couple of seconds, and clients configured with a secondary resolver don't notice. Low-traffic-hours scheduling (04:00, a window nothing else on the network cares about) and the random spread do the rest of the work a more clever cache-eviction scheme would have had to do by being correct.

The actual lesson

The part worth remembering isn't the fix - a restart timer is about as unglamorous as infrastructure gets. It's that the failure mode pointed everywhere except the real cause. An OOM kill on an unrelated process, on a box that looked fine by every metric you'd normally check first, turned out to be entirely explained by a single shared-memory segment that nothing in a standard health check looks at. free -m and ps aux both looked normal; df -h /dev/shm was the only place the problem was visible at all. Worth adding to the list of things to check early next time a small container starts OOM-killing things for no apparent reason.