]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Don't use all of host RAM for guests by default
authorPekka Enberg <penberg@kernel.org>
Sat, 7 May 2011 19:01:54 +0000 (22:01 +0300)
committerPekka Enberg <penberg@kernel.org>
Sat, 7 May 2011 19:01:54 +0000 (22:01 +0300)
This patch fixes the default guest RAM size maximum to 80% of the host RAM to
avoid swapping the host to death.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Suggested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/kvm-run.c

index ec1e4621649e3b853b39a658a13c5828b1224240..b9cdec27fd4b93cca689ca0455a5be4687725910 100644 (file)
@@ -213,6 +213,12 @@ static void kernel_usage_with_options(void)
        fprintf(stderr, "\nPlease see 'kvm run --help' for more options.\n\n");
 }
 
+/*
+ * If user didn't specify how much memory it wants to allocate for the guest,
+ * avoid filling the whole host RAM.
+ */
+#define RAM_SIZE_RATIO         0.8
+
 static u64 get_ram_size(int nr_cpus)
 {
        long available;
@@ -226,7 +232,7 @@ static u64 get_ram_size(int nr_cpus)
 
        page_size       = sysconf(_SC_PAGE_SIZE);
 
-       available       = (nr_pages * page_size) >> MB_SHIFT;
+       available       = ((nr_pages * page_size) >> MB_SHIFT) * RAM_SIZE_RATIO;
 
        if (ram_size > available)
                ram_size        = available;