exec.c: Support huge pages on Linux.
Change-Id: I971e597c0c337657f188304ed26420be6b5d15f6
diff --git a/exec.c b/exec.c
index 47c8825..9998487 100644
--- a/exec.c
+++ b/exec.c
@@ -791,7 +791,7 @@
qemu_mutex_unlock(&ram_list.mutex);
}
-#if defined(__linux__) && !defined(CONFIG_ANDROID)
+#ifdef __linux__
#include <sys/vfs.h>
@@ -837,7 +837,7 @@
hpagesize = gethugepagesize(path);
if (!hpagesize) {
- return NULL;
+ goto error;
}
if (memory < hpagesize) {
@@ -846,11 +846,11 @@
if (kvm_enabled() && !kvm_has_sync_mmu()) {
fprintf(stderr, "host lacks kvm mmu notifiers, -mem-path unsupported\n");
- return NULL;
+ goto error;
}
/* Make name safe to use with mkstemp by replacing '/' with '_'. */
- sanitized_name = g_strdup(block->mr->name);
+ sanitized_name = g_strdup(block->idstr);
for (c = sanitized_name; *c != '\0'; c++) {
if (*c == '/')
*c = '_';
@@ -864,7 +864,7 @@
if (fd < 0) {
perror("unable to create backing store for hugepages");
g_free(filename);
- return NULL;
+ goto error;
}
unlink(filename);
g_free(filename);
@@ -884,7 +884,7 @@
if (area == MAP_FAILED) {
perror("file_ram_alloc: can't mmap RAM pages");
close(fd);
- return (NULL);
+ goto error;
}
if (mem_prealloc) {
@@ -913,7 +913,7 @@
}
/* MAP_POPULATE silently ignores failures */
- for (i = 0; i < (memory/hpagesize)-1; i++) {
+ for (i = 0; i < (memory/hpagesize); i++) {
memset(area + (hpagesize*i), 0, 1);
}
@@ -928,6 +928,11 @@
block->fd = fd;
return area;
+error:
+ if (mem_prealloc) {
+ exit(1);
+ }
+ return NULL;
}
#else
static void *file_ram_alloc(RAMBlock *block,