From patchwork Wed Jul 18 14:31:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 171697 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 27D202C010F for ; Thu, 19 Jul 2012 00:31:08 +1000 (EST) Received: from localhost ([::1]:44520 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrVHO-0001wW-88 for incoming@patchwork.ozlabs.org; Wed, 18 Jul 2012 10:31:06 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrVHA-0001uw-FO for qemu-devel@nongnu.org; Wed, 18 Jul 2012 10:31:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SrVH4-0005ll-Dp for qemu-devel@nongnu.org; Wed, 18 Jul 2012 10:30:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52455) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrVH4-0005lZ-5A for qemu-devel@nongnu.org; Wed, 18 Jul 2012 10:30:46 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6IEUjfd030185 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 18 Jul 2012 10:30:45 -0400 Received: from doriath.home (ovpn-113-90.phx2.redhat.com [10.3.113.90]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q6IEUf07002609; Wed, 18 Jul 2012 10:30:42 -0400 Date: Wed, 18 Jul 2012 11:31:16 -0300 From: Luiz Capitulino To: qemu-devel Message-ID: <20120718113116.63253f58@doriath.home> Organization: Red Hat Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: jan.kiszka@siemens.com, Anthony Liguori , Avi Kivity Subject: [Qemu-devel] [PATCH v4] add -machine mem-merge=on|off option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It allows to disable memory merge support (KSM on Linux), which is enabled by default otherwise. Signed-off-by: Luiz Capitulino --- IMPORTANT: this is on top of this series: http://lists.gnu.org/archive/html/qemu-devel/2012-07/msg01798.html o v4 - rename option to mem-merge - rebase on top of latest master - rebase on top of the machine option rename series exec.c | 19 ++++++++++++++++--- qemu-config.c | 4 ++++ qemu-options.hx | 7 ++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/exec.c b/exec.c index c9fa17d..59d29ae 100644 --- a/exec.c +++ b/exec.c @@ -2510,6 +2510,19 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev) } } +static int memory_try_enable_merging(void *addr, size_t len) +{ + QemuOpts *opts; + + opts = qemu_opts_find(qemu_find_opts("machine"), 0); + if (opts && !qemu_opt_get_bool(opts, "mem-merge", true)) { + /* disabled by the user */ + return 0; + } + + return qemu_madvise(addr, len, QEMU_MADV_MERGEABLE); +} + ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr) { @@ -2529,7 +2542,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, new_block->host = file_ram_alloc(new_block, size, mem_path); if (!new_block->host) { new_block->host = qemu_vmalloc(size); - qemu_madvise(new_block->host, size, QEMU_MADV_MERGEABLE); + memory_try_enable_merging(new_block->host, size); } #else fprintf(stderr, "-mem-path option unsupported\n"); @@ -2544,7 +2557,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, } else { new_block->host = qemu_vmalloc(size); } - qemu_madvise(new_block->host, size, QEMU_MADV_MERGEABLE); + memory_try_enable_merging(new_block->host, size); } } new_block->length = size; @@ -2670,7 +2683,7 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) length, addr); exit(1); } - qemu_madvise(vaddr, length, QEMU_MADV_MERGEABLE); + memory_try_enable_merging(vaddr, length); } return; } diff --git a/qemu-config.c b/qemu-config.c index 9dac3be..3355e45 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -599,6 +599,10 @@ static QemuOptsList qemu_machine_opts = { .alias= "dt_compatible", .type = QEMU_OPT_STRING, .help = "Overrides the \"compatible\" property of the dt root node", + }, { + .name = "mem-merge", + .type = QEMU_OPT_BOOL, + .help = "enable/disable memory merge support", }, { /* End of list */ } }, diff --git a/qemu-options.hx b/qemu-options.hx index 90eab87..25ce07e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -33,7 +33,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " property accel=accel1[:accel2[:...]] selects accelerator\n" " supported accelerators are kvm, xen, tcg (default: tcg)\n" " kernel-irqchip=on|off controls accelerated irqchip support\n" - " kvm-shadow-mem=size of KVM shadow MMU\n", + " kvm-shadow-mem=size of KVM shadow MMU\n" + " mem-merge=on|off controls memory merge support (default: on)\n", QEMU_ARCH_ALL) STEXI @item -machine [type=]@var{name}[,prop=@var{value}[,...]] @@ -50,6 +51,10 @@ to initialize. Enables in-kernel irqchip support for the chosen accelerator when available. @item kvm-shadow-mem=size Defines the size of the KVM shadow MMU. +@item mem-merge=on|off +Enables or disables memory merge support. This feature, when supported by +the host, de-duplicates identical memory pages among VMs instances +(enabled by default). @end table ETEXI