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 <[email protected]>
Cc: Cyrill Gorcunov <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Prasad Joshi <[email protected]>
Cc: Sasha Levin <[email protected]>
Suggested-by: Ingo Molnar <[email protected]>
Signed-off-by: Pekka Enberg <[email protected]>
---
 tools/kvm/kvm-run.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index ec1e462..b9cdec2 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -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;
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to