109. Proxmox LXC reclaims cold page cache from idle containers through cgroup memory.reclaim
Status: Accepted
Date: 2026-11-28
Context
On a Proxmox node with many running LXC containers, idle containers keep gigabytes of cold file-backed page cache. Under memory pressure, especially when one NUMA node runs short of free memory, Linux global reclaim evicts file pages across cgroups in proportion to their cache size rather than sparing busy containers. Busy containers then stall in direct reclaim and repeatedly refault their hot working set, while idle containers hold cold cache they no longer need.
BB Box reaches Proxmox only through its pool-scoped API token and has no root access on the Proxmox host. We tested what an unprivileged LXC container’s own root (sudo) can trigger from inside:
/proc/sys/vm/drop_cachesis mounted read-only inside unprivileged containers (Read-only file system, exit 2) and cannot be used./sys/fs/cgroup/memory.reclaimis writable by container root (-rw-rw-r-- nobody root, mapped to the container’slxc/<vmid>/nscgroup v2) and accepts<bytes> swappiness=0on Linux 6.11 and later (including Proxmox VE 9’s Linux 6.17 kernel). Writing<bytes> swappiness=0frees file-backed page cache while leavinganon,shmemandmemory.swap.currentuntouched. Withoutswappiness=0, plain<bytes>can swap anonymous pages even while cold file cache is present.- In
memory.stat,fileincludesshmem(tmpfs and/dev/shm), whichswappiness=0cannot reclaim, andactive_fileholds hot pages such as mapped binaries and libraries. Reclaiming blindly fromfilecan strip real page cache and hot pages down to a few megabytes whenshmemoractive_fileis large. - Proxmox’s
/nodes/{node}/lxccpufield is a point sample over the interval since thepvedaemonworker last listed guests (and reads 0 on a fresh worker’s first call), so it is suitable only as a cheap pre-filter, not as proof that a container was idle across the whole window.
Decision
Proxmox LXC runs an idle page cache sweep (src/backends/proxmox-lxc/idle-cache.ts) inside its existing upkeep loop (ProxmoxLxcBackend.maintain(), run by the 3-minute sweep and throttled to at most once a minute), after warm pool top-ups (#topUp).
- Settings (on by default): Proxmox LXC adds two advanced settings:
idle-cache-reclaim(boolean, defaulttrue) andidle-cache-minutes(whole number from1to1440, default15). - Scope (no warm boxes or spares): the sweep considers only this install’s running, in-range containers and skips templates, warm boxes (
warmtag), spares (thread.spare), filling, acquiring, reserved, image and retired containers. Warm boxes and spares stay warm so they are handed over with their page cache intact. Claiming a warm box (hold) or relabelling a spare (relabel) resets the container’s idle tracker so a freshly claimed box starts a full idle window. - Idle detection (
cpu.statauthority with Proxmox pre-filter): each sweep reads running containers in one Proxmox API call (GET /nodes/{node}/lxc) and skips any container whoseuptimeis underidle-cache-minutes, whose Proxmoxcpuexceeds 5% (resetting its baseline), that is inside its per-box cooldown (idle-cache-minutes), or whose reported memory is at or below 192MiB. An eligible container’s first visit reads/sys/fs/cgroup/cpu.statusage_usecwithoutsudoand reclaims nothing. Only on a later visit, after at leastidle-cache-minutessince that baseline, does BB Box run the reclaim script, which first checks that(usage_usec - prev_usage_usec)over the full elapsed window is at most 5% of the container’s cores. If CPU usage exceeded 5%, the box is marked busy and the baseline resets to the new sample. - Inactive-file-only, stepped
swappiness=0reclaim: the sweep visits at most one container at a time, capped at 3 containers and 20 seconds per sweep, using direct SSH (ConnectTimeout=2, skipping the 15-second lost-connection retry wait) and wrapping the in-box script intimeout(1)so a stalled run stops inside the container before the SSH timeout. Inside the container, the script checkssudo -n truefirst (reportingsudo_faileddistinctly from unanswered SSH), checksmemory.pressure(someavg10 or avg60 at least 1%, orfullavg10 or avg60 at least 0.5%), and probes0 swappiness=0on/sys/fs/cgroup/memory.reclaim(skipping kernels withoutswappiness=, such as Proxmox VE 8 on Linux 6.8). It computes the reclaim budget from inactive, non-shmem file pages only:min(inactive_file, file - shmem - 128 MiB), skipping if below 64MiB. It steps in 256MiB chunks (up to 32 steps), stopping immediately if swap grows,memory.pressurerises (someavg10 at least 1%,fullavg10 at least 0.5%,sometotal rises by 50ms or more, orfulltotal rises by 10ms or more),active_filefalls since the start of the run by more than 32MiB or 10% of its starting value (whichever is larger, allowing for normal multi-generation LRU drift while still protecting hot pages),workingset_refault_filerises by 1024 pages or more in a step,memory.reclaimreturnsEAGAIN, or non-shmem file cache falls by less than 16MiB. - Cooldown, logging, history and doctor: unanswered boxes get the same
idle-cache-minutescooldown as reclaimed boxes and give up quietly without stopping the rest of the sweep. Each container whose cache is freed is logged with the estimated non-shmem file bytes reclaimed, before and after figures, step count and stop reason. Only sweeps that checked at least one box are stored (keeping the last 10 in backend storage) and reported bybb box doctorunderproxmox.idle-cache(“Idle page cache”), which warns when every checked container across recent sweeps failedsudo, was unsupported or did not answer.
Consequences
- Idle Proxmox LXC containers return cold inactive page cache above 128MiB back to the host without host-side root helpers or extra Proxmox API privileges, while preserving
shmem,active_file, warm boxes, spares, anonymous memory and swap. - Bursty workloads that spike CPU between 3-minute sweeps are caught by
cpu.statusage_usecacross the full idle window and are not reclaimed mid-task. - Unanswered boxes fail fast without stalling warm pool top-ups or retrying on every sweep, and sweeps after a BB restart stagger across 3 boxes per sweep.
- Operators on Proxmox VE 8 (Linux 6.8) see containers safely skipped and a warning in
bb box doctorsuggesting turningidle-cache-reclaimoff on older hosts.