# 107. Proxmox QEMU boxes enable the virtio balloon device

Status: Accepted  
Date: 2026-11-27

## Context

`setup/proxmox-qemu/build.sh` and `setup/proxmox-qemu/build-linux.sh` created QEMU templates with `--balloon 0`, and clones inherited `balloon: 0`. Without a virtio balloon device, a running VM cannot return unused RAM to the host. Windows touches all of its configured RAM during boot, so an idle 32 GiB Windows box held gigabytes of resident host memory and host swap even while Windows itself used only a few gigabytes.

Proxmox VE's `qemu-server` (since 7.2-1, commit `c70e4ec397`, across all Proxmox VE 7.2, 8.x and 9.x releases) attaches `virtio-balloon-pci,id=balloon0,...,free-page-reporting=on` whenever `balloon` is unset or non-zero and the QEMU machine version is at least `6.2` (`--machine q35` resolves to the host's QEMU version).

How Proxmox drives a configured `balloon` floor differs sharply from free page reporting:

- **Cold start at the floor:** on every start without a saved state (`QemuServer.pm` lines 5919 to 5920: `mon_cmd($vmid, "balloon", value => $conf->{balloon} * 1024 * 1024) if !$statefile && $conf->{balloon}`), Proxmox immediately sets the VM's balloon target to the configured `balloon` value. A box configured with a 50% floor cold-boots at half its memory (for example 16 GiB usable on a 32 GiB box, or 4 GiB on an 8 GiB box), and a warm VM that hibernates soon after boot is claimed still near the floor.
- **Slow ramp-up only under 80% host use:** `pvestatd` (`PVE/Service/pvestatd.pm`, `PVE::AutoBalloon::compute_alg1`) computes host memory use as total minus `MemAvailable` (which on a ZFS host can stay high with ARC). Only while host use is under `ballooning-target` (80% by default) does `pvestatd` grow a VM's balloon back toward `maxmem`, at most 100 MiB per VM per 10-second cycle (about 27 minutes to restore 16 GiB). On a host sitting above 80%, a cold-booted box stays at its floor.
- **Shrinking above 80% includes busy boxes:** when host memory use exceeds 80%, `compute_alg1` shrinks VMs with `freemem > balloon_min * 0.25` first, and if that does not meet the goal, falls through to every ballooned VM. Even a busy Windows box can therefore be shrunk by 100 MiB per cycle down to its floor, and `balloon.sys` does not deflate on guest memory pressure.
- **Monitor API privilege for resetting after cold start:** resetting a cold-booted VM's balloon target back to full memory via `POST /nodes/{node}/qemu/{vmid}/monitor` (`balloon <MiB>`) requires `Sys.Modify` on `/` (`PVE/API2/Qemu/HMPPerms.pm`: `balloon => 'Sys.Modify'`). BB Box's pool-scoped API token (`setup-token.sh`: `VM.*` and `Pool.Audit` on the pool, plus `Sys.Audit` on the node) deliberately does not hold `Sys.Modify` on `/`. Doing that in a later change would require either granting `Sys.Modify` on `/` or a root host helper.

Guest support also differs between Linux and Windows:

- **Linux VMs (Ubuntu 24.04):** the pinned Ubuntu 24.04 cloud image (`linux-image-6.8.0-139-generic`, `linux-image-virtual`) builds `CONFIG_VIRTIO_BALLOON=y`, `CONFIG_MEMORY_BALLOON=y` and `CONFIG_PAGE_REPORTING=y` into the kernel. Linux kernels 5.7 and later implement `VIRTIO_BALLOON_F_REPORTING`, so a Linux VM with `balloon` equal to `memory` returns large free page blocks to the host through free page reporting without auto-ballooning (page cache stays in the guest until reclaimed).
- **Windows VMs:** `setup/proxmox-qemu/answer/bb-box/firstlogon.ps1` runs `virtio-win-gt-x64.msi /qn /norestart`, which installs `FE_balloon_driver` (`balloon.inf`, `balloon.cat`, `balloon.sys` staged into the Windows Driver Store via `SetupCopyOEMInf`) and `BalloonService` (`blnsvr.exe`, automatic start). Existing Windows templates built with `--balloon 0` therefore bind `balloon.sys` at boot with no rebuild. However, upstream `virtio-win/kvm-guest-drivers-windows` (`master` as of November 2026) negotiates only `VIRTIO_BALLOON_F_STATS_VQ` and classic balloon inflate and deflate (`BalloonFill` and `BalloonLeak`), and does not yet implement `VIRTIO_BALLOON_F_REPORTING` (upstream issue 899; PR 1657 remains open). Windows therefore does not give unused memory back on its own today.

