$ cat proxmox-containers-get-killed-by-the-oom-killer-while-the-ho.md
Proxmox Containers Get Killed by the OOM Killer While the Host Has Free RAM: Reading memory.max and memory.swap.max
A container’s main service vanishes at 3 a.m. The Proxmox summary graph shows the host at 40% RAM. Nothing in the host’s syslog looks alarming, and the container itself is still running. Only the database inside it is gone.
That is a cgroup OOM kill. The host had plenty of memory. The container hit its own ceiling.
Confirm it was the OOM killer
Check the host kernel log, not the container’s:
journalctl -k --since "yesterday" | grep -i -E "oom|killed process"
A cgroup kill looks like this:
Memory cgroup out of memory: Killed process 4121 (mariadbd) ...
oom-kill:constraint=CONSTRAINT_MEMCG,... oom_memcg=/lxc/105
CONSTRAINT_MEMCG is the tell. A host-wide OOM says CONSTRAINT_NONE. The oom_memcg=/lxc/105 part names the container by its VMID. Inside the container, dmesg is usually empty or blocked, which is why people miss this.
Where the limit lives
The memory value in the container config becomes a cgroup v2 limit on the host. Read it directly:
cat /sys/fs/cgroup/lxc/105/memory.max
cat /sys/fs/cgroup/lxc/105/memory.current
cat /sys/fs/cgroup/lxc/105/memory.swap.max
cat /sys/fs/cgroup/lxc/105/memory.events
memory.max is in bytes. memory.events is the useful one. A nonzero oom_kill counter confirms the container has been killed from inside, and a high max counter shows how often it brushed the limit before anything died.
Some setups lay the cgroup out differently, for example under /sys/fs/cgroup/lxc.payload.105. Run find /sys/fs/cgroup -maxdepth 2 -name "*105*" if the path above doesn’t exist.
Page cache counts, but it isn’t the culprit
memory.current includes file cache. A container reading a lot of data will show usage near its limit even when the applications are small. The kernel reclaims cache before it kills anything, so a full-looking number alone is not a problem.
The kill happens when reclaim can’t free enough. Check memory.stat and compare anon (application memory, which can only be freed by swapping) with file (cache, which can be dropped):
grep -E "^(anon|file|shmem) " /sys/fs/cgroup/lxc/105/memory.stat
If anon is close to memory.max, the apps really do need more RAM. If file dominates and you still got killed, look at shmem. tmpfs mounts and shared memory can’t be dropped like ordinary cache, and they count against the container. A /tmp or /dev/shm full of data is a classic hidden consumer.
Swap is its own limit
The container’s swap setting becomes memory.swap.max. The default in Proxmox for a new container is 512 MiB of swap. If you set it to 0, any spike beyond RAM goes straight to a kill. If it is set and the host has no swap or has swap disabled, the setting does nothing useful.
Two things to check:
swapon --showon the host. No swap device means the container’s swap value is decoration.- Whether the host swappiness and the ZFS or zram setup make swapping painfully slow. Swap that thrashes can be worse than a clean kill, because the service stays up but unusable.
Which process gets picked
Within the cgroup, the kernel scores processes by memory use, adjusted by oom_score_adj. The biggest process usually loses, and on a typical app server that is the database. You can protect it, with the caveat that something else then gets killed instead:
systemctl edit mariadb
[Service]
OOMScoreAdjust=-500
That only changes the order of victims. If the container is genuinely too small, protecting one process just moves the kill to another.
Fixing it properly
Raise the limit if the working set needs it:
pct set 105 --memory 4096 --swap 1024
The new value applies to the running container immediately for memory, with no reboot. Verify by reading memory.max again.
If the usage is a leak, a higher limit only delays the kill. Watch memory.current over a few days. A staircase that never drops back after load subsides points at the application. A sawtooth that tracks activity points at undersized limits or cache.
To catch it before 3 a.m., alert on the memory.events counters instead of on host RAM. A small cron job or a node exporter textfile that reports oom_kill per container lets you see the first kill rather than the fifth. The host-level graph will never show it, because from the host’s point of view nothing went wrong.