node-io: add io.max layer so dind cannot fill the device queue
This commit is contained in:
parent
f38f9433b9
commit
6d9f5176e1
3 changed files with 89 additions and 13 deletions
|
|
@ -14,3 +14,7 @@ data:
|
||||||
# more than the etcd tail; keep background <= bytes.
|
# more than the etcd tail; keep background <= bytes.
|
||||||
dirty-bytes: "67108864"
|
dirty-bytes: "67108864"
|
||||||
dirty-background-bytes: "16777216"
|
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"
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,11 @@ spec:
|
||||||
configMapKeyRef:
|
configMapKeyRef:
|
||||||
name: etcd-io-guard-config
|
name: etcd-io-guard-config
|
||||||
key: dirty-background-bytes
|
key: dirty-background-bytes
|
||||||
|
- name: DIND_WBPS
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: etcd-io-guard-config
|
||||||
|
key: dind-wbps
|
||||||
securityContext:
|
securityContext:
|
||||||
privileged: true
|
privileged: true
|
||||||
resources:
|
resources:
|
||||||
|
|
@ -55,6 +60,11 @@ spec:
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: host-proc-sys
|
- name: host-proc-sys
|
||||||
mountPath: /host/proc/sys/vm
|
mountPath: /host/proc/sys/vm
|
||||||
|
- name: host-proc
|
||||||
|
mountPath: /host/proc
|
||||||
|
readOnly: true
|
||||||
|
- name: host-cgroup
|
||||||
|
mountPath: /host/sys/fs/cgroup
|
||||||
- name: script
|
- name: script
|
||||||
mountPath: /opt/guard
|
mountPath: /opt/guard
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
|
@ -63,6 +73,14 @@ spec:
|
||||||
hostPath:
|
hostPath:
|
||||||
path: /proc/sys/vm
|
path: /proc/sys/vm
|
||||||
type: Directory
|
type: Directory
|
||||||
|
- name: host-proc
|
||||||
|
hostPath:
|
||||||
|
path: /proc
|
||||||
|
type: Directory
|
||||||
|
- name: host-cgroup
|
||||||
|
hostPath:
|
||||||
|
path: /sys/fs/cgroup
|
||||||
|
type: Directory
|
||||||
- name: script
|
- name: script
|
||||||
configMap:
|
configMap:
|
||||||
name: etcd-io-guard-script
|
name: etcd-io-guard-script
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,38 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Keep the host's writeback backlog bounded so an etcd WAL fdatasync does not
|
# etcd-io-guard: keep etcd's WAL fdatasync tail short while the amd64 dind
|
||||||
# wait for gigabytes of dind writeback. Idempotent: rewrites only on drift.
|
# runner hammers the same PM991 NVMe (/dev/nvme0n1p3).
|
||||||
#
|
#
|
||||||
# Deliberately NOT done here: per-cgroup io.latency / io.max on the dind pod.
|
# Two layers, both re-applied on drift every 30 s:
|
||||||
# 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
|
# 1. Bound the host writeback backlog (vm.dirty_bytes / dirty_background_bytes).
|
||||||
# child_lat), and kubelet puts every pod in its own slice, so an etcd target
|
# On the default vm.dirty_ratio=20 a 15 GB box allows ~3 GB of dirty pages,
|
||||||
# can never throttle the dind pod - measured on 2026-10-26: dind depth stayed
|
# so an etcd WAL commit queues behind seconds of dind writeback. 64/16 MiB
|
||||||
# `max` and the stall count did not move. See README.md in the repo.
|
# 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
|
set -u
|
||||||
|
|
||||||
DB="${DIRTY_BYTES:-67108864}"
|
DB="${DIRTY_BYTES:-67108864}"
|
||||||
DBG="${DIRTY_BACKGROUND_BYTES:-16777216}"
|
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() { echo "$(date -u +%FT%TZ) $*"; }
|
||||||
|
|
||||||
log "start dirty_bytes=${DB} dirty_background_bytes=${DBG}"
|
apply_writeback_limits() {
|
||||||
while true; do
|
|
||||||
cur_bg="$(cat /host/proc/sys/vm/dirty_background_bytes 2>/dev/null || echo read-error)"
|
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 [ "${cur_bg}" != "${DBG}" ]; then
|
||||||
if echo "${DBG}" > /host/proc/sys/vm/dirty_background_bytes 2>/dev/null; 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})"
|
log "applied vm.dirty_background_bytes=${DBG} (was ${cur_bg})"
|
||||||
|
|
@ -35,5 +48,46 @@ while true; do
|
||||||
log "FAILED to write vm.dirty_bytes"
|
log "FAILED to write vm.dirty_bytes"
|
||||||
fi
|
fi
|
||||||
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
|
sleep 30
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue