node-io: document the io.max layer and the measured before/after
This commit is contained in:
parent
baac2419e4
commit
242d76a6d3
1 changed files with 69 additions and 49 deletions
|
|
@ -1,81 +1,101 @@
|
|||
# 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.
|
||||
`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.
|
||||
|
||||
## What the fault actually is (measured 2026-10-26)
|
||||
## 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 | 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 %) |
|
||||
| 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 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
|
||||
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 this DaemonSet does
|
||||
## What the guard does (two layers, re-applied every 30 s)
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
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.
|
||||
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
|
||||
# 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
|
||||
kubectl -n node-io logs ds/etcd-io-guard --tail=6 # "start" + "applied io.max ..." per pod
|
||||
|
||||
# the host agrees (0 ratio => the byte limits are in force)
|
||||
# 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
|
||||
# expect 67108864 / 16777216 / 0 / 0
|
||||
|
||||
# etcd tail under load
|
||||
# the cap is on the current dind (dockerd) cgroup, not on a slice
|
||||
ssh -i ~/.ssh/lancelot_priv Lancelot@192.168.1.179 \
|
||||
'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'
|
||||
'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'
|
||||
```
|
||||
|
||||
## Tuning and known trade-offs
|
||||
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.
|
||||
|
||||
- Both knobs are in `configmap.yaml`; change, push, Flux applies, the guard
|
||||
rewrites within 30 s. Keep `dirty-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.
|
||||
## 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
|
||||
on siriussec while `/dev/nvme0n1` reports `DISC-MAX 2T`; enable it once (it
|
||||
survives reboots):
|
||||
while `/dev/nvme0n1` reports `DISC-MAX 2T`; enable it once (it survives reboots):
|
||||
|
||||
```bash
|
||||
sudo systemctl enable --now fstrim.timer
|
||||
```
|
||||
|
||||
That is hygiene against write amplification/GC on a heavily churned SSD, not a
|
||||
measured tail-latency fix.
|
||||
Hygiene against write amplification/GC on a heavily churned SSD, not a measured
|
||||
tail-latency fix.
|
||||
|
|
|
|||
Loading…
Reference in a new issue