From patchwork Thu Feb 19 15:29:36 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 7996 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 n1JFj4Po004279 for ; Thu, 19 Feb 2009 15:45:04 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752102AbZBSPoy (ORCPT ); Thu, 19 Feb 2009 10:44:54 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752894AbZBSPoy (ORCPT ); Thu, 19 Feb 2009 10:44:54 -0500 Received: from tx2ehsobe002.messaging.microsoft.com ([65.55.88.12]:35051 "EHLO TX2EHSOBE004.bigfish.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752102AbZBSPox (ORCPT ); Thu, 19 Feb 2009 10:44:53 -0500 X-Greylist: delayed 902 seconds by postgrey-1.27 at vger.kernel.org; Thu, 19 Feb 2009 10:44:52 EST Received: from mail137-tx2-R.bigfish.com (10.9.14.250) by TX2EHSOBE004.bigfish.com (10.9.40.24) with Microsoft SMTP Server id 8.1.340.0; Thu, 19 Feb 2009 15:29:49 +0000 Received: from mail137-tx2 (localhost.localdomain [127.0.0.1]) by mail137-tx2-R.bigfish.com (Postfix) with ESMTP id 6ED521178369; Thu, 19 Feb 2009 15:29:48 +0000 (UTC) X-BigFish: VPS5(z5b2jzzzzzz32i43j) Received: by mail137-tx2 (MessageSwitch) id 1235057385608190_13699; Thu, 19 Feb 2009 15:29:45 +0000 (UCT) Received: from ausb3extmailp01.amd.com (unknown [163.181.251.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail137-tx2.bigfish.com (Postfix) with ESMTP id 56935DB8052; Thu, 19 Feb 2009 15:29:45 +0000 (UTC) Received: from ausb3twp01.amd.com ([163.181.250.37]) by ausb3extmailp01.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id n1JFTbQd012961; Thu, 19 Feb 2009 09:29:40 -0600 X-WSS-ID: 0KFBKD9-01-8MD-01 Received: from sausexbh2.amd.com (SAUSEXBH2.amd.com [163.181.22.102]) by ausb3twp01.amd.com (Tumbleweed MailGate 3.5.1) with ESMTP id 2AA491944B9; Thu, 19 Feb 2009 09:29:33 -0600 (CST) Received: from SAUSEXMB3.amd.com ([163.181.22.202]) by sausexbh2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 19 Feb 2009 09:29:40 -0600 Received: from SDRSEXMB1.amd.com ([172.20.3.116]) by SAUSEXMB3.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 19 Feb 2009 09:29:39 -0600 Received: from seurexmb1.amd.com ([165.204.82.130]) by SDRSEXMB1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 19 Feb 2009 16:29:37 +0100 Received: from lemmy.amd.com ([165.204.85.93]) by seurexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 19 Feb 2009 16:29:37 +0100 Received: by lemmy.amd.com (Postfix, from userid 41430) id 0CC955392F; Thu, 19 Feb 2009 16:29:37 +0100 (CET) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: kvm@vger.kernel.org, Joerg Roedel Subject: [PATCH] kvm/qemu: use statfs to determine size of huge pages Date: Thu, 19 Feb 2009 16:29:36 +0100 Message-ID: <1235057376-22481-1-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.5.6.4 X-OriginalArrivalTime: 19 Feb 2009 15:29:37.0136 (UTC) FILETIME=[DFA88700:01C992A6] 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, 21 insertions(+), 23 deletions(-) diff --git a/qemu/sysemu.h b/qemu/sysemu.h index 19464cf..4333495 100644 --- a/qemu/sysemu.h +++ b/qemu/sysemu.h @@ -99,7 +99,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 bbd7aa3..b8c1162 100644 --- a/qemu/vl.c +++ b/qemu/vl.c @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #if defined(__NetBSD__) @@ -254,7 +255,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; @@ -4717,32 +4718,29 @@ 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); + + if (ret != 0) { + perror("statfs"); + return 0; } - ret = read(fd, buf, sizeof(buf)); - if (ret < 0) { - perror("read"); - exit(0); + if (fs.f_type != HUGETLBFS_MAGIC) { + fprintf(stderr, "Path not on HugeTLBFS: %s\n", path); + return 0; } - size = strstr(buf, needle); - if (!size) - return 0; - size += strlen(needle); - hugepagesize = strtol(size, NULL, 0); - return hugepagesize; + return fs.f_bsize; } static void *alloc_mem_area(size_t memory, unsigned long *len, const char *path) @@ -4762,7 +4760,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;