From patchwork Mon Jun 25 16:55:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 167167 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 50CEC1007D2 for ; Tue, 26 Jun 2012 02:55:35 +1000 (EST) Received: from localhost ([::1]:51321 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SjCZY-00054x-Pl for incoming@patchwork.ozlabs.org; Mon, 25 Jun 2012 12:55:32 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SjCZH-000545-1U for qemu-devel@nongnu.org; Mon, 25 Jun 2012 12:55:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SjCZD-0003YI-GB for qemu-devel@nongnu.org; Mon, 25 Jun 2012 12:55:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47774) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SjCZD-0003Y9-84 for qemu-devel@nongnu.org; Mon, 25 Jun 2012 12:55:11 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5PGt9hl019845 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 25 Jun 2012 12:55:09 -0400 Received: from localhost (ovpn-113-122.phx2.redhat.com [10.3.113.122]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q5PGt8S5021077; Mon, 25 Jun 2012 12:55:09 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Mon, 25 Jun 2012 13:55:30 -0300 Message-Id: <1340643332-5653-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1340643332-5653-1-git-send-email-lcapitulino@redhat.com> References: <1340643332-5653-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: aarcange@redhat.com, avi@redhat.com Subject: [Qemu-devel] [RFC 1/3] memory: add -disable-mem-merge command-line 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 Allow for disabling memory merge support (KSM on Linux), which is enabled by default otherwise. Signed-off-by: Luiz Capitulino --- cpu-all.h | 1 + exec-obsolete.h | 1 + exec.c | 25 +++++++++++++++++++++---- memory.c | 5 +++++ memory.h | 5 +++++ qemu-options.hx | 7 +++++++ vl.c | 3 +++ 7 files changed, 43 insertions(+), 4 deletions(-) diff --git a/cpu-all.h b/cpu-all.h index 9dc249a..429c1c3 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -484,6 +484,7 @@ typedef struct RAMBlock { } RAMBlock; typedef struct RAMList { + bool merge_memory; uint8_t *phys_dirty; QLIST_HEAD(, RAMBlock) blocks; } RAMList; diff --git a/exec-obsolete.h b/exec-obsolete.h index 792c831..71faf81 100644 --- a/exec-obsolete.h +++ b/exec-obsolete.h @@ -30,6 +30,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr); void qemu_ram_free(ram_addr_t addr); void qemu_ram_free_from_ptr(ram_addr_t addr); +void qemu_set_mem_merge(bool value); struct MemoryRegion; struct MemoryRegionSection; diff --git a/exec.c b/exec.c index 8244d54..c003789 100644 --- a/exec.c +++ b/exec.c @@ -112,7 +112,10 @@ static uint8_t *code_gen_ptr; int phys_ram_fd; static int in_migration; -RAMList ram_list = { .blocks = QLIST_HEAD_INITIALIZER(ram_list.blocks) }; +RAMList ram_list = { + .merge_memory = true, + .blocks = QLIST_HEAD_INITIALIZER(ram_list.blocks) +}; static MemoryRegion *system_memory; static MemoryRegion *system_io; @@ -2499,6 +2502,20 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev) } } +void qemu_set_mem_merge(bool value) +{ + ram_list.merge_memory = value; +} + +static int madvise_mergeable(void *addr, size_t len) +{ + if (ram_list.merge_memory) { + return qemu_madvise(addr, len, QEMU_MADV_MERGEABLE); + } + + return -1; +} + ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr) { @@ -2518,7 +2535,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); + madvise_mergeable(new_block->host, size); } #else fprintf(stderr, "-mem-path option unsupported\n"); @@ -2545,7 +2562,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, new_block->host = qemu_vmalloc(size); } #endif - qemu_madvise(new_block->host, size, QEMU_MADV_MERGEABLE); + madvise_mergeable(new_block->host, size); } } new_block->length = size; @@ -2672,7 +2689,7 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) length, addr); exit(1); } - qemu_madvise(vaddr, length, QEMU_MADV_MERGEABLE); + madvise_mergeable(vaddr, length); } return; } diff --git a/memory.c b/memory.c index aab4a31..71789ab 100644 --- a/memory.c +++ b/memory.c @@ -1439,6 +1439,11 @@ void memory_global_dirty_log_stop(void) MEMORY_LISTENER_CALL_GLOBAL(log_global_stop, Reverse); } +void memory_global_set_merge(bool value) +{ + qemu_set_mem_merge(value); +} + static void listener_add_address_space(MemoryListener *listener, AddressSpace *as) { diff --git a/memory.h b/memory.h index 740c48e..ac224d4 100644 --- a/memory.h +++ b/memory.h @@ -746,6 +746,11 @@ void memory_global_dirty_log_start(void); */ void memory_global_dirty_log_stop(void); +/** + * memory_global_set_merge: enable/disable memory merging done by the host + */ +void memory_global_set_merge(bool value); + void mtree_info(fprintf_function mon_printf, void *f); #endif diff --git a/qemu-options.hx b/qemu-options.hx index 8b66264..324cc97 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -409,6 +409,13 @@ Preallocate memory when using -mem-path. ETEXI #endif +DEF("disable-mem-merge", 0, QEMU_OPTION_disable_mem_merge, + "-disable-mem-merge disable memory merging.", QEMU_ARCH_ALL) +STEXI +@item -disable-mem-merge +Disable memory merging. On Linux systems this disables KSM support. +ETEXI + DEF("k", HAS_ARG, QEMU_OPTION_k, "-k language use keyboard layout (for example 'fr' for French)\n", QEMU_ARCH_ALL) diff --git a/vl.c b/vl.c index 1329c30..f81aadf 100644 --- a/vl.c +++ b/vl.c @@ -2676,6 +2676,9 @@ int main(int argc, char **argv, char **envp) mem_prealloc = 1; break; #endif + case QEMU_OPTION_disable_mem_merge: + memory_global_set_merge(false); + break; case QEMU_OPTION_d: log_mask = optarg; break;