In this lesson, you will learn how to use cgroup v2 to prevent a single process or service from saturating your storage device by strictly limiting its disk I/O bandwidth.
Controlling Disk Congestion
When you run multiple services on a single server, one "noisy neighbor" process performing massive read/write operations can choke the disk, causing latency spikes for every other application. While we have previously discussed filesystem-level optimizations like Btrfs metadata tuning or subvolume management, bandwidth capping happens at the kernel’s controller level. With cgroup v2, we can apply "throttling" to ensure a specific service only consumes a designated slice of your disk’s I/O capacity.
Implementing I/O Limits
The cgroup v2 interface manages I/O via the io.max file. To limit a service, you define the major and minor numbers of your storage device followed by the rbps (read bytes per second) or wbps (write bytes per second) limit.
For example, if you want to restrict a backup service (contained within a specific cgroup) to a maximum write speed of 10MB/s on your primary disk (e.g., major:minor 8:0), you would run:
# Set a write limit of 10MB/s for the group
echo "8:0 wbps=10485760" | sudo tee /sys/fs/cgroup/my_service/io.max
Once this value is set, the kernel monitors all write operations originating from processes in that cgroup. If the process exceeds the defined threshold, the kernel will artificially delay those I/O requests, effectively throttling the service to keep your disk bandwidth available for more critical tasks.
This approach is highly effective because it doesn't require modifying the application code; it is a policy enforced directly by the Linux kernel. By combining this with the storage management techniques you have already mastered—such as managing Btrfs subvolumes or monitoring pool health—you gain granular control over both your data structure and your hardware performance.
Key Takeaway: Use cgroup v2 io.max to define hard bandwidth limits on specific processes, ensuring that I/O-heavy background tasks cannot overwhelm your storage performance.