In this lesson, you will learn how to use Pressure Stall Information (PSI) to detect when your containers are struggling due to resource starvation rather than just high utilization.
Understanding Resource Contention
In a containerized environment, high CPU or memory usage is often misinterpreted as a performance bottleneck. However, a container running at 90% CPU might be perfectly healthy, while one at 30% might be stuttering because it is waiting for blocked I/O or swap memory.
Pressure Stall Information (PSI) provides a metric for "stalls"—the percentage of time tasks spent waiting for a resource. Unlike traditional utilization metrics, PSI tells you how much the system's performance is actually being degraded.
Monitoring PSI at the Cgroup Level
PSI is exposed through the cgroup v2 filesystem. For every cgroup (including your containers), the kernel provides a io.pressure, memory.pressure, and cpu.pressure file. Each file contains two lines: some and full.
- Some: The percentage of time at least one task was delayed.
- Full: The percentage of time all non-idle tasks were delayed simultaneously (meaning the container has completely stalled).
If you are monitoring a container and see full pressure rising in memory.pressure, your container is thrashing. It is unable to make any progress because it is constantly waiting for memory pages to be swapped or reclaimed.
You can inspect this from the host with:
# Check memory pressure for a specific container
cat /sys/fs/cgroup/system.slice/docker-<container_id>.scope/memory.pressure
Proactive Bottleneck Identification
By monitoring these files, you can implement proactive alerting. Instead of alerting on "80% memory usage," you alert when memory.pressure indicates that tasks are stalled for more than a specific threshold (e.g., 5% over a 10-second window). This allows you to differentiate between a container that is simply caching data effectively and one that is experiencing genuine resource starvation. This precision is vital in multi-tenant environments where you need to identify which specific container is impacting the performance of others due to resource contention.
Key Takeaway: PSI shifts the focus from how much of a resource a container uses to how much the container is being stalled by that resource, enabling accurate identification of true performance bottlenecks.