Re: [PATCH kvmtool v1 2/2] Align the calculated guest ram size to the host's page size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jul 17, 2023 at 11:23:00AM +0100, Fuad Tabba wrote:
> If host_ram_size() * RAM_SIZE_RATIO does not result in a value
> aligned to the host page size, it triggers an error in
> __kvm_set_memory_region(), called via the
> KVM_SET_USER_MEMORY_REGION ioctl, which requires the size to be
> page-aligned.
> 
> Fixes: 18bd8c3bd2a7 ("kvm tools: Don't use all of host RAM for guests by default")
> Signed-off-by: Fuad Tabba <tabba@xxxxxxxxxx>
> ---
>  builtin-run.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/builtin-run.c b/builtin-run.c
> index 2801735..ff8ba0b 100644
> --- a/builtin-run.c
> +++ b/builtin-run.c
> @@ -406,7 +406,7 @@ static u64 get_ram_size(int nr_cpus)
>  	if (ram_size > available)
>  		ram_size	= available;
>  
> -	return ram_size;
> +	return ALIGN(ram_size, host_page_size());
>  }

I guess we could avoid querying the page size twice if we also factored
out a helper to grab _SC_PHYS_PAGES and then did the multiply by
RAM_SIZE_RATIO before converting back to bytes.

e.g. something like:

	available = MIN_RAM_SIZE;

	nrpages = host_ram_nrpages() * RAM_SIZE_RATIO;
	if (nrpages)
		available = nrpages * host_page_size();

and then host_ram_size() just calls the two new helpers.

What do you think?

Will



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux