Stop letting your container processes lose their mind when they hit memory limits
Container Basics On Linux (Namespaces/Cgroups)
Stop letting your container processes lose their mind when they hit memory limits
🧩 The Challenge
Dealing with a container that silently OOM-kills itself instead of just slowing down is a nightmare when you’re on-call at 2 AM. You look at the metrics and everything seems fine until you realize the cgroup controller is just nuking your process without telling you why.
💡 The Fix
Setting a soft limit alongside your hard limit helps the kernel try to reclaim memory before it panics and fires the OOM killer at your app. It gives your application a fighting chance to stay alive under pressure.
echo 512M > /sys/fs/cgroup/memory/my_container/memory.soft_limit_in_bytes
echo 1G > /sys/fs/cgroup/memory/my_container/memory.limit_in_bytes
⚙️ Why It Works
This works because the kernel treats the soft limit as a suggestion to aggressively reclaim pages when memory gets tight, rather than just hitting the hard wall. Under heavy load, the process will see increased latency but won’t get sent the SIGKILL signal immediately.
🚀 Pro-Tip: Always keep an eye on memory.stat inside the cgroup folder to see how many times you’ve actually triggered that reclaim cycle.
Linux Tips & Tricks | © ngelinux.com | 11/29/2026
