From patchwork Sun May 17 15:43:07 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 24319 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 n4HFher9013002 for ; Sun, 17 May 2009 15:43:41 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754656AbZEQPng (ORCPT ); Sun, 17 May 2009 11:43:36 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754444AbZEQPnf (ORCPT ); Sun, 17 May 2009 11:43:35 -0400 Received: from e3.ny.us.ibm.com ([32.97.182.143]:35427 "EHLO e3.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754564AbZEQPnd (ORCPT ); Sun, 17 May 2009 11:43:33 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by e3.ny.us.ibm.com (8.13.1/8.13.1) with ESMTP id n4HFdFrC022554 for ; Sun, 17 May 2009 11:39:15 -0400 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n4HFhYdc051264 for ; Sun, 17 May 2009 11:43:34 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n4HFfX3V030287 for ; Sun, 17 May 2009 11:41:34 -0400 Received: from localhost.localdomain (sig-9-65-8-189.mts.ibm.com [9.65.8.189]) by d01av02.pok.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id n4HFfPcS030035; Sun, 17 May 2009 11:41:32 -0400 From: Anthony Liguori To: kvm@vger.kernel.org Cc: Glauber Costa , Joerg Roedel , Avi Kivity , Anthony Liguori Subject: [PATCH 06/17] Use statfs to determine size of huge pages Date: Sun, 17 May 2009 10:43:07 -0500 Message-Id: <1242574999-20887-7-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.6.0.6 In-Reply-To: <1242574999-20887-1-git-send-email-aliguori@us.ibm.com> References: <1242574999-20887-1-git-send-email-aliguori@us.ibm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Joerg Roedel The current method of finding out the size of huge pages does not work reliably 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 qemu to use statfs instead of parsing /proc/meminfo. Signed-off-by: Joerg Roedel Signed-off-by: Avi Kivity Signed-off-by: Anthony Liguori diff --git a/sysemu.h b/sysemu.h index 19464cf..4333495 100644 --- a/sysemu.h +++ b/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/vl.c b/vl.c index 0437159..5d02e10 100644 --- a/vl.c +++ b/vl.c @@ -62,6 +62,7 @@ #include #include #include +#include #include #include #if defined(__NetBSD__) @@ -256,7 +257,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; @@ -4707,32 +4708,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) @@ -4752,7 +4748,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;