From 9c60766887c647df7193463f7a2075e8993b514c Mon Sep 17 00:00:00 2001 From: Alexey Kardashevskiy Date: Thu, 2 Mar 2017 13:36:11 +1100 Subject: exec, kvm, target-ppc: Move getrampagesize() to common code getrampagesize() returns the largest supported page size and mainly used to know if huge pages are enabled. However is implemented in target-ppc/kvm.c and not available in TCG or other architectures. This renames and moves gethugepagesize() to mmap-alloc.c where fd-based analog of it is already implemented. This renames and moves getrampagesize() to exec.c as it seems to be the common place for helpers like this. Signed-off-by: Alexey Kardashevskiy Signed-off-by: David Gibson --- util/mmap-alloc.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'util/mmap-alloc.c') diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 2f55f5e94f..3ec029a9ea 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -40,6 +40,31 @@ size_t qemu_fd_getpagesize(int fd) return getpagesize(); } +size_t qemu_mempath_getpagesize(const char *mem_path) +{ +#ifdef CONFIG_LINUX + 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 (fs.f_type == HUGETLBFS_MAGIC) { + /* It's hugepage, return the huge page size */ + return fs.f_bsize; + } +#endif + + return getpagesize(); +} + void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared) { /* -- cgit v1.2.1