Skip to main content
Container Resource Limits: What They Actually Do at the Kernel Level

Container Resource Limits: What They Actually Do at the Kernel Level

KU
· Founder & Chief Editor
• 8 min read•Updated •

cpu.weight vs cpu.max vs memory.max: the cgroup mechanics behind Kubernetes resource limits, and the surprises that explain the weird symptoms you've seen.

Key takeaways

  • A CPU request becomes a cgroup weight that only matters under contention, while a CPU limit becomes a CFS quota per 100 ms period that throttles even on an idle node.
  • A memory limit becomes memory.max, a hard ceiling enforced by the OOM killer, and page cache counts toward it.
  • Keep memory limits; question CPU limits on latency-sensitive services.

A Kubernetes CPU request becomes a cgroup weight (cpu.weight on cgroup v2, cpu.shares on v1) that only matters when CPUs are contended. A CPU limit becomes a CFS quota in cpu.max, enforced per 100 ms period, so it throttles even on an idle node. A memory limit becomes memory.max, a hard ceiling enforced by OOM kills.

Verified against

Kubernetes 1.37 docs, Linux kernel cgroup v2 and CFS bandwidth control docs, OpenJDK container-awareness backports (JDK 15, 11.0.16, 8u372), against kubernetes.io, docs.kernel.org and bugs.openjdk.org. Checked October 2026.

That model explains the symptoms teams hit: throttling on a barely loaded service, OOM kills well below what ps reports, "CPU at 50% but everything's slow." Since Kubernetes 1.35 the kubelet refuses cgroup v1 nodes by default (the cgroup v1 kubelet failure covers the migration), so this post uses v2 file names and notes the v1 equivalents.

See it for yourself first

On a cgroup v2 node, a container sees its own cgroup at /sys/fs/cgroup. For a pod with requests.cpu: 500m, limits.cpu: 1, limits.memory: 512Mi:

Terminal
kubectl exec -it api-7d9f -- sh -c 'cat /sys/fs/cgroup/cpu.max /sys/fs/cgroup/memory.max'
100000 100000
536870912
kubectl exec -it api-7d9f -- cat /sys/fs/cgroup/cpu.stat
usage_usec 81234567
user_usec 70211002
system_usec 11023565
nr_periods 412880
nr_throttled 9312
throttled_usec 401229331
nr_bursts 0
burst_usec 0

cpu.max reads "quota period": 100,000 µs of CPU per 100,000 µs, one CPU. memory.max is 512 MiB in bytes. The request lands in cpu.weight, whose exact value depends on your runtime's shares-to-weight conversion, so treat it as relative. In cpu.stat, nr_throttled / nr_periods is the share of periods in which the container hit its quota. Above a few percent on a latency-sensitive service, the limit is costing you.

CPU requests are a weight, not a reservation

The scheduler uses requests to place pods: the sum of requests on a node can't exceed allocatable capacity. At runtime the kernel turns the request into a weight. On cgroup v1, 500m becomes cpu.shares: 512 (1,024 per CPU). On v2 it becomes a cpu.weight in the range 1 to 10,000, default 100.

A weight only matters when there is contention. If the node has idle CPU, your container gets as much as it wants regardless of its request. Kubernetes says it plainly: a container may use more than its request if the node has the resource available. A node packed to 90% of requested CPU can still let one container use far more than its request while neighbors idle. That's the design.

CPU limits are a quota per period

Limits use CFS bandwidth control. The kernel gives the cgroup a quota of CPU time per period, written to cpu.max (v1: cpu.cfs_quota_us and cpu.cfs_period_us). The default period is 100 ms; a 500m limit becomes 50000 100000, 50 ms of CPU per 100 ms window. Once the quota is spent, every thread in the cgroup is throttled until the next period.

That is why a container can be throttled while the node idles. The limit is per period, not per second. Average usage can read 50% while individual 100 ms windows are exhausted in their first 30 ms.

The quota is also spread across cores, which is the part people miss. A 1 CPU limit on a 16-core node lets 16 threads run in parallel, each burning quota, so the 100 ms budget is gone in about 6 ms of wall clock. The container then sits idle for the remaining 94 ms. A JVM running parallel GC threads, or any thread pool sized to the host's core count, hits this on every collection: pauses stretch several times longer than the CPU work they contain.

Why removing CPU limits is often correct

If your concern is "a runaway service can't eat the whole node," the request already handles it under contention: weights decide who gets CPU when there isn't enough. The limit only bites when there's no contention, which is exactly when you didn't need protection. For latency-sensitive services we'd remove CPU limits and keep requests honest. Keep limits where you need predictable performance (benchmarks, Guaranteed QoS for CPU pinning with the static CPU manager policy) or on multi-tenant nodes where one team must not borrow another's idle CPU.

If you keep limits, the kubelet's cpuCFSQuotaPeriod (1 ms to 1 s, default 100 ms) can shorten the period so throttling waits are shorter, but it needs the CustomCPUCFSQuotaPeriod feature gate and adds scheduling overhead. Test it per workload; it isn't a general win.

