Hi, On Fri, Nov 25, 2022 at 10:43 AM Alexandru Elisei <alexandru.elisei@xxxxxxx> wrote: > > Hi, > > Did some digging, correction(s) below. > > On Thu, Nov 24, 2022 at 05:14:33PM +0000, Alexandru Elisei wrote: > > Hi, > > > > On Thu, Nov 24, 2022 at 03:19:34PM +0000, Fuad Tabba wrote: > > > [..] > > > kvmtool closer to a more consistent way of allocating guest memory, in > > > a similar manner to other VMMs. > > > > I would really appreciate pointing me to where qemu allocates memory using > > memfd when invoked with -m <size>. I was able to follow the hostmem-ram > > backend allocation function until g_malloc0(), but I couldn't find the > > implementation for that. > > As far as I can tell, qemu allocates memory without backing storage (so by > specifying only -m on the command line) like this: > > main -> qemu_init -> qmp_x_exit_preconfig -> qemu_init_board -> > create_default_memdev, which creates a TYPE_MEMORY_BACKEND_RAM object. > > When creating the VM ram, the object's alloc function is called in: > > create_default_memdev -> user_creatable_complete -> > host_memory_backend_complete) -> ram_backend_memory_alloc -> > memory_region_init_ram_flags_nomigrate -> qemu_ram_alloc -> > qemu_ram_alloc_internal -> ram_block_add -> qemu_anon_ram_alloc -> > qemu_ram_mmap(fd=-1,..) -> mmap_activate(..,fd=-1,..) -> > mmap(..,MAP_ANONYMOUS,fd=-1,..) > > Unless I'm mistaken with the above (it was quite convoluted to unwrap all > of this), qemu doesn't allocate RAM for the VM using a backing file, unless > specifically requested by the user. Thanks and sorry that you had to do some digging because of my mistake (thinking that the memfd backend was the default one). Cheers, /fuad > On the other hand. for crosvm: > > main -> crosvm_main -> run_vm -> run_config (from src/scrovm/sys/unix.rs), > creates the memory layout in GuestMemory::new -> > MemoryMappingBuilder::new -> from_shared_memory -> offset -> build. > > I couldn't find the implementation for MemoryMappingBuilder::build, if it's > anything like build_fixed, then indeed it looks like it uses the memfd > created with GuestMemory::create_shm and passed to > MemoryMappingBuild::from_shared_offset. > > Thanks, > Alex