[PATCH kvmtool v2 3/3] Apply scaling down the calculated guest ram size to the number of pages

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

 



Calculate the guest ram size based a ratio proportional to the
number of pages available, rather than the amount of memory
available in bytes, in the host. This is to ensure that the
result is always page-aligned.

If the result of get_ram_size() isn't 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 | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/builtin-run.c b/builtin-run.c
index 44ea690..21373d4 100644
--- a/builtin-run.c
+++ b/builtin-run.c
@@ -400,17 +400,15 @@ static u64 host_ram_size(void)
 
 static u64 get_ram_size(int nr_cpus)
 {
-	u64 available;
-	u64 ram_size;
+	long nr_pages_available = host_ram_nrpages() * RAM_SIZE_RATIO;
+	u64 ram_size = (u64)SZ_64M * (nr_cpus + 3);
+	u64 available = MIN_RAM_SIZE;
 
-	ram_size	= (u64)SZ_64M * (nr_cpus + 3);
-
-	available	= host_ram_size() * RAM_SIZE_RATIO;
-	if (!available)
-		available = MIN_RAM_SIZE;
+	if (nr_pages_available)
+		available = nr_pages_available * host_page_size();
 
 	if (ram_size > available)
-		ram_size	= available;
+		ram_size = available;
 
 	return ram_size;
 }
-- 
2.41.0.255.g8b1d071c50-goog




[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