Hands-on task
A report that eats memory: memory.max
On bad data the quarterly report /opt/report/build.py starts eating memory without limit. Last time the kernel's OOM killer picked not the report but the database on the same server as its victim. While the developers fix the script, restrict it with the kernel's own tools:
- Create a cgroup v2
report(a directory in/sys/fs/cgroup) with a memory limit of 64 MiB and forbid swap for the group. - Run
/opt/report/build.pyinside that group and make sure the kernel killed it inside the group — and the rest of the server didn't notice.
Don't run the script without a limit: on a production server it would eat all the memory. In the lab it has a safety fuse — outside a group with a small limit it stops by itself at 256 MiB, but then no OOM kill happens inside the group. cgroup v2 is mounted at /sys/fs/cgroup, and the controllers for child groups are already enabled.
- cgroups
- cgroup v2
- memory.max
- OOM killer