node-io: bound the writeback backlog so dind writeback cannot stall etcd

This commit is contained in:
Lance Walters 2026-10-26 16:35:03 -04:00
commit c773a3e2a9
7 changed files with 220 additions and 0 deletions

View file

@ -0,0 +1,39 @@
#!/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.
#
# 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.
set -u
DB="${DIRTY_BYTES:-67108864}"
DBG="${DIRTY_BACKGROUND_BYTES:-16777216}"
log() { echo "$(date -u +%FT%TZ) $*"; }
log "start dirty_bytes=${DB} dirty_background_bytes=${DBG}"
while true; do
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})"
else
log "FAILED to write vm.dirty_background_bytes"
fi
fi
cur_db="$(cat /host/proc/sys/vm/dirty_bytes 2>/dev/null || echo read-error)"
if [ "${cur_db}" != "${DB}" ]; then
if echo "${DB}" > /host/proc/sys/vm/dirty_bytes 2>/dev/null; then
log "applied vm.dirty_bytes=${DB} (was ${cur_db})"
else
log "FAILED to write vm.dirty_bytes"
fi
fi
sleep 30
done