From 18bd8c3bd2a7df24b691d26bd36116cb730fb0a0 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Sat, 7 May 2011 22:01:54 +0300 Subject: [PATCH] kvm tools: Don't use all of host RAM for guests by default 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 Cc: Cyrill Gorcunov Cc: Ingo Molnar Cc: Prasad Joshi Cc: Sasha Levin Suggested-by: Ingo Molnar Signed-off-by: Pekka Enberg --- kvm-run.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kvm-run.c b/kvm-run.c index ec1e462..b9cdec2 100644 --- a/kvm-run.c +++ b/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;