On Thu, Apr 02, 2020 at 04:30:33PM +0200, Igor Mammedov wrote: > 1. why xen uses memory_region_init_ram() which does not allocate anything
This seems to be due to history. > can it use plain memory_region_init() instead? I can give it a try. And it doesn't work, I had to call qemu_ram_alloc() as well, to set ram_memory.ram_block. On the other and, I think memory_region_init_ram_nomigrate() would be enough. QEMU didn't complain when I migrated the guest. > 2. how main ram is allocated? It's done by the toolstack, libxl. It creates a new domain in the hypervisor, memory allocation is part of this, then QEMU is started, for emulation of some devices. There is one thing that QEMU does in regards to memory, it's the call xc_domain_populate_physmap_exact() in xen_ram_alloc(). This is for when an emulated PCI device needs some memory, like for the VGA region. > 3. code has > /* > > * Xen does not allocate the memory continuously, it keeps a > > * hole of the size computed above or passed in. > > */ > > block_len = (1ULL << 32) + x86ms->above_4g_mem_size; > which fixes up size ram memory region > can we allocate 1 memory region of ram_size and then > alias lower and upper memory instead of that? I don't know, I don't think I know enough about how memory_region are used to be able to answer that. > 4. how RAM migration works in case of xen? >From QEMU, we only migrate devices states, we call the "xen-save-devices-state" QMP command. Memory migration is done by the toolstack. In QEMU, there is a bodge in xen_ram_alloc() to avoid having QEMU doing some "allocation" during migration. I hope that help. Cheers, -- Anthony PERARD