4.6 KiB
node-io — protecting etcd's WAL fsync from the dind runner
etcd-io-guard is a one-node DaemonSet (siriussec) that keeps the kernel's
dirty-page writeback backlog bounded. It exists because the amd64 Forgejo runner
(forgejo-runner-amd64, privileged docker:dind) and the etcd WAL share
/dev/nvme0n1p3, and heavy dind writeback turns etcd's fdatasync into
multi-second stalls — which in turn bounces kube-apiserver's liveness probe and
every leader-election client on the control plane.
What the fault actually is (measured 2026-10-26)
| observation | evidence |
|---|---|
| etcd fsync tail is extreme but rare | etcd_disk_wal_fsync_duration_seconds: 14.8 M samples over 45 d, 99.9 % ≤ 32 ms, 158 samples > 8.192 s, worst logged slow fdatasync 10.39 s |
| the tail is not a per-cgroup queueing problem | under a 150 s synthetic dind build load with no mitigation: 24 etcd fsyncs, 11 of them > 1 s, 5 > 8.192 s, while the dind cgroup averaged ~48 MB/s and ~35 IOPS — the device queue was nearly empty (ios in progress 0) |
| bulk dirty data is necessary for the tail | same load with only the fsync/metadata writers (no 512 MB bulk streams): 422 etcd fsyncs, 0 above 1 s, p99 512 ms |
per-cgroup io.latency cannot fix it |
cgroup-v2 applies latency targets only between peers of the same parent. kubelet puts every pod in its own slice, so etcd's leaf and the dind pod's leaf never influence each other. Set 259:0 target=50000 on etcd's leaf and it is accepted, but during load the dind cgroup's io.stat still reported depth=max — never throttled — and the stall count did not move (17 → 27 samples > 1 s, i.e. noise). Verified against block/blk-iolatency.c and the cgroup-v2 docs, not assumed |
| shrinking the backlog helps | vm.dirty_bytes=64 MiB, dirty_background_bytes=16 MiB: median fsync 512 ms → ~10 ms, 0 samples above 8.192 s (control: 5), dind throughput 48 → 39 MB/s (−17 %) |
Mechanism in one sentence: an fdatasync completes only after the device has
made everything already submitted durable, so an etcd WAL commit queues behind
whatever the runner has pushed into the page cache and writeback; on the default
vm.dirty_ratio=20 (≈3 GB of a 15 GB box) that backlog is seconds of I/O.
What this DaemonSet does
Writes vm.dirty_bytes / vm.dirty_background_bytes from the
etcd-io-guard-config ConfigMap into the host's /proc/sys/vm every 30 s,
re-applying on drift. It mounts the host /proc/sys/vm (privileged + hostPID) and
sleeps otherwise.
It deliberately does not set io.latency or io.max on the runner pod: the
latency controller is peer-scoped (above), and an io.max cap throttles drain
rate rather than the queued backlog, so it lengthens the flush instead of
shortening the commit.
Verify
# the guard is running and has applied the limits
kubectl -n node-io get ds,po
kubectl -n node-io logs ds/etcd-io-guard --tail=5
# the host agrees (0 ratio => the byte limits are in force)
ssh -i ~/.ssh/lancelot_priv [email protected] \
'sysctl vm.dirty_bytes vm.dirty_background_bytes vm.dirty_ratio vm.dirty_background_ratio'
# expect: 67108864 / 16777216 / 0 / 0
# etcd tail under load
ssh -i ~/.ssh/lancelot_priv [email protected] \
'curl -s http://127.0.0.1:2381/metrics | grep -E "^etcd_disk_wal_fsync_duration_seconds_(bucket|count)"'
kubectl -n kube-system logs etcd-siriussec --since=1h | grep -c 'slow fdatasync'
Tuning and known trade-offs
- Both knobs are in
configmap.yaml; change, push, Flux applies, the guard rewrites within 30 s. Keepdirty-background-bytes <= dirty-bytes. - 64 MiB is aggressive (≈0.4 % of RAM). It cost ~17 % of dind write bandwidth in the pressure test and made the 1–4 s band more frequent because there are many more, much shorter commits. Raise to 256 MiB/64 MiB if CI wall time regresses; that still bounds the backlog far below the 3 GB default.
- The limits are host-global: they apply to every writer on siriussec, not just the runner. There is no per-cgroup dirty limit in this kernel that binds a different pod.
- Not touched here (out of scope for this card): the dind data-root is still on the etcd device. Moving it to its own disk removes the contention entirely and is the only fix that lets the dirty limits go back to default.
Node-level step that is not GitOps
Periodic TRIM is not covered by this directory. fstrim.timer was disabled
on siriussec while /dev/nvme0n1 reports DISC-MAX 2T; enable it once (it
survives reboots):
sudo systemctl enable --now fstrim.timer
That is hygiene against write amplification/GC on a heavily churned SSD, not a measured tail-latency fix.