The Architectural Flaw of cgroups v1
- Memory Controller: Tracked anonymous and page cache allocations.
- BlkIO Controller: Tracked block device I/O requests.
blkio.weight.
cgroups v1 (Fragmented):
/sys/fs/cgroup/memory/user-1001/
/sys/fs/cgroup/cpu/user-1001/
/sys/fs/cgroup/blkio/user-1001/ <-- No coordination between memory & I/O
cgroups v2 (Unified):
/sys/fs/cgroup/hosting.slice/user-1001/
├── cgroup.controllers (cpu memory io pids)
├── memory.max
├── io.weight
└── cpu.weight1. Unified Hierarchy and Memory Writeback
io controller throttles the specific cgroup rather than slowing down other tenants.
Key controllers in production include:
| Attribute | Function | Hosting Use Case |
|---|---|---|
memory.min | Hard memory reservation (never reclaimed) | Protect system-critical services (SSH, DNS) |
memory.low | Soft memory protection (reclaimed only under pressure) | Prevent cold-start latency on active tenant pools |
memory.high | Throttle limit before hard OOM | Gently slows down misbehaving PHP workers |
memory.max | Hard limit (OOM killer invoked if breached) | Prevents runaway memory leaks |
2. Implementing Systemd Slices for Web Hosting
systemd slices provides a reliable mechanism to isolate user worker pools without manual script orchestration:
# /etc/systemd/system/hosting-user.slice
[Unit]
Description=Isolated Slice for Hosting Tenant
DefaultDependencies=no
[Slice]
CPUAccounting=yes
MemoryAccounting=yes
IOAccounting=yes
# Limits
CPUQuota=200%
MemoryHigh=1024M
MemoryMax=1536M
IOWeight=100
TasksMax=256systemctl daemon-reload
systemctl set-property hosting-user.slice MemoryHigh=1024M MemoryMax=1536MSummary for Systems Administrators
/proc/pressure/), infrastructure teams can guarantee sub-millisecond response times for stable tenants while automatically throttling resource spikes before they escalate into node-wide outages.