Reading — step 1 of 5
Read
cgroups: CPU Limits
CPU limits in cgroups come in three flavors:
Shares (relative weight):
cpu.shares = 1024 (default)
Two cgroups with shares 1024 each split CPU 50/50 under contention. With shares 2048 vs 1024, it's 67/33. No effect when only one is using CPU.
Quota (hard cap on absolute CPU time):
cpu.cfs_period_us = 100000 (100ms accounting period)
cpu.cfs_quota_us = 50000 (50ms allowed per period)
Cap at 0.5 CPUs (50%). Period is fixed at 100ms by default; quota is the work budget. Setting quota > period * num_cores means "more than one core's worth allowed".
Cpuset (specific CPUs):
cpuset.cpus = 0-3 (this cgroup runs only on cores 0-3)
cpuset.mems = 0 (NUMA node 0 only)
Used for cache-locality-sensitive workloads. Pin a real-time process to its own cores.
In Docker:
--cpu-shares 512-> cpu.shares=512--cpus 0.5-> cfs_quota=50000, cfs_period=100000--cpuset-cpus 0,2-> cpuset.cpus=0,2
Throttling is invisible to the process — it just runs slower than expected. Watch throttled_time in cpu.stat for evidence.
For this lesson: model quota-based CPU limiting.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…