From patchwork Fri Mar 27 14:34:38 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 14737 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n2REaTdf010071 for ; Fri, 27 Mar 2009 14:36:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759213AbZC0Oez (ORCPT ); Fri, 27 Mar 2009 10:34:55 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1759099AbZC0Oez (ORCPT ); Fri, 27 Mar 2009 10:34:55 -0400 Received: from tx2ehsobe003.messaging.microsoft.com ([65.55.88.13]:7317 "EHLO TX2EHSOBE006.bigfish.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1759252AbZC0Oex (ORCPT ); Fri, 27 Mar 2009 10:34:53 -0400 Received: from mail81-tx2-R.bigfish.com (10.9.14.235) by TX2EHSOBE006.bigfish.com (10.9.40.26) with Microsoft SMTP Server id 8.1.340.0; Fri, 27 Mar 2009 14:34:51 +0000 Received: from mail81-tx2 (localhost.localdomain [127.0.0.1]) by mail81-tx2-R.bigfish.com (Postfix) with ESMTP id 0DA7CA403C9; Fri, 27 Mar 2009 14:34:51 +0000 (UTC) X-BigFish: VPS5(z5b2jzzz1202hzzz32i43j66h) X-Spam-TCS-SCL: 5:0 X-FB-SS: 5, Received: by mail81-tx2 (MessageSwitch) id 1238164489363217_25093; Fri, 27 Mar 2009 14:34:49 +0000 (UCT) Received: from svlb1extmailp02.amd.com (unknown [139.95.251.11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail81-tx2.bigfish.com (Postfix) with ESMTP id 3167AB1005C; Fri, 27 Mar 2009 14:34:49 +0000 (UTC) Received: from svlb1twp02.amd.com ([139.95.250.35]) by svlb1extmailp02.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id n2REYgCt028074; Fri, 27 Mar 2009 07:34:45 -0700 X-WSS-ID: 0KH65TQ-04-0L3-01 Received: from SSVLEXBH1.amd.com (ssvlexbh1.amd.com [139.95.53.182]) by svlb1twp02.amd.com (Tumbleweed MailGate 3.5.1) with ESMTP id 201D51103BC; Fri, 27 Mar 2009 07:34:38 -0700 (PDT) Received: from SSVLEXMB1.amd.com ([139.95.53.181]) by SSVLEXBH1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 27 Mar 2009 07:34:45 -0700 Received: from SF36EXMB1.amd.com ([172.19.4.24]) by SSVLEXMB1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 27 Mar 2009 07:34:44 -0700 Received: from seurexmb1.amd.com ([165.204.82.130]) by SF36EXMB1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 27 Mar 2009 15:34:40 +0100 Received: from lemmy.amd.com ([165.204.15.93]) by seurexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 27 Mar 2009 15:34:39 +0100 Received: by lemmy.amd.com (Postfix, from userid 41430) id 2CDE724612; Fri, 27 Mar 2009 15:34:39 +0100 (CET) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: kvm@vger.kernel.org, Joerg Roedel Subject: [PATCH 1/2] kvm/qemu: use statfs to determine size of huge pages Date: Fri, 27 Mar 2009 15:34:38 +0100 Message-ID: <1238164479-16207-2-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.5.6.4 In-Reply-To: <1238164479-16207-1-git-send-email-joerg.roedel@amd.com> References: <1238164479-16207-1-git-send-email-joerg.roedel@amd.com> X-OriginalArrivalTime: 27 Mar 2009 14:34:39.0691 (UTC) FILETIME=[291959B0:01C9AEE9] MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The current method of finding out the size of huge pages does not work reliable anymore. Current Linux supports more than one huge page size but /proc/meminfo only show one of the supported sizes. To find out the real page size used can be found by calling statfs. This patch changes kvm/qemu to use statfs instead of parsing /proc/meminfo. Signed-off-by: Joerg Roedel --- qemu/sysemu.h | 2 +- qemu/vl.c | 42 +++++++++++++++++++----------------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/qemu/sysemu.h b/qemu/sysemu.h index 4457a40..d765465 100644 --- a/qemu/sysemu.h +++ b/qemu/sysemu.h @@ -105,7 +105,7 @@ extern int graphic_rotate; extern int no_quit; extern int semihosting_enabled; extern int old_param; -extern int hpagesize; +extern long hpagesize; extern const char *bootp_filename; #ifdef USE_KQEMU diff --git a/qemu/vl.c b/qemu/vl.c index c52d2d7..f820d3a 100644 --- a/qemu/vl.c +++ b/qemu/vl.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #if defined(__NetBSD__) @@ -261,7 +262,7 @@ const char *mem_path = NULL; #ifdef MAP_POPULATE int mem_prealloc = 1; /* force preallocation of physical target memory */ #endif -int hpagesize = 0; +long hpagesize = 0; const char *cpu_vendor_string; #ifdef TARGET_ARM int old_param = 0; @@ -4747,32 +4748,27 @@ void qemu_get_launch_info(int *argc, char ***argv, int *opt_daemonize, const cha } #ifdef USE_KVM -static int gethugepagesize(void) + +#define HUGETLBFS_MAGIC 0x958458f6 + +static long gethugepagesize(const char *path) { - int ret, fd; - char buf[4096]; - const char *needle = "Hugepagesize:"; - char *size; - unsigned long hugepagesize; + struct statfs fs; + int ret; - fd = open("/proc/meminfo", O_RDONLY); - if (fd < 0) { - perror("open"); - exit(0); - } + do { + ret = statfs(path, &fs); + } while (ret != 0 && errno == EINTR); - ret = read(fd, buf, sizeof(buf)); - if (ret < 0) { - perror("read"); - exit(0); + if (ret != 0) { + perror("statfs"); + return 0; } - size = strstr(buf, needle); - if (!size) - return 0; - size += strlen(needle); - hugepagesize = strtol(size, NULL, 0); - return hugepagesize; + if (fs.f_type != HUGETLBFS_MAGIC) + fprintf(stderr, "Warning: path not on HugeTLBFS: %s\n", path); + + return fs.f_bsize; } static void *alloc_mem_area(size_t memory, unsigned long *len, const char *path) @@ -4792,7 +4788,7 @@ static void *alloc_mem_area(size_t memory, unsigned long *len, const char *path) if (asprintf(&filename, "%s/kvm.XXXXXX", path) == -1) return NULL; - hpagesize = gethugepagesize() * 1024; + hpagesize = gethugepagesize(path); if (!hpagesize) return NULL;