Impossible OS Docs

Kernel Logging v2 (Lockless, Priority Lanes)

What is it?

Kernel logging v2 is a design for the next kernel logging substrate: per-CPU lockless ring buffers instead of one global lock, priority lanes so a debug flood cannot crowd out a fatal line, structured fields instead of pre-formatted text, and an emergency path that gets a fatal message to serial even when the ring is full or serial is stuck. None of it has shipped: all ten rows of the roadmap's Implementation Order table are open and no klog_v2 symbol exists in the tree. The logging system that runs today is v1, documented in System Logging (klog).

How does it work?

As designed, each CPU gets a ring field in struct per_cpu_data (smp.h) holding a fixed ring of cache-line-aligned entries, with the producer and consumer indices on separate cache lines so only the owning CPU writes into it. A lockless klog_v2() enqueues without touching a global lock. Five priority lanes (debug, info, warn, error, fatal) share the ring with per-level budgets so a lower level cannot evict a higher one. Fatal messages bypass the ring and write straight to serial with a bounded retry, falling back to a static per-CPU emergency buffer. A background drain thread reads every CPU's ring in turn and batches serial writes, so the call site no longer pays serial latency. One binary wire format would feed the JSON Lines disk writer, ETW, and a host-side decoder.

The plan ships v2 beside v1 behind a build switch until benchmarks show it faster, and only then retires v1's klog.c and klog.h.

What are its interfaces?

None of the v2 interfaces exist. The roadmap names klog_v2(), the KLOG_DEBUG to KLOG_FATAL macros, ring enqueue and dequeue helpers, per-subsystem rate limits, statistics, a fatal path, survival-snapshot capture and recovery, and a system-information class for reading the statistics. Kernel code calls the v1 klog() API today, with the disk writer in klog_disk.c; both are covered in System Logging (klog).

How do I use it?

There is nothing to use yet: no v2 build switch and no v2 symbol exist. Code that logs today calls klog().

What is not implemented yet?

All ten sections:

How does it compare with Windows 11 and Linux?

The roadmap's comparison table sets the target: since 5.10 Linux printk writes lock-free into one shared ring (per-CPU buffers belong to the separate tracing ring buffer), Windows ETW buffers per CPU, but neither guarantees a fatal line under every failure mode, neither has per-level lanes, and neither renders one structured record as both plain text and a binary event. Until the sections above ship, Impossible OS has none of these properties; v1 is a single ring behind a global lock with text entries, as System Logging (klog) describes.

See also

Impossible OS is free software under the GPL-3.0-only license. Last updated Edit this page on GitHub