In this lesson, you will learn how to enforce fine-grained CPU time distribution by balancing relative weight-based shares against strict time-based quota constraints.
While we previously explored the Cgroup v2 hierarchy for organizing processes, we now focus on the CFS (Completely Fair Scheduler) mechanisms that dictate how those processes compete for execution cycles. We manage this competition through two distinct, yet complementary, knobs: CPU Shares and Period Constraints (Quota).
Proportional Shares (Weight)
cpu.weight allows you to define the relative importance of a container group. This is a "soft" limit; if the system has spare capacity, a group can use more than its share. If multiple groups are competing for CPU, the scheduler distributes cycles based on the ratio of their weights. If Group A has a weight of 200 and Group B has 100, Group A will receive twice the CPU time of Group B during periods of contention.
Period Constraints (Quota)
Sometimes, you need a "hard" cap—a guarantee that a process cannot exceed a specific amount of time regardless of system availability. This is managed via cpu.max, which takes two values: quota and period.
- Period: The duration of the measurement window (default is usually 100,000 microseconds, or 100ms).
- Quota: The total time within that window a group is allowed to run.
For example, if you set cpu.max to 50000 100000, the process is permitted to execute for 50ms every 100ms window, effectively capping its utilization at 50% of a single core.
Putting it Together
The power of this system lies in the interaction. You can define a high cpu.weight to ensure a service stays responsive during load, while simultaneously applying a cpu.max limit to prevent a runaway process from consuming the entire host. By combining these, you ensure that your containers remain performant under pressure without monopolizing underlying hardware resources.
Key Takeaway: Use CPU shares for proportional bandwidth allocation during contention and period constraints for enforcing absolute execution ceilings.