#include "qapi/visitor.h"
#include "qemu/config-file.h"
#include "qom/object_interfaces.h"
+#include "qemu/mmap-alloc.h"
#ifdef CONFIG_NUMA
#include <numaif.h>
return backend->is_mapped;
}
+#ifdef __linux__
+size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
+{
+ Object *obj = OBJECT(memdev);
+ char *path = object_property_get_str(obj, "mem-path", NULL);
+ size_t pagesize = qemu_mempath_getpagesize(path);
+
+ g_free(path);
+ return pagesize;
+}
+#else
+size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
+{
+ return getpagesize();
+}
+#endif
+
static void
host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
{
long *hpsize_min = opaque;
if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) {
- char *mem_path = object_property_get_str(obj, "mem-path", NULL);
- long hpsize = qemu_mempath_getpagesize(mem_path);
- g_free(mem_path);
+ long hpsize = host_memory_backend_pagesize(MEMORY_BACKEND(obj));
+
if (hpsize < *hpsize_min) {
*hpsize_min = hpsize;
}
void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped);
bool host_memory_backend_is_mapped(HostMemoryBackend *backend);
+size_t host_memory_backend_pagesize(HostMemoryBackend *memdev);
+
#endif
bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path)
{
Object *mem_obj = object_resolve_path(obj_path, NULL);
- char *mempath = object_property_get_str(mem_obj, "mem-path", NULL);
- long pagesize;
-
- pagesize = qemu_mempath_getpagesize(mempath);
- g_free(mempath);
+ long pagesize = host_memory_backend_pagesize(MEMORY_BACKEND(mem_obj));
return pagesize >= max_cpu_page_size;
}