[PATCH 2/2] osdep: Cache getpagesize() call in qemu_real_host_page_size()

Philippe Mathieu-Daudé posted 2 patches 1 week, 5 days ago
[PATCH 2/2] osdep: Cache getpagesize() call in qemu_real_host_page_size()
Posted by Philippe Mathieu-Daudé 1 week, 5 days ago
Since we can not know whether a libc implementation of
getpagesize() calls syscalls -- potentially slow --, but
we know the host page size won't change during runtime,
we can cache its value.

Reported-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 util/osdep.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/util/osdep.c b/util/osdep.c
index 44fad13dcc7..9b50d00dbda 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -616,5 +616,11 @@ int qemu_fdatasync(int fd)
 
 uintptr_t qemu_real_host_page_size(void)
 {
-    return getpagesize();
+    static uintptr_t real_host_page_size;
+
+    if (!real_host_page_size) {
+        real_host_page_size = getpagesize();
+    }
+
+    return real_host_page_size;
 }
-- 
2.51.0