From patchwork Sat May 7 19:09:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pekka Enberg X-Patchwork-Id: 764612 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p47J9EjJ007824 for ; Sat, 7 May 2011 19:09:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756008Ab1EGTJJ (ORCPT ); Sat, 7 May 2011 15:09:09 -0400 Received: from filtteri1.pp.htv.fi ([213.243.153.184]:58960 "EHLO filtteri1.pp.htv.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754973Ab1EGTJH (ORCPT ); Sat, 7 May 2011 15:09:07 -0400 Received: from localhost (localhost [127.0.0.1]) by filtteri1.pp.htv.fi (Postfix) with ESMTP id CD9168BBCB; Sat, 7 May 2011 22:09:06 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at pp.htv.fi Received: from smtp4.welho.com ([213.243.153.38]) by localhost (filtteri1.pp.htv.fi [213.243.153.184]) (amavisd-new, port 10024) with ESMTP id RUxG0u9b1XzQ; Sat, 7 May 2011 22:09:06 +0300 (EEST) Received: from localhost.localdomain (cs181148025.pp.htv.fi [82.181.148.25]) by smtp4.welho.com (Postfix) with ESMTP id 8FE495BC005; Sat, 7 May 2011 22:09:06 +0300 (EEST) From: Pekka Enberg To: kvm@vger.kernel.org Cc: Pekka Enberg , Asias He , Cyrill Gorcunov , Ingo Molnar , Prasad Joshi , Sasha Levin Subject: [PATCH 1/2] kvm tools: Don't use all of host RAM for guests by default Date: Sat, 7 May 2011 22:09:04 +0300 Message-Id: <1304795345-7092-1-git-send-email-penberg@kernel.org> X-Mailer: git-send-email 1.7.0.4 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sat, 07 May 2011 19:09:15 +0000 (UTC) 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 --- 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;