free -m inside the container shows swap usage climbing fast. The application feels sluggish, maybe processes restart without explanation. The confusion is common: KVM and LXC handle memory limits through completely different mechanisms, and a straight number-for-number migration often leaves the container with a swap allowance you never intended.
How KVM and LXC Memory Limits Differ
si/so in vmstat, latency spikes, and mysterious slowdowns.
If your KVM VM had no swap partition (or a small one), and the replacement LXC container suddenly has gigabytes of swap courtesy of cgroup defaults, the behavior difference is dramatic.
Step 1: Check What Proxmox Actually Configured
CTID with your container ID:
BASH
pct config CTID | grep -E 'memory|swap'TEXT
memory: 2048
swap: 2048swap is missing from the output, Proxmox may be using its default (which is typically equal to the memory value — verify this against your Proxmox version's documentation). If you see swap: 2048 and you did not want swap, that is your problem right there.
To set swap to zero from the host:
BASH
pct set CTID -swap 0Step 2: Verify Effective Cgroup Limits on the Host
/sys/fs/cgroup. The exact path depends on your Proxmox version and cgroup hierarchy. For cgroup v2, it typically looks like:
BASH
# Memory limit in bytes
cat /sys/fs/cgroup/lxc/CTID/memory.max
# Swap limit in bytes
cat /sys/fs/cgroup/lxc/CTID/memory.swap.max
# Current memory usage
cat /sys/fs/cgroup/lxc/CTID/memory.current
# Current swap usage
cat /sys/fs/cgroup/lxc/CTID/memory.swap.currentmemory.swap.max shows a large number (or max, meaning unlimited), the container can swap as much as the host allows. That is almost never what you want for a production workload that was previously running in a fixed-RAM KVM VM.
On older Proxmox installations still using cgroup v1, the paths differ: look under /sys/fs/cgroup/memory/lxc/CTID/ for files like memory.limit_in_bytes, memory.memsw.limit_in_bytes, and memory.usage_in_bytes. The memsw file controls memory+swap combined, not swap alone, which is another source of confusion.
If you are unsure whether your host uses cgroup v1 or v2, check:
BASH
mount | grep cgroupcgroup2 indicate v2. Lines with cgroup and specific controller names (memory, cpu) indicate v1.
Step 3: Look for Silent OOM Kills
BASH
cat /sys/fs/cgroup/lxc/CTID/memory.eventsTEXT
low 0
high 0
max 312
oom 4
oom_kill 4
oom_group_kill 0oom_kill counter shows how many times the OOM killer fired inside this container's cgroup. If that number is non-zero, processes have been killed. This counter persists until the container restarts.
You can also check dmesg on the host for OOM messages:
BASH
dmesg | grep -i 'out of memory\|oom-killer\|killed process' | tail -20Step 4: Measure Current Memory Pressure
free -m gives you the basics, but vmstat 1 5 is more useful for spotting active swapping:
BASH
vmstat 1 5si (swap in) and so (swap out) columns. Non-zero so values mean the kernel is actively pushing pages to swap right now. Non-zero si means it is pulling them back. Sustained non-zero values in both columns indicate thrashing — the system is spending more time moving pages than doing useful work.
For a related deep-dive on interpreting vmstat swap columns before deciding to upgrade, see Why Your App Uses More RAM After Moving a VPS from OpenVZ to KVM, which covers a similar class of memory-behavior surprises after migration.
On cgroup v2, there is also a memory.pressure file that shows PSI (Pressure Stall Information) metrics:
BASH
cat /sys/fs/cgroup/lxc/CTID/memory.pressureTEXT
some avg10=45.32 avg60=38.10 avg300=22.50 total=198273645
full avg10=12.05 avg60=9.88 avg300=5.42 total=52738291some line shows the percentage of time at least one task was stalled waiting for memory. The full line shows when all tasks were stalled. If avg10 on the full line is above single digits, the container is under serious memory pressure right now.
Step 5: Right-Size the Limits
-
If the workload ran fine in a KVM VM with no swap, set
swap: 0in the LXC config and give it the same RAM amount (or slightly more, since the container shares the host kernel and some overhead differs). - If you want a small swap buffer for occasional spikes, set swap to a fraction of memory (an illustrative example: 256 MB swap for a 2048 MB container) rather than accepting the default 1:1 ratio.
-
After changing limits, restart the container and re-run the verification steps above. Confirm
memory.swap.maxin the cgroup filesystem matches your intent,oom_killcounter is zero, andvmstatshows no sustained swap activity.
free -m on the Proxmox node itself.
The Short Version
memory.events, and set swap explicitly to what you actually want. The five minutes of verification saves hours of debugging mysterious process restarts.