Repository navigation
Description
The UML half of #376, with the measurement that issue asks for.
Guest RAM is a file. UML's "physical" memory is an unlinked file it mmaps MAP_SHARED. It is sparse, so a large mem= costs nothing until the guest touches it -- and it only ever grows, because nothing punches holes in it.
Measured, one guest at mem=1024M reading 563 MiB of store paths over hostfs:
guest Cached |
79 MB -> 658 MB |
| host blocks allocated to that guest's RAM file | 717 MiB |
host page cache of the same three files, by mincore |
563 of 563 MiB |
The host pays about 1126 MiB to read 563 MiB once: its own page cache, and the guest's copy inside the guest's RAM file. Neither half comes back while the guest runs.
The second copy buys less here than on KVM. A guest page-cache miss on hostfs is a host read() that hits the host's page cache -- a memcpy, not disk I/O. Same guest, same file, host cache hot:
- guest cache miss: 1.3-1.5 GB/s
- guest cache hit: 5.1-6.5 GB/s
So a smaller mem= costs a 4x slower re-read at memory speed, not a disk seek. That is a much cheaper trade than #376's QEMU case, and it makes right-sizing mem= a real lever on its own.
Nothing removes the copy. hostfs is generic_file_read_iter plus read_folio: no DAX, no O_DIRECT, no mapping of the host's own pages. ubd's flags are r s d c t, where s is O_SYNC; there is no O_DIRECT there either. Removing the copy means teaching hostfs to map the host's pages, which is upstream work.
Giving the memory back is possible today, in one of two shapes.
- mconsole's
memdevice.config mem=-256Mallocates guest pages andMADV_REMOVEs them from the RAM file -- UML's own balloon. NeedsCONFIG_MCONSOLE(allnoconfig leaves it off),uml_dir=andumid=, and a client, which isstruct.packon a datagram socket. Two limits:mem_configallocatesGFP_ATOMICand stops at the first failure, so it only takes pages that are already free -- drop the guest's caches first -- andmem=+Ncannot go above the bootmem=. - A
page_reportingconsumer.CONFIG_PAGE_REPORTINGis generic mm. A UML driver that registers areportcallback callingos_drop_memoryshrinks continuously with no host orchestration, and growing back is free because the file is sparse. A kernel patch carried inpkgs/uml-kernel.
virtio-balloon does not apply: virtio_uml is a vhost-user transport, and there is no balloon backend to speak to.
Fixed separately while measuring this: every sandboxed guest's RAM file landed on the builder's disk, because Nix sets TMPDIR=/build and UML takes it with only a warning.
Assisted-By: Opus 5
Activity
feat(uml-runner): let a guest give its memory back
Lillecarl commentedon Sep 21, 2026
The mconsole half is landed: user-mode-nixos
04d7d96b 8000 code>, locked by nixidae61e4641a.CONFIG_MCONSOLE=y,uml_dir=/umid=on the kernel line, a struct.pack client inuml_runner, andMachine.drop_caches/shrink/grow/meminfo/host_memory_kib.tests/memory.pyis the check, and it is inchecks.Measured by that test, one guest at
mem=1024Mreading its own 362 MiB closure:Cacheddrop_cachesshrink("256M")Still open here: the
page_reportingdriver, which is what makes this automatic instead of a knob a test has to call. Filed separately.Assisted-By: Opus 5
Lillecarl commentedon Sep 21, 2026
Both runners now, and both mechanisms. user-mode-nixos
48bef443, locked by nixidae0125c92c.memory.pyruns on both backends and cannot tell which it is on. One guest atmemory = "1024M"reading its own 362 MiB closure and dropping its cache:Answering the original question directly:
mincoreon one side and the guest's RAM file on the other. hostfs isgeneric_file_read_iter+read_folio: no DAX, noO_DIRECT, no mapping of the host's pages. Removing it means teaching hostfs to map them, which is upstream work nobody has started.read()that hits the host's own cache — 1.3-1.5 GB/s against 5.1-6.5 GB/s for a hit. A memcpy, not a seek. So a smallermemoryis a cheap lever under UML in a way it is not under QEMU.madvise(MADV_REMOVE)under UML (pynixd: detect the builder-rpc-v0 feature so a remote store can present it #13, a patch inpkgs/uml-kernel),virtio-balloon-pci,free-page-reporting=onunder QEMU (Move to one repository with josh exports, the way pyterm did #4).vm.shrink()/vm.grow().Nothing left open here. #506 and #376 carry the two halves.
Assisted-By: Opus 5
Lillecarl commentedon Nov 3, 2026
Why the krun answer, a DAX window, does not reach UML today. Read in linux-7.2.9's Kconfig against the
umlKernelconfig (2026-11-03):FUSE_DAX(virtio-fs DAX, what krun uses) depends onVIRTIO_FS,FS_DAXandDAX(fs/fuse/Kconfig:43).FS_DAXdepends onZONE_DEVICE(fs/Kconfig:58), andZONE_DEVICEdepends onMEMORY_HOTPLUG,MEMORY_HOTREMOVEandSPARSEMEM_VMEMMAP(mm/Kconfig:1236).arch/um/Kconfigselects neitherARCH_SPARSEMEM_ENABLEnorARCH_ENABLE_MEMORY_HOTPLUG. So UML is FLATMEM, and none of those options appear inumlKernel's config at all.VIRTIO_UMLdrives virtio devices over vhost-user (arch/um/drivers/Kconfig:142), so virtio-fs with virtiofsd would load. It would not get DAX.So DAX on UML first needs SPARSEMEM_VMEMMAP and memory hotplug in arch/um. That is arch work, not a config change. The other route is the one this issue names: hostfs that maps the host's page-cache pages on a fault. UML's MMU is built on host
mmap, so that may cost less than porting ZONE_DEVICE. Neither is measured.For reference, the krun numbers this would aim at: 3-node k8s on dynhetz, peak host PSS of the guest processes 2250 MiB on krun against 3347 MiB on QEMU.
Assisted-By: Claude Opus 5.5
Lillecarl commentedon Nov 17, 2026
User wants this for UML when the time is right (2026-11-17): something that works like krun's virtio-fs DAX window, so a UML guest reads the store from the host's page cache and keeps no copy of its own.
The two routes in the comment above still stand:
Measure route 1 first.
Assisted-By: Claude Opus 5.5