Resource limits

On this page 7

Resource limits are enforceable ceilings that an operating system or runtime places on how much CPU time, memory, disk I/O, processes and open files a process, user, service or container may consume. In the management of server resources, they turn a shared machine into a set of predictable allocations, so that one workload cannot starve every other workload on the same host.

Limits are the counterpart of capacity planning: planning decides how much a server has, while limits decide who may use how much of it. They protect stability, enforce hosting plans and contain faults such as memory leaks or runaway loops before they become outages.

How resource limits are enforced

On Linux, resource limits are enforced by two main kernel mechanisms. The older rlimit interface, set with setrlimit and the shell command ulimit, applies per-process limits such as the maximum number of open file descriptors, the stack size or the number of processes a user may own.

The newer mechanism is control groups, usually called cgroups, which group processes and apply limits to the whole group. With cgroups v2, the unified hierarchy used by modern distributions, controllers such as memory.max, cpu.max, io.max and pids.max govern an entire service or container rather than a single process.

Higher-level tools sit on top of these primitives. systemd exposes cgroup settings as unit directives, container runtimes translate flags such as memory and CPU options into cgroup values, and Kubernetes converts requests and limits in a pod specification into the same kernel controls.

LayerExample interfaceScope of the limit
rlimitulimit -n, /etc/security/limits.confSingle process or user session
cgroups v2memory.max, cpu.max, pids.maxGroup of processes
systemd unitsMemoryMax, CPUQuota, TasksMaxOne service and its children
ContainersDocker memory and CPU flagsOne container
OrchestratorsKubernetes requests and limitsPod or container in a cluster
Enforcement layers for resource limits

Types of resource limits and what happens at the ceiling

Each resource type reacts differently when its limit is reached, and this behavior determines how an application fails. CPU limits throttle a workload and make it slower, whereas memory limits terminate processes or force reclaim, which is far more disruptive.

The table below summarizes the main limit types, the usual unit and the typical consequence of hitting the ceiling.

ResourceTypical unitEffect when exceeded
CPUQuota per period, for example 50 ms per 100 msThrottling and higher latency
MemoryBytes, for example 2 GiBReclaim, then OOM kill
Disk I/OIOPS or bytes per secondRequests queue and I/O wait rises
ProcessesNumber of tasksfork fails with EAGAIN
Open filesNumber of descriptorsCalls fail with EMFILE
Disk spaceBytes or inodes via quotasWrites fail with EDQUOT
Limit types and their effects

Many limits distinguish a soft limit from a hard limit. With rlimits, a process may raise its soft limit up to the hard limit but cannot exceed the hard limit without privileges. In cgroups v2, memory.high acts as a throttling threshold that slows allocation, while memory.max is the absolute ceiling that triggers the out-of-memory killer.

Resource limits are often confused with neighboring ideas such as reservations, quotas and scheduling weights. The distinction matters because a limit is a ceiling, not a guarantee, and a server with generous limits can still be overloaded.

ConceptWhat it controlsGuarantee or ceiling
LimitMaximum consumptionCeiling
Request or reservationCapacity set aside for schedulingGuarantee
CPU weight or sharesRelative priority under contentionProportional share
Disk quotaStorage per user or projectCeiling
Memory overcommitTotal promised versus physical memoryNeither, a policy
Limits and related allocation concepts

Limits also interact with symptoms tracked elsewhere in server monitoring. A container that reaches its CPU quota shows CPU throttling even when the host has idle cores, and a virtual machine that loses time to other tenants shows CPU steal time, which no limit inside the guest can fix. Limits are the main defense against the noisy neighbor problem on shared hosts.

Setting resource limits in practice

Good limits are based on measured peak usage plus headroom, not on guesses. A common approach is to observe a workload under realistic load, take the 95th or 99th percentile of usage and add a margin of roughly 20 to 50 percent, depending on how bursty the workload is.

The following decision table shows typical situations and the limit strategy that usually suits them.

SituationRecommended approachReason
Shared web hostingPer-account CPU, memory and process capsKeeps one site from slowing others
Database serverGenerous memory limit, no tight CPU quotaThrottling hurts query latency
Batch jobsLow CPU weight, firm memory limitYields to interactive work
High-connection proxyRaised open file limitEach connection uses a descriptor
Latency-sensitive APIRequests equal to limitsAvoids throttling and eviction
Choosing a limit strategy

Configuration should live in version-controlled files, such as systemd drop-ins or container manifests, rather than in interactive shell sessions. A ulimit typed in a terminal affects only that session and disappears at the next login or service restart.

Common mistakes and failure modes

Most problems with resource limits come from limits that are too tight, too loose or applied at the wrong layer. Typical errors include:

  • Setting CPU limits too low for multithreaded applications, which causes heavy throttling during short bursts even when average usage looks modest.
  • Sizing memory limits to average usage, so that normal peaks trigger out-of-memory kills.
  • Editing limits.conf for a systemd service, which has no effect because systemd applies its own LimitNOFILE and related directives.
  • Ignoring runtime awareness, for example a Java or Node.js process that sizes its heap from host memory instead of the container limit.
  • Relying on limits instead of monitoring, so that silent throttling is never noticed.

Limits should therefore be paired with alerting on throttling counters, OOM events and limit utilization, so that operators adjust ceilings before users notice degraded performance.

The idea in brief

Resource limits work like portion sizes at a shared table. A server has a fixed amount of processing power, memory and storage, and many programs or customers want a share of it. Limits say how much each one may take.

If a program tries to take more, the system either slows it down or stops it. That may sound strict, but it protects everyone else on the same machine. The key point is that limits keep one misbehaving program from ruining the experience for all the others.

A practical scenario

A hosting provider runs about 200 small business websites on one server with 16 CPU cores and 64 GB of memory. One night, a poorly written plugin on a single site enters a loop and starts spawning PHP processes, each consuming memory.

Because the provider assigns every account a limit of one CPU core, 1 GB of memory and 40 processes, the runaway site hits its process ceiling within seconds. New requests to that site fail with errors, but the kernel never touches the memory of the other accounts, and the monitoring system raises an alert about repeated limit hits.

The administrator identifies the faulty plugin the next morning and disables it. The other 199 websites stayed fast throughout the incident, and nobody outside the affected account noticed any slowdown.