## Decision

- **Linux VMs (`linux` and `linux-desktop-cpu`):** BB Box sets `balloon` equal to `memory` (in MiB) whenever it configures a Linux VM's size: on acquire, resize (taking the kind from the method's `kind` argument, including rollbacks), fork, image build or trial boxes, and template capture. `setup/proxmox-qemu/build-linux.sh` creates new `linux` and `linux-desktop` templates with `--balloon` equal to `--memory` (16384 MiB during build, then 4096 MiB for `linux` and 8192 MiB for `linux-desktop` before templating). Auto-ballooning never shrinks Linux VMs; free page reporting returns large free page blocks to the host.
- **Windows VMs (`windows-desktop`):** Proxmox QEMU adds an advanced setting `windows-balloon-min-percent` with default `100` (whole numbers from `25` to `100`). At the default of `100`, `balloon` equals `memory`: every Windows box cold-boots at full memory with auto-ballooning off, `virtio-balloon-pci` and `free-page-reporting=on` ready, and `BalloonService` reporting real guest memory to Proxmox. Operators who accept the cold-boot-at-floor and busy-shrink trade-offs can lower the setting (25 to 99); BB Box then sets `balloon` to `round(memory * windows-balloon-min-percent / 100)` MiB (clamped between 1 and `memory`) on acquire, warm pool fill, resize (including rollbacks) and image boxes. `setup/proxmox-qemu/build.sh` and template capture (`#capture`) always write templates with `balloon` equal to `memory`.
- **Android VMs (`android`):** unchanged (`balloon: 0` in `build-linux.sh` and omitted by BB Box).
- **Start gate (`src/backends/proxmox/start-gate.ts`):** extends decision 106 with no code changes. Ballooned Linux VMs no longer have `balloon` off, so they do not count as heavy (they allocate memory lazily and do not zero all RAM at boot). Windows VMs remain heavy by OS (`windows`), kind (`windows-desktop`) and `ostype` (`win*`), and Android remains heavy by kind. Admission continues to check each guest's full configured `memory`, never a lower balloon floor.
- **Existing guests and hibernated warm VMs:** boxes and warm VMs made before this change keep `balloon: 0` until they are made again. Claiming a hibernated warm VM resumes it first and never changes its hardware configuration before resume.

## Consequences

- Linux VMs on Proxmox QEMU return large free page blocks to the host through `free-page-reporting=on` with no change to guest-visible memory and no heavy start settle delay, while page cache stays until reclaimed.
- At the default `windows-balloon-min-percent` of `100`, Windows boxes cold-boot at full memory and report guest memory usage to Proxmox through `BalloonService`, but do not return idle RAM to the host on their own until upstream `virtio-win` ships free page reporting (PR 1657).
- When an operator lowers `windows-balloon-min-percent` below `100`, cold-booted Windows boxes start at that floor and grow back toward full memory only while host memory use is under 80% (at most 100 MiB per 10-second cycle); above 80%, Proxmox can shrink even a busy Windows box to its floor. Inside Windows, `balloon.sys` locks inflated pages via `MmAllocatePagesForMdlEx`, so Task Manager still shows full installed RAM while "In use" rises and "Available" RAM falls by the inflated amount.
- Proxmox rejects a VM config where non-zero `balloon` exceeds `memory`, so resize and capture always update `memory` and `balloon` together.
- A later change to start lower-floor Windows boxes at full memory would need to reset the balloon target after each cold start (which requires `Sys.Modify` on `/` for Proxmox's monitor endpoint, or a host helper), or wait for upstream `virtio-win` PR 1657.
