容器进程因io导致cacheMemory较高处理随记

来自三线的随记
Admin讨论 | 贡献2025年10月22日 (三) 18:19的版本

就好像harbor的registry容器,因为经常有io,所以比较容易触发这种现象。

或者频繁追加写日志到文件的进程,也会触发这种现象

如果是cgroup2,就可以用cgroup2 的mem.high处理。找到相应的cgroup2路径,配置mem.high即可

以harbor为例

nerdctl ps|grep registry-photon|awk '{print "nerdctl inspect --mode native -f \"{{json .Spec.linux.cgroupsPath}}\" "$1}'|sh|cut -c 2-|cut -c -144|awk 'BEGIN{FS=":"};{print "cat /sys/fs/cgroup/kubepods.slice/kubepods-burstable.slice/"$1"/"$2"-"$3".scope/memory.high"}'


nerdctl ps|grep registry-photon|awk '{print "nerdctl inspect --mode native -f \"{{json .Spec.linux.cgroupsPath}}\" "$1}'|sh|cut -c 2-|cut -c -144|awk 'BEGIN{FS=":"};{print "echo 2G >  /sys/fs/cgroup/kubepods.slice/kubepods-burstable.slice/"$1"/"$2"-"$3".scope/memory.high"}'