Hacktakes · Edition 19
Hacktakes · Edition 19 · August 14, 2026

O(1) Diagnostics and the Operator's Catch-22

Without strictly bounded O(1) work, memory-mapped logging triggers fatal write amplification under load, turning the observer itself into the outage.

By Owen Tate

Sparked by Single log line is 49KB+ (ext4) / 110KB+ (btrfs) of systemd-journald disk writes · discussion

The engine is fine, but the diagnostics just totaled the car.
The engine is fine, but the diagnostics just totaled the car.

It seems like every week, a new thread pops up on Hacker News or r/linuxadmin where a Linux node mysteriously locks up under load, and the discourse immediately points the finger at bloated software or sloppy application code. I was reading a recent Hacker News thread on exactly this phenomenon, and you see the identical sentiment echoing through bug trackers for critical infrastructure. The default assumption is almost always that a careless developer shipped a memory leak, the application panicked, chewed through the system's resources, and took the OS down with it. But let's look past that assumption and examine the actual physics of the underlying node architecture. When a machine crashes at 3 AM and SSH stops responding, the root cause is frequently baked into the OS's logging mechanism itself. Specifically, the node is killed by the architectural choice to use an indexed, memory-mapped binary format for telemetry.

If you read the specification for systemd-journald's file format, you’ll find a marvel of C-struct engineering (complete with its LPKSHHRH magic string). On paper, using mmap for this is highly elegant. You write to memory, the kernel handles syncing it to disk in the background, and you get fast, indexed lookups almost for free. But abstractions, especially storage abstractions, leak badly when subjected to the physical realities of modern storage subsystems. This is particularly punishing when that memory-mapped file sits on top of a Copy-On-Write (COW) filesystem like Btrfs or ZFS.

To understand why, we need to run the math on a perfectly benign failure.

Imagine an application throwing a routine exception in a tight loop. It is emitting roughly 1MB/s of text logs. In a traditional, unindexed append-only text file (/var/log/messages), that logical throughput requires almost exactly 1MB/s of physical disk bandwidth. It is sequentially written. $O(1)$ work. A memory-mapped binary format fundamentally alters this equation. Every appended log record forces the kernel to update a complex web of internal data structures: hash tables for fields, doubly-linked lists for message sequencing, and entry arrays. A tiny 100-byte logical append might dirty a 4KB memory page for the data payload, another 4KB page for the index update, and perhaps a third for a metadata pointer.

When the kernel eventually flushes those dirty pages to disk, we encounter the grim reality of write amplification. On a COW filesystem, updating a single 4KB page often requires rewriting an entire 16KB or 64KB block, plus rewriting the filesystem's own metadata tree up to the root. That 1MB/s of logical log volume might easily translate to 5MB/s or 10MB/s of physical disk write. At this low baseline multiplier, the node handles the overhead just fine. The queue depth barely registers.

Now let's escalate the load. A downstream database blips. Our application panics, spawning a fleet of concurrent retry storms, and log volume jumps to 10MB/s.

This is where pristine theory collides with the messy production reality of failing networks, thermal noise, and unyielding IO limits. Due to the highly fragmented page-dirtying of the binary b-tree and the compounding COW filesystem metadata overhead, our write amplification multiplier doesn't scale linearly. The page cache begins to thrash. That 10MB/s logical burst translates to hundreds of megabytes per second of random, heavily fragmented IO operations.

The physical disk queue depth begins to climb. At a queue depth of 4, overall latency degrades slightly, but the system keeps ticking along nicely. At a queue depth of 32, the disk reaches total saturation. The kernel, desperately trying to flush memory pages to persistent storage to free up RAM, begins to forcefully block write system calls across the entire node. Oof.[^1]

This bimodal IO collapse is the defining signature of a metastable failure. A persistent metastable state requires a vicious internal feedback loop to sustain itself once the initial trigger is removed, and we have mathematically guaranteed exactly that here. The application slows down because its threads are blocked on IO. Those blocked threads trigger upstream network timeouts. What does an application do when it experiences a network timeout? I'm going to write a timeout error to the log. The attempt to handle the error generates more log volume, which dirties more memory-mapped pages, which queues more disk IO, which blocks more threads.

The system enters a bimodal IO collapse, a vicious cycle that trench-level operators have been screaming about for years.

And here we must make the leap from Big-O mathematical collapse to the socio-technical reality of the operator on call. What does a disk queue depth of infinity actually look like to a human? It looks like an SSH connection timing out at 3 AM.

The operator gets paged, tries to shell into the box to see what's wrong, and the sshd daemon hangs because it needs to page in memory or write to the audit log, both of which are stuck behind the saturated disk. The exact telemetry mechanism designed to give you visibility during an outage is the same mechanism choking all available IO. By weaponizing a routine application exception into a full-system disk saturation, the architecture locks the responder completely out of the box.

The operator is caught in a brutal Catch-22, unable to query the logs because the act of writing the logs has paralyzed the kernel.

Diagnostics are fundamentally a control plane. They must be structurally insulated from the data plane's chaos. Therefore, the diagnostic primitive must guarantee strictly bounded $O(1)$ work per logical event. There can be no hidden multipliers, no mmap page-amplification, and no complex binary b-tree rebalancing on the critical write path. When a system is under maximal duress, telemetry must cost exactly what it claims to cost.

Architectural elegance cannot repeal the physics of IO limits: if your telemetry does not guarantee strictly bounded $O(1)$ work, the observer inevitably becomes the outage.

[^1]: If you want to be pedantic—and in distributed systems, pedantry is a survival skill—you might point out that page-dirtying amplification depends heavily on the specific record size and kernel flush intervals. True, but the asymptotic limit remains relentlessly fatal.

← Back to Edition 19