Skip to content

Commit

Permalink
Make qemu_mempath_getpagesize() accept NULL
Browse files Browse the repository at this point in the history
qemu_mempath_getpagesize() gets the effective (host side) page size for
a block of memory backed by an mmap()ed file on the host.  It requires
the mem_path parameter to be non-NULL.

This ends up meaning all the callers need a different case for handling
anonymous memory (for memory-backend-ram or default memory with -mem-path
is not specified).

We can make all those callers a little simpler by having
qemu_mempath_getpagesize() accept NULL, and treat that as the anonymous
memory case.

Signed-off-by: David Gibson <[email protected]>
Reviewed-by: Greg Kurz <[email protected]>
Acked-by: Paolo Bonzini <[email protected]>
  • Loading branch information
dgibson committed Apr 27, 2018
1 parent 8a4fd42 commit 0de6e2a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 33 deletions.
21 changes: 6 additions & 15 deletions exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,19 +1488,14 @@ void ram_block_dump(Monitor *mon)
*/
static int find_max_supported_pagesize(Object *obj, void *opaque)
{
char *mem_path;
long *hpsize_min = opaque;

if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) {
mem_path = object_property_get_str(obj, "mem-path", NULL);
if (mem_path) {
long hpsize = qemu_mempath_getpagesize(mem_path);
g_free(mem_path);
if (hpsize < *hpsize_min) {
*hpsize_min = hpsize;
}
} else {
*hpsize_min = getpagesize();
char *mem_path = object_property_get_str(obj, "mem-path", NULL);
long hpsize = qemu_mempath_getpagesize(mem_path);
g_free(mem_path);
if (hpsize < *hpsize_min) {
*hpsize_min = hpsize;
}
}

Expand All @@ -1513,11 +1508,7 @@ long qemu_getrampagesize(void)
long mainrampagesize;
Object *memdev_root;

if (mem_path) {
mainrampagesize = qemu_mempath_getpagesize(mem_path);
} else {
mainrampagesize = getpagesize();
}
mainrampagesize = qemu_mempath_getpagesize(mem_path);

/* it's possible we have memory-backend objects with
* hugepage-backed RAM. these may get mapped into system
Expand Down
8 changes: 2 additions & 6 deletions target/ppc/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,8 @@ bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path)
char *mempath = object_property_get_str(mem_obj, "mem-path", NULL);
long pagesize;

if (mempath) {
pagesize = qemu_mempath_getpagesize(mempath);
g_free(mempath);
} else {
pagesize = getpagesize();
}
pagesize = qemu_mempath_getpagesize(mempath);
g_free(mempath);

return pagesize >= max_cpu_page_size;
}
Expand Down
26 changes: 14 additions & 12 deletions util/mmap-alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,21 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
struct statfs fs;
int ret;

do {
ret = statfs(mem_path, &fs);
} while (ret != 0 && errno == EINTR);

if (ret != 0) {
fprintf(stderr, "Couldn't statfs() memory path: %s\n",
strerror(errno));
exit(1);
}
if (mem_path) {
do {
ret = statfs(mem_path, &fs);
} while (ret != 0 && errno == EINTR);

if (fs.f_type == HUGETLBFS_MAGIC) {
/* It's hugepage, return the huge page size */
return fs.f_bsize;
if (ret != 0) {
fprintf(stderr, "Couldn't statfs() memory path: %s\n",
strerror(errno));
exit(1);
}

if (fs.f_type == HUGETLBFS_MAGIC) {
/* It's hugepage, return the huge page size */
return fs.f_bsize;
}
}
#ifdef __sparc__
/* SPARC Linux needs greater alignment than the pagesize */
Expand Down

0 comments on commit 0de6e2a

Please sign in to comment.