mmap-alloc.c (06e64339555096a2bc2d08c7e012b36a9977062c) | mmap-alloc.c (038adc2f5850e32019bda06c559d0301be436eae) |
---|---|
1/* 2 * Support for RAM backed by mmaped host memory. 3 * 4 * Copyright (c) 2015 Red Hat, Inc. 5 * 6 * Authors: 7 * Michael S. Tsirkin <mst@redhat.com> 8 * --- 34 unchanged lines hidden (view full) --- 43 } 44 } 45#ifdef __sparc__ 46 /* SPARC Linux needs greater alignment than the pagesize */ 47 return QEMU_VMALLOC_ALIGN; 48#endif 49#endif 50 | 1/* 2 * Support for RAM backed by mmaped host memory. 3 * 4 * Copyright (c) 2015 Red Hat, Inc. 5 * 6 * Authors: 7 * Michael S. Tsirkin <mst@redhat.com> 8 * --- 34 unchanged lines hidden (view full) --- 43 } 44 } 45#ifdef __sparc__ 46 /* SPARC Linux needs greater alignment than the pagesize */ 47 return QEMU_VMALLOC_ALIGN; 48#endif 49#endif 50 |
51 return getpagesize(); | 51 return qemu_real_host_page_size; |
52} 53 54size_t qemu_mempath_getpagesize(const char *mem_path) 55{ 56#ifdef CONFIG_LINUX 57 struct statfs fs; 58 int ret; 59 --- 14 unchanged lines hidden (view full) --- 74 } 75 } 76#ifdef __sparc__ 77 /* SPARC Linux needs greater alignment than the pagesize */ 78 return QEMU_VMALLOC_ALIGN; 79#endif 80#endif 81 | 52} 53 54size_t qemu_mempath_getpagesize(const char *mem_path) 55{ 56#ifdef CONFIG_LINUX 57 struct statfs fs; 58 int ret; 59 --- 14 unchanged lines hidden (view full) --- 74 } 75 } 76#ifdef __sparc__ 77 /* SPARC Linux needs greater alignment than the pagesize */ 78 return QEMU_VMALLOC_ALIGN; 79#endif 80#endif 81 |
82 return getpagesize(); | 82 return qemu_real_host_page_size; |
83} 84 85void *qemu_ram_mmap(int fd, 86 size_t size, 87 size_t align, 88 bool shared, 89 bool is_pmem) 90{ --- 18 unchanged lines hidden (view full) --- 109 * from the supplied fd, we should make sure to use the same page size, to 110 * this end we mmap the supplied fd. In this case, set MAP_NORESERVE to 111 * avoid allocating backing store memory. 112 * We do this unless we are using the system page size, in which case 113 * anonymous memory is OK. 114 */ 115 flags = MAP_PRIVATE; 116 pagesize = qemu_fd_getpagesize(fd); | 83} 84 85void *qemu_ram_mmap(int fd, 86 size_t size, 87 size_t align, 88 bool shared, 89 bool is_pmem) 90{ --- 18 unchanged lines hidden (view full) --- 109 * from the supplied fd, we should make sure to use the same page size, to 110 * this end we mmap the supplied fd. In this case, set MAP_NORESERVE to 111 * avoid allocating backing store memory. 112 * We do this unless we are using the system page size, in which case 113 * anonymous memory is OK. 114 */ 115 flags = MAP_PRIVATE; 116 pagesize = qemu_fd_getpagesize(fd); |
117 if (fd == -1 || pagesize == getpagesize()) { | 117 if (fd == -1 || pagesize == qemu_real_host_page_size) { |
118 guardfd = -1; 119 flags |= MAP_ANONYMOUS; 120 } else { 121 guardfd = fd; 122 flags |= MAP_NORESERVE; 123 } 124#else 125 guardfd = -1; | 118 guardfd = -1; 119 flags |= MAP_ANONYMOUS; 120 } else { 121 guardfd = fd; 122 flags |= MAP_NORESERVE; 123 } 124#else 125 guardfd = -1; |
126 pagesize = getpagesize(); | 126 pagesize = qemu_real_host_page_size; |
127 flags = MAP_PRIVATE | MAP_ANONYMOUS; 128#endif 129 130 guardptr = mmap(0, total, PROT_NONE, flags, guardfd, 0); 131 132 if (guardptr == MAP_FAILED) { 133 return MAP_FAILED; 134 } --- 65 unchanged lines hidden (view full) --- 200{ 201 size_t pagesize; 202 203 if (ptr) { 204 /* Unmap both the RAM block and the guard page */ 205#if defined(__powerpc64__) && defined(__linux__) 206 pagesize = qemu_fd_getpagesize(fd); 207#else | 127 flags = MAP_PRIVATE | MAP_ANONYMOUS; 128#endif 129 130 guardptr = mmap(0, total, PROT_NONE, flags, guardfd, 0); 131 132 if (guardptr == MAP_FAILED) { 133 return MAP_FAILED; 134 } --- 65 unchanged lines hidden (view full) --- 200{ 201 size_t pagesize; 202 203 if (ptr) { 204 /* Unmap both the RAM block and the guard page */ 205#if defined(__powerpc64__) && defined(__linux__) 206 pagesize = qemu_fd_getpagesize(fd); 207#else |
208 pagesize = getpagesize(); | 208 pagesize = qemu_real_host_page_size; |
209#endif 210 munmap(ptr, size + pagesize); 211 } 212} | 209#endif 210 munmap(ptr, size + pagesize); 211 } 212} |