hostmem: no need to check for host_memory_backend_mr_inited() in alloc()
PATCH 1/1 hostmem: no need to check for host_memory_backend_mr_inited() in alloc()
memfd_backend_memory_alloc/file_backend_memory_alloc both needlessly are are calling host_memory_backend_mr_inited() which creates an illusion that alloc could be called multiple times but it isn't, it's called once from UserCreatable complete().
--- backends/hostmem-file.c | 2 +- backends/hostmem-memfd.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-)
backends/hostmem-file.c +1 -1
@@ -54,7 +54,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)#ifndef CONFIG_LINUX error_setg (errp,"-mem-path not supported on this host" );#else -if (!host_memory_backend_mr_inited (backend)) { + {gchar *path; backend->force_prealloc = mem_prealloc; path =object_get_canonical_path (OBJECT (backend));
backends/hostmem-memfd.c +0 -4
@@ -44,10 +44,6 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)return ; } -if (host_memory_backend_mr_inited (backend)) { -return ; - } - backend->force_prealloc = mem_prealloc; fd = qemu_memfd_create(TYPE_MEMORY_BACKEND_MEMFD, backend->size, m->hugetlb, m->hugetlbsize, m->seal ?
Signature · 1 line
2.19.0.rc0.48.gb9dfa238d5
Quoted 7 lines · Marc-André Lureau
memfd_backend_memory_alloc/file_backend_memory_alloc both needlessly are are calling
host_memory_backend_mr_inited()which creates an illusion that alloc could be called multiple times but it isn't, it's called once from UserCreatablecomplete().Suggested-by Igor Mammedov <[email protected]>Signed-off-by Marc-André Lureau <[email protected]>
If calling the function multiple times is a mistake, should we replace the checks with:
assert(!host_memory_backend_mr_inited(backend));
?
Quoted 36 lines
--- backends/hostmem-file.c | 2 +- backends/hostmem-memfd.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-)backends/hostmem-file.c +1
-1@@ -54,7 +54,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)#ifndef CONFIG_LINUX error_setg (errp,"-mem-path not supported on this host" );#else -if (!host_memory_backend_mr_inited (backend)) { + {gchar *path; backend->force_prealloc = mem_prealloc; path =object_get_canonical_path (OBJECT (backend));backends/hostmem-memfd.c +0
-4@@ -44,10 +44,6 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)return ; } -if (host_memory_backend_mr_inited (backend)) { -return ; - } - backend->force_prealloc = mem_prealloc; fd = qemu_memfd_create(TYPE_MEMORY_BACKEND_MEMFD, backend->size, m->hugetlb, m->hugetlbsize, m->seal ?Signature · 1 line
2.19.0.rc0.48.gb9dfa238d5
Signature · 1 line
Eduardo
Quoted 5 lines · On Thu, 30 Aug 2018 16:09:58 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 4 lines · Marc-André Lureau
memfd_backend_memory_alloc/file_backend_memory_alloc both needlessly are are calling
host_memory_backend_mr_inited()which creates an illusion that alloc could be called multiple times but it isn't, it's called once from UserCreatablecomplete().
could you extend this patch to cover file_backend_memory_alloc() as well? Otherwise this logic would be copy-pasted again in the future.
Quoted 7 lines
Quoted 2 lines
Suggested-by Igor Mammedov <[email protected]>Signed-off-by Marc-André Lureau <[email protected]>If calling the function multiple times is a mistake, should we replace the checks with:
assert(!host_memory_backend_mr_inited(backend));
?
it is confusing calling it where it's not necessary, hence this cleanup. Considering that HostMemoryBackendClass::alloc is internal bussines of hostmem backends, assert() would just add clutter.
Quoted 37 lines
Quoted 36 lines
--- backends/hostmem-file.c | 2 +- backends/hostmem-memfd.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-)backends/hostmem-file.c +1
-1@@ -54,7 +54,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)#ifndef CONFIG_LINUX error_setg (errp,"-mem-path not supported on this host" );#else -if (!host_memory_backend_mr_inited (backend)) { + {gchar *path; backend->force_prealloc = mem_prealloc; path =object_get_canonical_path (OBJECT (backend));backends/hostmem-memfd.c +0
-4@@ -44,10 +44,6 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)return ; } -if (host_memory_backend_mr_inited (backend)) { -return ; - } - backend->force_prealloc = mem_prealloc; fd = qemu_memfd_create(TYPE_MEMORY_BACKEND_MEMFD, backend->size, m->hugetlb, m->hugetlbsize, m->seal ?Signature · 1 line
2.19.0.rc0.48.gb9dfa238d5