# node-io — protecting etcd's WAL fsync from the dind runner `etcd-io-guard` is a one-node DaemonSet (siriussec) that stops the amd64 Forgejo runner (`forgejo-runner-amd64`, privileged `docker:dind`) from starving etcd on the shared PM991 NVMe (`/dev/nvme0n1p3`). The etcd WAL, the dind data-root, `forgejo-data` and the CNPG PVCs all live on that one device. ## The fault (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 | during an unmitigated burst the dind cgroup moved ~41–48 MB/s at ~35 IOPS with `ios in progress` 0 — the device queue was nearly empty while etcd fsyncs took seconds | | bulk dirty data is what causes it | the same load with only fsync/metadata writers (no 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** (`block/blk-iolatency.c`: a miss is recorded in the missing group's *parent* `child_lat`). kubelet gives every pod its own slice, so etcd's leaf and the dind leaf never influence each other. Setting `259:0 target=50000` on etcd's leaf is accepted, but during load the dind cgroup's `io.stat` still read `depth=max` — never throttled — and the stall count did not move | | an unmitigated burst takes the control plane down | 4×1 GiB `dd conv=fsync` on the same device: etcd `slow fdatasync` **68.9 s, 26.6 s, 17.6 s**; `kube-apiserver` restarted, `kube-controller-manager` and `kube-scheduler` logged `Failed to renew lease` → `leaderelection lost/stopped` | Mechanism in one sentence: an `fdatasync` completes only once 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 — and on the default `vm.dirty_ratio=20` (≈3 GB of a 15 GB box) that backlog is seconds of I/O. ## What the guard does (two layers, re-applied every 30 s) 1. **Bounds the host writeback backlog** — writes `vm.dirty_bytes=64 MiB` and `vm.dirty_background_bytes=16 MiB` into the host `/proc/sys/vm`. 2. **Caps the dind container's dispatch rate** — `io.max` `wbps=40 MiB/s` on the cgroup of the container whose main process is `dockerd`. This is *not* the peer-scoped `io.latency` controller: `io.max` is an absolute per-cgroup cap, so dind can only keep a bounded number of requests in the device queue and etcd's tiny WAL writes find free slots. The dind cgroup path changes on every pod recreation, so layer 2 re-discovers it by scanning `kubepods.slice/**/cri-containerd-*.scope` for `dockerd` on each tick. Nothing is written to `kubepods-burstable.slice` or `kubepods.slice` — etcd lives in that slice. ## Measured result (same load before/after) Load: 4 concurrent writers, 128 MiB per `dd conv=fsync`, 150 s, executed **inside the dind container** so the I/O is charged to the dind cgroup. | metric | no mitigation | guard (64 MiB + 40 MiB/s) | |---|---|---| | worst `slow fdatasync` | 68.9 s (burst run) | **1.40 s** | | `slow fdatasync` lines | 11 | **1** | | etcd fsyncs > 8.192 s | 5 | **0** | | etcd fsyncs > 2.048 s | 39 (dirty-limit only) | **1** | | control-plane restarts during run | apiserver 1, KCM/scheduler leases lost | **none** | | dind write volume | ~8 GiB / 178 s (~46 MB/s) | exactly 6.0 GiB / 157 s (**41 MB/s — the cap binds**) | ## Verify ```bash kubectl -n node-io get ds,po kubectl -n node-io logs ds/etcd-io-guard --tail=6 # "start" + "applied io.max ..." per pod # host agrees with the ConfigMap (0 ratio => the byte limits are in force) ssh -i ~/.ssh/lancelot_priv Lancelot@192.168.1.179 \ 'sysctl vm.dirty_bytes vm.dirty_background_bytes vm.dirty_ratio vm.dirty_background_ratio' # expect 67108864 / 16777216 / 0 / 0 # the cap is on the current dind (dockerd) cgroup, not on a slice ssh -i ~/.ssh/lancelot_priv Lancelot@192.168.1.179 \ 'for d in $(sudo find /sys/fs/cgroup/kubepods.slice -name io.max -path "*cri-containerd-*"); do \ grep -q . /dev/null; sudo cat $d | grep -q wbps=41943040 && echo "$d"; done' # etcd tail kubectl -n kube-system logs etcd-siriussec --since=1h | grep 'slow fdatasync' ``` Self-healing is proven by deleting the runner pod: the replacement gets a new cgroup path and the guard applies `io.max` to it within one 30 s tick. ## Tuning and trade-offs - Knobs live in `configmap.yaml` (`dirty-bytes`, `dirty-background-bytes`, `dind-wbps`); change, push, Flux applies, the guard rewrites within 30 s. - 64 MiB is aggressive (≈0.4 % of a 15 GB box) and the 40 MiB/s cap costs ~11 % of dind write bandwidth (46 → 41 MB/s). Both were chosen for the etcd tail; raise them if CI wall time regresses more than ~20 %. - The dirty limits are host-global: they bind every writer on siriussec, not just the runner. The kernel has no per-cgroup dirty limit that binds a different pod. - `io.cost`/`io.weight` would be the better tool (it can reserve latency rather than bandwidth) but this kernel exposes no `/sys/block/nvme0n1/queue/io.cost.*`, so `io.max` is the available lever. - Not touched here: the dind data-root is still on the etcd device. Moving it to its own disk removes the contention entirely and is the only change that lets these limits go back to default. ## Node-level step that is not GitOps Periodic TRIM is **not** covered by this directory. `fstrim.timer` was disabled while `/dev/nvme0n1` reports `DISC-MAX 2T`; enable it once (it survives reboots): ```bash sudo systemctl enable --now fstrim.timer ``` Hygiene against write amplification/GC on a heavily churned SSD, not a measured tail-latency fix.