8000 A QEMU guest never gives its memory back · Issue #376 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

A QEMU guest never gives its memory back #376

Closed

Description

@Lillecarl

A QEMU guest's RAM is a memory-backend-memfd the host allocates lazily, so a guest that has just booted costs almost nothing however large boot.uml.memory is. Measured on nixkube's node guest at -m 14336M: 3.5 GB resident while it was still importing images, and 8.5s to boot.

That is the good half. The other half is that a Linux guest fills the rest of its RAM with page cache and never returns it, and the host pays for every page the guest has ever touched, for as long as the guest runs. A long test therefore drifts towards its full memory whatever it is actually using.

Why it matters now: nix run --file . umlTest.qemu.run is a CI job, and a GitHub-hosted x64 runner has 16 GB. The nixkube guest asks for 14 of them. Nothing has been killed for memory yet -- the nine-scenario run takes 13.4 minutes, which may simply be too short to reach the ceiling -- but the margin is two gigabytes for the host, virtiofsd, passt, the nix daemon and the runner agent, and the failure mode when it goes is the runner losing communication rather than a test failing.

Three options, in the order I would try them:

virtio-balloon with free page reporting. -device virtio-balloon-pci,free-page-reporting=on and CONFIG_BALLOON_COMPACTION. The guest then tells the host which pages it has freed and the host madvises them away, so page cache that is dropped stops costing anything. This is the one that actually fixes the mechanism rather than working around it. Needs checking against memory-backend-memfd with share=on, which is not the usual balloon setup -- vhost-user-fs requires that backend, so the two have to coexist.

A smaller number. One line, and it gives up the headroom the larger guest was for.

Cap the guest's page cache instead. Possible from inside with cgroup limits on the workload, but it treats a symptom and every test would have to opt in.

No measurement yet of how fast the drift actually is, and that is the first thing to get: run one guest at -m 14336M for an hour doing repeated store reads and plot RSS. If it plateaus well below the ceiling this is not urgent; if it tracks the ceiling, the balloon is worth the work before more tests move to QEMU.

Related: the sizing comment in nixkube's nix/uml/default.nix says to lower memory first if a run is killed for memory rather than failing, which is the stopgap until this is answered.

Activity

  1. added
    source: vivarium
    on Oct 19, 2026
  2. transferred this issue fromnixidae/vivariumon Oct 19, 2026
  3. added theissue type on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source: vivarium

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0