Skip to contentSkip to conversation

kvm/qemu: use statfs to determine size of huge pages

PATCH In review Joerg Roedel 3 participants 3 messages Feb 19, 2009 – Feb 22, 2009 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm/qemu: use statfs to determine size of huge pages

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.

---
 qemu/sysemu.h |    2 +-
 qemu/vl.c     |   42 ++++++++++++++++++++----------------------
 2 files changed, 21 insertions(+), 23 deletions(-)
qemu/sysemu.h +1 -1
index 19464cf..4333495 100644
@@ -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
qemu/vl.c +20 -22

72 lines not on this page · raw message

Signature · 1 line
1.5.6.4
#1 lore raw

Hi Joerg,

qemu/vl.c void qemu_get_launch_info(int *argc, char ***argv, int *opt_daemonize, const cha · line 4741

Quoted 12 lines · Joerg Roedel

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.

qemu/vl.c +3 -0
+    if (fs.f_type != HUGETLBFS_MAGIC) {
+	    fprintf(stderr, "Path not on HugeTLBFS: %s\n", path);
+	    return 0;
     }

Would be nicer to use standard page size (sysconf) in case its not a hugetlbfs mount, instead of failing. Useful for testing with shmem.

Quoted 11 lines
qemu/vl.c +1 -6
-    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)

qemu/vl.c static void *alloc_mem_area(size_t memory, unsigned long *len, const char *path) · line 4765

Quoted 7 lines
qemu/vl.c +1 -1
@@ -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;

Out of curiosity, your immediate reason for this patch is use of gbpages?

#2 lore raw
Quoted 33 lines · Marcelo Tosatti

Hi Joerg,

qemu/vl.c void qemu_get_launch_info(int *argc, char ***argv, int *opt_daemonize, const cha · line 4741

Quoted 12 lines · Joerg Roedel

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.

qemu/vl.c +3 -0
+    if (fs.f_type != HUGETLBFS_MAGIC) {
+	    fprintf(stderr, "Path not on HugeTLBFS: %s\n", path);
+	    return 0;
     }

Would be nicer to use standard page size (sysconf) in case its not a hugetlbfs mount, instead of failing. Useful for testing with shmem.

Quoted 14 lines
qemu/vl.c +1 -6
-    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;
 
Quoted 7 lines

qemu/vl.c static void *alloc_mem_area(size_t memory, unsigned long *len, const char *path) · line 4765

Quoted 4 lines
qemu/vl.c +1 -1
-    hpagesize = gethugepagesize() * 1024;
+    hpagesize = gethugepagesize(path);
     if (!hpagesize)
 	return NULL;

Out of curiosity, your immediate reason for this patch is use of gbpages?

Yes. I am currently preparing patches to support gbpages in KVM. I think they will be ready for submission next week.
The leak bugs were also found when I was debugging the code this week. My test system has 5 gbpages an leaking one or two of them is _really_ bad ;)

Joerg