Memory limits are a hard ceiling

Memory is not compressible: you can't throttle a process's memory the way you throttle its CPU. When usage reaches memory.max and the kernel can't reclaim enough, it invokes the OOM killer inside the cgroup. The details that surprise people:

Page cache counts. memory.current includes page cache and anonymous memory. A workload doing heavy file I/O shows usage far above its RSS. Clean page cache is reclaimable, so it usually gets dropped before an OOM, but dirty pages and tmpfs (including emptyDir with medium: Memory) are charged and much harder to reclaim. Compare anon and file in memory.stat, not ps.

The whole container dies together. On cgroup v2, the kubelet sets memory.oom.group, so all processes in the container are killed as a unit. Setting singleProcessOOMKill: true in the kubelet config restores the v1 behavior of killing one process.

Pressure shows up before the kill. memory.pressure (PSI) and the high and max counters in memory.events rise as the cgroup reclaims. Watching them gives you warning; reading PSI before the OOM shows how.

Why containers see "wrong" memory in /proc/meminfo

/proc/meminfo and /proc/cpuinfo inside a container report the host, not the cgroup. Anything that sizes itself from them misbehaves. Java has read cgroup v2 limits since JDK 15, backported to 11.0.16 and 8u372; older builds see only v1 or the host. Set heap explicitly anyway, so the sizing is visible in the manifest:

YAML
# k8s/api-deployment.yaml (container excerpt)
resources:
  requests: { cpu: "500m", memory: "1Gi" }
  limits:   { memory: "1Gi" }
env:
  - name: JAVA_TOOL_OPTIONS
    value: "-XX:MaxRAMPercentage=75 -XX:ActiveProcessorCount=2"

ActiveProcessorCount stops the JVM sizing GC and thread pools from the host's core count. For Node.js, set --max-old-space-size below the limit; for Go, GOMEMLIMIT.

Failure modes and the exact signals

What you seeWhere it comes fromFix
OOMKilled, exit code 137, in kubectl describe podUsage hit memory.maxRaise the limit or fix the leak; see OOMKilled troubleshooting
oom_kill count rising in memory.events with no pod restartOne child process killed (singleProcessOOMKill: true or v1)Check which process; size the worker pool
High p99, low average CPU, nr_throttled climbingCFS quota exhausted early in each periodRemove the CPU limit or raise it; cap thread counts
The node was low on resource: memory evictionNode pressure, pod above its requestSet memory request equal to real usage
JVM OutOfMemoryError long before the limitHeap sized from defaults or the hostMaxRAMPercentage, check java -XshowSettings:system

Where this breaks

This describes Linux nodes with cgroup v2 and the default CFS scheduler path. Windows containers use job objects, not cgroups. VM-isolated runtimes (Kata, gVisor, Firecracker) enforce limits at a guest boundary with different symptoms. With the MemoryQoS feature enabled, the kubelet also sets memory.high below the limit, which throttles allocations before any OOM. And removing CPU limits assumes honest requests; if requests are guesses, fix those first with request right-sizing.

Questions people ask

What happens when a container exceeds its CPU limit?

It gets throttled, not killed. The CPU limit becomes a CFS quota, by default per 100 ms period, written to cpu.max on cgroup v2. When the container's threads use up the quota, all of them pause until the next period starts. You see it as nr_throttled and throttled_usec rising in cpu.stat, and as latency spikes even while average CPU usage looks low.

Should I set CPU limits in Kubernetes?

For most latency-sensitive services, set accurate CPU requests and skip the limit. Requests become weights that protect neighbors when CPUs are contended; limits only add throttling when there is spare capacity. Keep limits for Guaranteed-QoS workloads that need CPU pinning, for benchmarking, or on shared multi-tenant nodes where teams must not borrow each other's idle CPU.

Does page cache count toward the container memory limit?

Yes. On cgroup v2, memory.current includes page cache as well as anonymous memory, so file-heavy workloads report usage well above their RSS. Clean cache is reclaimed before the OOM killer runs, so it rarely causes kills by itself, but dirty pages, tmpfs and memory-backed emptyDir volumes are charged and harder to reclaim. Check anon versus file in memory.stat.

Limits look like simple numbers and aren't. Knowing the kernel side turns "weird slowness" into "the cgroup spent its quota 6 ms into the period and sat throttled for 94."

Sources

Explore topics:LinuxKubernetes
React
Share this post
Cite this article
Plain text

Kiril Urbonas (2026). Container Resource Limits: What They Actually Do at the Kernel Level. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/container-resource-limits-what-they-actually-do

Markdown

[Container Resource Limits: What They Actually Do at the Kernel Level](https://www.devopsness.com/blog/container-resource-limits-what-they-actually-do) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)

KU

Kiril Urbonas

Founder & Chief Editor

607 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.