Replace qemu_real_host_page variables with inlined functions

Replace the global variables with inlined helper functions. getpagesize() is very
likely annotated with a "const" function attribute (at least with glibc), and thus
optimization should apply even better.

This avoids the need for a constructor initialization too.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20220323155743.1585078-12-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Marc-André Lureau 2022-03-23 19:57:22 +04:00 committed by Paolo Bonzini
parent b307e5052d
commit 8e3b0cbb72
53 changed files with 150 additions and 162 deletions

View file

@ -50,7 +50,7 @@ size_t qemu_fd_getpagesize(int fd)
#endif
#endif
return qemu_real_host_page_size;
return qemu_real_host_page_size();
}
size_t qemu_mempath_getpagesize(const char *mem_path)
@ -81,7 +81,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
#endif
#endif
return qemu_real_host_page_size;
return qemu_real_host_page_size();
}
#define OVERCOMMIT_MEMORY_PATH "/proc/sys/vm/overcommit_memory"
@ -101,7 +101,7 @@ static bool map_noreserve_effective(int fd, uint32_t qemu_map_flags)
* MAP_NORESERVE.
* b) MAP_NORESERVE is not affected by /proc/sys/vm/overcommit_memory.
*/
if (qemu_fd_getpagesize(fd) != qemu_real_host_page_size) {
if (qemu_fd_getpagesize(fd) != qemu_real_host_page_size()) {
return true;
}
@ -166,7 +166,7 @@ static void *mmap_reserve(size_t size, int fd)
* We do this unless we are using the system page size, in which case
* anonymous memory is OK.
*/
if (fd == -1 || qemu_fd_getpagesize(fd) == qemu_real_host_page_size) {
if (fd == -1 || qemu_fd_getpagesize(fd) == qemu_real_host_page_size()) {
fd = -1;
flags |= MAP_ANONYMOUS;
} else {
@ -243,7 +243,7 @@ static inline size_t mmap_guard_pagesize(int fd)
/* Mappings in the same segment must share the same page size */
return qemu_fd_getpagesize(fd);
#else
return qemu_real_host_page_size;
return qemu_real_host_page_size();
#endif
}