Show service memory usage (cgroup v2)

Current memory usage of a systemd service (page cache included) and its hard limit. If current is close to max, OOM is near

cat /sys/fs/cgroup/system.slice/<name>.service/memory.current /sys/fs/cgroup/system.slice/<name>.service/memory.max

tool
cgroups8 commands
tags
cgroupsmemoryperformancetroubleshooting

More cgroups commands

  • cat /sys/fs/cgroup/system.slice/<name>.service/memory.pressure

    PSI shows how long tasks wait for memory reclaim. A growing avg10 means thrashing before OOM

  • grep -E 'nr_throttled|throttled_usec' /sys/fs/cgroup/system.slice/<name>.service/cpu.stat

    How many times and for how many microseconds the cgroup was throttled by the cpu.max quota

  • cat /sys/fs/cgroup/system.slice/<name>.service/cpu.max # "max 100000" = unlimited; "50000 100000" = 0.5 core

    cpu.max is "quota period" in microseconds, max means no limit. To change it, use systemctl set-property

  • cat /sys/fs/cgroup/system.slice/<name>.service/io.pressure /sys/fs/cgroup/system.slice/<name>.service/io.stat

    PSI IO stalls plus rbytes/wbytes/rios per major:minor. Helps find noisy disk neighbors

  • cat /sys/fs/cgroup/system.slice/<name>.service/cgroup.procs; systemctl status <name>.service | grep CGroup

    All PIDs that are in the service cgroup right now. Compare them with the tree from systemctl status

all 8 cgroups commands