From patchwork Mon Jul 2 18:06:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 168629 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 9E9F32C0097 for ; Tue, 3 Jul 2012 04:41:10 +1000 (EST) Received: from localhost ([::1]:46572 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sll1S-0002Zn-OI for incoming@patchwork.ozlabs.org; Mon, 02 Jul 2012 14:06:54 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sll0b-0000Q0-8v for qemu-devel@nongnu.org; Mon, 02 Jul 2012 14:06:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sll0Z-0001nK-28 for qemu-devel@nongnu.org; Mon, 02 Jul 2012 14:06:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23503) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sll0Y-0001n1-QA for qemu-devel@nongnu.org; Mon, 02 Jul 2012 14:05:58 -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 q62I5n8w018318 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 2 Jul 2012 14:05:50 -0400 Received: from blackpad.lan.raisama.net (vpn1-4-141.gru2.redhat.com [10.97.4.141]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q62I5nKh023286; Mon, 2 Jul 2012 14:05:49 -0400 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id DB7AE203EE4; Mon, 2 Jul 2012 15:06:40 -0300 (BRT) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2012 15:06:38 -0300 Message-Id: <1341252398-12268-7-git-send-email-ehabkost@redhat.com> In-Reply-To: <1341252398-12268-1-git-send-email-ehabkost@redhat.com> References: <1341252398-12268-1-git-send-email-ehabkost@redhat.com> 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: Bill Gray , Andrea Arcangeli , Andre Przywara , kvm@vger.kernel.org, Bharata B Rao Subject: [Qemu-devel] [RFC PATCH 6/6] add -keep-mem-path-files option (v2) 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 This make QEMU create files inside the -mem-path directory using more predictable names, and not remove them afterwards. This allow (for example) users or management layers to use numactl later, to set NUMA policy for the guest RAM. Changes v1 -> v2: - Fix trailing space issue - Coding style changes - Do not initialize static variable to false - Use g_strdup_printf() instead of asprintf() Signed-off-by: Eduardo Habkost --- cpu-all.h | 1 + exec.c | 26 +++++++++++++++++++++++++- qemu-options.hx | 12 ++++++++++++ vl.c | 5 +++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/cpu-all.h b/cpu-all.h index 2beed5a..acd59ff 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -490,6 +490,7 @@ typedef struct RAMList { extern RAMList ram_list; extern const char *mem_path; +extern bool keep_mem_path_files; extern bool mem_prealloc; /* Flags stored in the low bits of the TLB virtual address. These are diff --git a/exec.c b/exec.c index 456ac73..2525a65 100644 --- a/exec.c +++ b/exec.c @@ -2377,6 +2377,25 @@ static int get_temp_fd(const char *path) return fd; } +/* Return FD to RAM block file, using the memory region name as filename + */ +static int open_ramblock_file(RAMBlock *block, const char *path) +{ + int fd; + gchar *filename; + + filename = g_strdup_printf("%s/%s", path, block->mr->name); + fd = open(filename, O_RDWR|O_CREAT); + if (fd < 0) { + perror("unable to open backing store for hugepages"); + g_free(filename); + return -1; + } + g_free(filename); + + return fd; +} + static void *file_ram_alloc(RAMBlock *block, size_t length, const char *path) @@ -2402,7 +2421,12 @@ static void *file_ram_alloc(RAMBlock *block, return NULL; } - fd = get_temp_fd(path); + if (keep_mem_path_files) { + fd = open_ramblock_file(block, path); + } else { + fd = get_temp_fd(path); + } + if (fd < 0) { return NULL; } diff --git a/qemu-options.hx b/qemu-options.hx index 8b66264..f2eb237 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -399,6 +399,18 @@ STEXI Allocate guest RAM from a temporarily created file in @var{path}. ETEXI +DEF("keep-mem-path-files", HAS_ARG, QEMU_OPTION_keep_mempath_files, + "-keep-mem-path-files Keep files created in -mem-path\n", QEMU_ARCH_ALL) +STEXI +@item -keep-mem-path-files +Create the files for -mem-path using the memory region names, and don't remove +them afterwards. + +This allows further fine-tuning of NUMA policy for memory regions using +numactl. +ETEXI + + #ifdef MAP_POPULATE DEF("mem-prealloc", 0, QEMU_OPTION_mem_prealloc, "-mem-prealloc preallocate guest memory (use with -mem-path)\n", diff --git a/vl.c b/vl.c index 5c80189..9f18d53 100644 --- a/vl.c +++ b/vl.c @@ -177,6 +177,8 @@ int display_remote = 0; const char* keyboard_layout = NULL; ram_addr_t ram_size; const char *mem_path = NULL; +bool keep_mem_path_files; /* Keep files created at mem_path. + * use memory region names as filename */ #ifdef MAP_POPULATE bool mem_prealloc; /* force preallocation of physical target memory */ #endif @@ -2671,6 +2673,9 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_mempath: mem_path = optarg; break; + case QEMU_OPTION_keep_mempath_files: + keep_mem_path_files = true; + break; #ifdef MAP_POPULATE case QEMU_OPTION_mem_prealloc: mem_prealloc = true;