Drill: Inspect Cgroup Resource Limits and Usage¶
Goal¶
Inspect cgroup resource limits and current usage for a systemd service to understand resource constraints.
Setup¶
- Linux system with cgroups v2 (most modern distros) or v1
- Root access or membership in appropriate groups
- A running service to inspect
Commands¶
Check which cgroup version is in use:
Find the cgroup for a service:
View CPU usage:
View memory current usage and limits:
cat /sys/fs/cgroup/system.slice/nginx.service/memory.current
cat /sys/fs/cgroup/system.slice/nginx.service/memory.max
cat /sys/fs/cgroup/system.slice/nginx.service/memory.stat
Check IO stats:
Use systemd-cgtop for a live view:
View resource limits set via systemd:
Set a memory limit via drop-in:
What to Look For¶
memory.currentvsmemory.maxshows how close a service is to its limitcpu.statshowsusage_usecfor total CPU time andnr_throttledfor throttling eventsmemory.statbreaks down memory into anon, file cache, slab, etc.systemd-cgtopgives a top-like view organized by cgroup hierarchy
Common Mistakes¶
- Looking in cgroups v1 paths when the system uses v2 (or vice versa)
- Confusing the slice hierarchy path (system.slice vs user.slice)
- Not understanding that
memory.maxofmaxmeans unlimited - Forgetting that
set-propertycreates a persistent drop-in override