From 6d9f5176e18b792dc6fb3582a3557c55bfe2d7e0 Mon Sep 17 00:00:00 2001 From: Lance Walters Date: Mon, 26 Oct 2026 17:10:18 -0400 Subject: [PATCH] node-io: add io.max layer so dind cannot fill the device queue --- infrastructure/node-io/configmap.yaml | 4 ++ infrastructure/node-io/etcd-io-guard.yaml | 18 +++++ infrastructure/node-io/guard-script.sh | 80 +++++++++++++++++++---- 3 files changed, 89 insertions(+), 13 deletions(-) diff --git a/infrastructure/node-io/configmap.yaml b/infrastructure/node-io/configmap.yaml index 494ba32..42e7d9c 100644 --- a/infrastructure/node-io/configmap.yaml +++ b/infrastructure/node-io/configmap.yaml @@ -14,3 +14,7 @@ data: # more than the etcd tail; keep background <= bytes. dirty-bytes: "67108864" dirty-background-bytes: "16777216" + # blk-throttle cap on the dind container's own cgroup (bytes/s write). + # dirty_bytes bounds the backlog; this bounds how much of the device queue + # dind may occupy, so etcd's tiny WAL writes find a free slot. + dind-wbps: "41943040" diff --git a/infrastructure/node-io/etcd-io-guard.yaml b/infrastructure/node-io/etcd-io-guard.yaml index a7f8190..afa09af 100644 --- a/infrastructure/node-io/etcd-io-guard.yaml +++ b/infrastructure/node-io/etcd-io-guard.yaml @@ -43,6 +43,11 @@ spec: configMapKeyRef: name: etcd-io-guard-config key: dirty-background-bytes + - name: DIND_WBPS + valueFrom: + configMapKeyRef: + name: etcd-io-guard-config + key: dind-wbps securityContext: privileged: true resources: @@ -55,6 +60,11 @@ spec: volumeMounts: - name: host-proc-sys mountPath: /host/proc/sys/vm + - name: host-proc + mountPath: /host/proc + readOnly: true + - name: host-cgroup + mountPath: /host/sys/fs/cgroup - name: script mountPath: /opt/guard readOnly: true @@ -63,6 +73,14 @@ spec: hostPath: path: /proc/sys/vm type: Directory + - name: host-proc + hostPath: + path: /proc + type: Directory + - name: host-cgroup + hostPath: + path: /sys/fs/cgroup + type: Directory - name: script configMap: name: etcd-io-guard-script diff --git a/infrastructure/node-io/guard-script.sh b/infrastructure/node-io/guard-script.sh index f1b864e..e12aca4 100644 --- a/infrastructure/node-io/guard-script.sh +++ b/infrastructure/node-io/guard-script.sh @@ -1,25 +1,38 @@ #!/bin/sh -# Keep the host's writeback backlog bounded so an etcd WAL fdatasync does not -# wait for gigabytes of dind writeback. Idempotent: rewrites only on drift. +# etcd-io-guard: keep etcd's WAL fdatasync tail short while the amd64 dind +# runner hammers the same PM991 NVMe (/dev/nvme0n1p3). # -# Deliberately NOT done here: per-cgroup io.latency / io.max on the dind pod. -# io.latency only throttles *peers of the same parent* (cgroup-v2 doc, and -# block/blk-iolatency.c: a miss is recorded in the missing group's parent -# child_lat), and kubelet puts every pod in its own slice, so an etcd target -# can never throttle the dind pod - measured on 2026-10-26: dind depth stayed -# `max` and the stall count did not move. See README.md in the repo. +# Two layers, both re-applied on drift every 30 s: +# +# 1. Bound the host writeback backlog (vm.dirty_bytes / dirty_background_bytes). +# On the default vm.dirty_ratio=20 a 15 GB box allows ~3 GB of dirty pages, +# so an etcd WAL commit queues behind seconds of dind writeback. 64/16 MiB +# removes the multi-second (>8 s) stalls but, measured 2026-10-26, still +# leaves 1-4 s fdatasyncs and lets kube-controller-manager / kube-scheduler +# lose their leases, because 64 MiB at this device's throttled drain rate is +# still ~1.4 s of queue. +# +# 2. Cap the dind container's dispatch rate with blk-throttle io.max. This is +# NOT the peer-scoped io.latency controller (which cannot reach across +# kubelet's per-pod slices and was measured to do nothing): io.max is an +# absolute per-cgroup cap, so the dind cgroup can only keep N requests in +# the device queue and etcd's small WAL writes find free slots. +# +# The dind container's cgroup path changes on every pod restart, so layer 2 +# re-discovers the scope by looking for the container whose main process is +# dockerd. Nothing here targets kubepods-burstable.slice (etcd lives in it). set -u + DB="${DIRTY_BYTES:-67108864}" DBG="${DIRTY_BACKGROUND_BYTES:-16777216}" +WMAX="${DIND_WBPS:-41943040}" # 40 MiB/s write bandwidth cap for dind +CGROOT="${CGROUP_ROOT:-/host/sys/fs/cgroup}" +PROCROOT="${PROC_ROOT:-/host/proc}" log() { echo "$(date -u +%FT%TZ) $*"; } -log "start dirty_bytes=${DB} dirty_background_bytes=${DBG}" -while true; do +apply_writeback_limits() { cur_bg="$(cat /host/proc/sys/vm/dirty_background_bytes 2>/dev/null || echo read-error)" - # dirty_background_bytes must be written before dirty_bytes: writing - # dirty_bytes zeroes dirty_ratio, and a nonzero dirty_background_bytes keeps - # dirty_background_ratio out of play. if [ "${cur_bg}" != "${DBG}" ]; then if echo "${DBG}" > /host/proc/sys/vm/dirty_background_bytes 2>/dev/null; then log "applied vm.dirty_background_bytes=${DBG} (was ${cur_bg})" @@ -35,5 +48,46 @@ while true; do log "FAILED to write vm.dirty_bytes" fi fi +} + +# Echo the cgroup directory of the dind container, or nothing. +find_dind_cgroup() { + for procs in "${CGROOT}"/kubepods.slice/kubepods-*.slice/kubepods-*-pod*.slice/cri-containerd-*.scope/cgroup.procs; do + [ -f "${procs}" ] || continue + dir="${procs%/cgroup.procs}" + while read -r pid; do + [ -n "${pid}" ] || continue + comm="$(cat "${PROCROOT}/${pid}/comm" 2>/dev/null || true)" + if [ "${comm}" = "dockerd" ]; then + echo "${dir}" + return 0 + fi + done < "${procs}" + done + return 1 +} + +apply_io_max() { + dir="$(find_dind_cgroup)" || return 1 + want="259:0 wbps=${WMAX}" + cur="$(cat "${dir}/io.max" 2>/dev/null || true)" + case "${cur}" in + *"${want}"*) : ;; + *) + if echo "${want}" > "${dir}/io.max" 2>/dev/null; then + log "applied io.max '${want}' to ${dir#"${CGROOT}"} (was '${cur}')" + else + log "FAILED to write io.max to ${dir#"${CGROOT}"}" + fi + ;; + esac +} + +log "start dirty_bytes=${DB} dirty_background_bytes=${DBG} dind_wbps=${WMAX}" +while true; do + apply_writeback_limits + if ! apply_io_max; then + log "no dockerd cgroup found yet (runner pod down?)" + fi sleep 30 done