On Mon, Aug 20, 2018 at 01:40:21PM +0200, Paolo Bonzini wrote: > On 20/08/2018 12:30, Peter Xu wrote: > >>> + > >>> + /* > >>> + * The default size is (slightly) not enough to put the page > >>> + * tables for the dirty logging memory region. Extend it > >>> + * depending on how big a region we're testing upon > >>> + */ > >>> + mem_size = DEFAULT_GUEST_PHY_PAGES + TEST_MEM_PAGES / 512 * 2; > >> Hmm, now I see why you need the argument; I thought you were just adding > >> more memory for the test pages there but you are (correctly) using a > >> separate memory slot. If it's about the page tables, maybe you could > >> pass TEST_MEM_PAGES to vm_create_default and then do the computation in > >> vm_create_default? (Therefore scrapping my suggestion in patch 4/5). > > This computation totally comes from the requirement for bigger page > > tables (e.g., 4K page contains 512 page entries on 64bit x86 hosts), > > Yes, exactly. So if you pass TEST_MEM_PAGES (number of pages that will > be virt_mapped outside vm_create_default) to vm_create_default, or 0 for > other tests, it can compute the amount of memory that you need for the > page tables. You can choose whether to use *2 for virt_mapping to 1G > pages, or *4 for virt_mapping 4KB pages. For example > > mem_size = DEFAULT_GUEST_PHY_PAGES + extra_mapped_pages / 512 * 4; > > > I'm just afraid that people might need to expand that for other > > reasons. One thing I can think of is when the ELF is too big to be > > put into the VM memory due to some reason, then the VM memory size > > will depend on something else rather than the size of page tables. > > That can be covered by increasing DEFAULT_GUEST_PHY_PAGES, by loading > the ELF file before you compute the number, or ultimately by splitting > the test to a separate executable. I'll take the suggestion and pass in "extra mem size", then do the page table calculation for 4k page only (since we don't yet support huge pages, and even if we support it, 4k page table is still the biggest hence it will also be big enough if huge page is used). Thanks! -- Peter Xu