Skip to content

Commit 038adc2

Browse files
Wei Yangbonzini
Wei Yang
authored andcommittedOct 26, 2019
core: replace getpagesize() with qemu_real_host_page_size
There are three page size in qemu: real host page size host page size target page size All of them have dedicate variable to represent. For the last two, we use the same form in the whole qemu project, while for the first one we use two forms: qemu_real_host_page_size and getpagesize(). qemu_real_host_page_size is defined to be a replacement of getpagesize(), so let it serve the role. [Note] Not fully tested for some arch or device. Signed-off-by: Wei Yang <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 5608956 commit 038adc2

25 files changed

+52
-50
lines changed
 

‎accel/kvm/kvm-all.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
/* KVM uses PAGE_SIZE in its definition of KVM_COALESCED_MMIO_MAX. We
5353
* need to use the real host PAGE_SIZE, as that's what KVM will use.
5454
*/
55-
#define PAGE_SIZE getpagesize()
55+
#define PAGE_SIZE qemu_real_host_page_size
5656

5757
//#define DEBUG_KVM
5858

@@ -507,7 +507,7 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,
507507
{
508508
ram_addr_t start = section->offset_within_region +
509509
memory_region_get_ram_addr(section->mr);
510-
ram_addr_t pages = int128_get64(section->size) / getpagesize();
510+
ram_addr_t pages = int128_get64(section->size) / qemu_real_host_page_size;
511511

512512
cpu_physical_memory_set_dirty_lebitmap(bitmap, start, pages);
513513
return 0;
@@ -1841,7 +1841,7 @@ static int kvm_init(MachineState *ms)
18411841
* even with KVM. TARGET_PAGE_SIZE is assumed to be the minimum
18421842
* page size for the system though.
18431843
*/
1844-
assert(TARGET_PAGE_SIZE <= getpagesize());
1844+
assert(TARGET_PAGE_SIZE <= qemu_real_host_page_size);
18451845

18461846
s->sigmask_len = 8;
18471847

‎backends/hostmem.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
304304
#else
305305
size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
306306
{
307-
return getpagesize();
307+
return qemu_real_host_page_size;
308308
}
309309
#endif
310310

‎block.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ size_t bdrv_opt_mem_align(BlockDriverState *bs)
106106
{
107107
if (!bs || !bs->drv) {
108108
/* page size or 4k (hdd sector size) should be on the safe side */
109-
return MAX(4096, getpagesize());
109+
return MAX(4096, qemu_real_host_page_size);
110110
}
111111

112112
return bs->bl.opt_mem_alignment;
@@ -116,7 +116,7 @@ size_t bdrv_min_mem_align(BlockDriverState *bs)
116116
{
117117
if (!bs || !bs->drv) {
118118
/* page size or 4k (hdd sector size) should be on the safe side */
119-
return MAX(4096, getpagesize());
119+
return MAX(4096, qemu_real_host_page_size);
120120
}
121121

122122
return bs->bl.min_mem_alignment;

‎block/file-posix.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
327327
{
328328
BDRVRawState *s = bs->opaque;
329329
char *buf;
330-
size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
330+
size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
331331
size_t alignments[] = {1, 512, 1024, 2048, 4096};
332332

333333
/* For SCSI generic devices the alignment is not really used.
@@ -1136,13 +1136,14 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
11361136

11371137
ret = sg_get_max_segments(s->fd);
11381138
if (ret > 0) {
1139-
bs->bl.max_transfer = MIN(bs->bl.max_transfer, ret * getpagesize());
1139+
bs->bl.max_transfer = MIN(bs->bl.max_transfer,
1140+
ret * qemu_real_host_page_size);
11401141
}
11411142
}
11421143

11431144
raw_probe_alignment(bs, s->fd, errp);
11441145
bs->bl.min_mem_alignment = s->buf_align;
1145-
bs->bl.opt_mem_alignment = MAX(s->buf_align, getpagesize());
1146+
bs->bl.opt_mem_alignment = MAX(s->buf_align, qemu_real_host_page_size);
11461147
}
11471148

11481149
static int check_for_dasd(int fd)
@@ -1705,7 +1706,7 @@ static int allocate_first_block(int fd, size_t max_size)
17051706
size_t write_size = (max_size < MAX_BLOCKSIZE)
17061707
? BDRV_SECTOR_SIZE
17071708
: MAX_BLOCKSIZE;
1708-
size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
1709+
size_t max_align = MAX(MAX_BLOCKSIZE, qemu_real_host_page_size);
17091710
void *buf;
17101711
ssize_t n;
17111712
int ret;

‎block/io.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)
160160
bdrv_merge_limits(&bs->bl, &bs->file->bs->bl);
161161
} else {
162162
bs->bl.min_mem_alignment = 512;
163-
bs->bl.opt_mem_alignment = getpagesize();
163+
bs->bl.opt_mem_alignment = qemu_real_host_page_size;
164164

165165
/* Safe default since most protocols use readv()/writev()/etc */
166166
bs->bl.max_iov = IOV_MAX;

‎block/parallels.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
847847
}
848848
}
849849

850-
s->bat_dirty_block = 4 * getpagesize();
850+
s->bat_dirty_block = 4 * qemu_real_host_page_size;
851851
s->bat_dirty_bmap =
852852
bitmap_new(DIV_ROUND_UP(s->header_size, s->bat_dirty_block));
853853

‎block/qcow2-cache.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void qcow2_cache_table_release(Qcow2Cache *c, int i, int num_tables)
7474
/* Using MADV_DONTNEED to discard memory is a Linux-specific feature */
7575
#ifdef CONFIG_LINUX
7676
void *t = qcow2_cache_get_table_addr(c, i);
77-
int align = getpagesize();
77+
int align = qemu_real_host_page_size;
7878
size_t mem_size = (size_t) c->table_size * num_tables;
7979
size_t offset = QEMU_ALIGN_UP((uintptr_t) t, align) - (uintptr_t) t;
8080
size_t length = QEMU_ALIGN_DOWN(mem_size - offset, align);

‎contrib/vhost-user-gpu/vugbm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct udmabuf_create {
5252
static size_t
5353
udmabuf_get_size(struct vugbm_buffer *buf)
5454
{
55-
return ROUND_UP(buf->width * buf->height * 4, getpagesize());
55+
return ROUND_UP(buf->width * buf->height * 4, qemu_real_host_page_size);
5656
}
5757

5858
static bool

‎exec.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1756,11 +1756,11 @@ long qemu_maxrampagesize(void)
17561756
#else
17571757
long qemu_minrampagesize(void)
17581758
{
1759-
return getpagesize();
1759+
return qemu_real_host_page_size;
17601760
}
17611761
long qemu_maxrampagesize(void)
17621762
{
1763-
return getpagesize();
1763+
return qemu_real_host_page_size;
17641764
}
17651765
#endif
17661766

@@ -2417,7 +2417,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
24172417
new_block->max_length = max_size;
24182418
assert(max_size >= size);
24192419
new_block->fd = -1;
2420-
new_block->page_size = getpagesize();
2420+
new_block->page_size = qemu_real_host_page_size;
24212421
new_block->host = host;
24222422
if (host) {
24232423
new_block->flags |= RAM_PREALLOC;

‎hw/intc/s390_flic_kvm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "migration/qemu-file-types.h"
2626
#include "trace.h"
2727

28-
#define FLIC_SAVE_INITIAL_SIZE getpagesize()
28+
#define FLIC_SAVE_INITIAL_SIZE qemu_real_host_page_size
2929
#define FLIC_FAILED (-1UL)
3030
#define FLIC_SAVEVM_VERSION 1
3131

‎hw/ppc/mac_newworld.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ static void ppc_core99_init(MachineState *machine)
439439
}
440440

441441
/* The NewWorld NVRAM is not located in the MacIO device */
442-
if (kvm_enabled() && getpagesize() > 4096) {
442+
if (kvm_enabled() && qemu_real_host_page_size > 4096) {
443443
/* We can't combine read-write and read-only in a single page, so
444444
move the NVRAM out of ROM again for KVM */
445445
nvram_addr = 0xFFE00000;

‎hw/ppc/spapr_pci.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
19421942
* our memory slot is of page size granularity.
19431943
*/
19441944
if (kvm_enabled()) {
1945-
msi_window_size = getpagesize();
1945+
msi_window_size = qemu_real_host_page_size;
19461946
}
19471947

19481948
memory_region_init_io(&sphb->msiwindow, OBJECT(sphb), &spapr_msi_ops, spapr,

‎hw/rdma/vmw/pvrdma_main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ static void pvrdma_realize(PCIDevice *pdev, Error **errp)
601601
rdma_info_report("Initializing device %s %x.%x", pdev->name,
602602
PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
603603

604-
if (TARGET_PAGE_SIZE != getpagesize()) {
604+
if (TARGET_PAGE_SIZE != qemu_real_host_page_size) {
605605
error_setg(errp, "Target page size must be the same as host page size");
606606
return;
607607
}

‎hw/vfio/spapr.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,15 @@ int vfio_spapr_create_window(VFIOContainer *container,
196196
* bits_per_level is a safe guess of how much we can allocate per level:
197197
* 8 is the current minimum for CONFIG_FORCE_MAX_ZONEORDER and MAX_ORDER
198198
* is usually bigger than that.
199-
* Below we look at getpagesize() as TCEs are allocated from system pages.
199+
* Below we look at qemu_real_host_page_size as TCEs are allocated from
200+
* system pages.
200201
*/
201-
bits_per_level = ctz64(getpagesize()) + 8;
202+
bits_per_level = ctz64(qemu_real_host_page_size) + 8;
202203
create.levels = bits_total / bits_per_level;
203204
if (bits_total % bits_per_level) {
204205
++create.levels;
205206
}
206-
max_levels = (64 - create.page_shift) / ctz64(getpagesize());
207+
max_levels = (64 - create.page_shift) / ctz64(qemu_real_host_page_size);
207208
for ( ; create.levels <= max_levels; ++create.levels) {
208209
ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
209210
if (!ret) {

‎include/exec/ram_addr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
373373
hwaddr addr;
374374
ram_addr_t ram_addr;
375375
unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
376-
unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
376+
unsigned long hpratio = qemu_real_host_page_size / TARGET_PAGE_SIZE;
377377
unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
378378

379379
/* start address is aligned at the start of a word? */

‎include/qemu/osdep.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,9 @@ void qemu_anon_ram_free(void *ptr, size_t size);
423423
# define QEMU_VMALLOC_ALIGN (256 * 4096)
424424
#elif defined(__linux__) && defined(__sparc__)
425425
#include <sys/shm.h>
426-
# define QEMU_VMALLOC_ALIGN MAX(getpagesize(), SHMLBA)
426+
# define QEMU_VMALLOC_ALIGN MAX(qemu_real_host_page_size, SHMLBA)
427427
#else
428-
# define QEMU_VMALLOC_ALIGN getpagesize()
428+
# define QEMU_VMALLOC_ALIGN qemu_real_host_page_size
429429
#endif
430430

431431
#ifdef CONFIG_POSIX

‎migration/migration.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2284,7 +2284,7 @@ static struct rp_cmd_args {
22842284
static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname,
22852285
ram_addr_t start, size_t len)
22862286
{
2287-
long our_host_ps = getpagesize();
2287+
long our_host_ps = qemu_real_host_page_size;
22882288

22892289
trace_migrate_handle_rp_req_pages(rbname, start, len);
22902290

‎migration/postcopy-ram.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis)
308308
return false;
309309
}
310310

311-
if (getpagesize() != ram_pagesize_summary()) {
311+
if (qemu_real_host_page_size != ram_pagesize_summary()) {
312312
bool have_hp = false;
313313
/* We've got a huge page */
314314
#ifdef UFFD_FEATURE_MISSING_HUGETLBFS
@@ -346,7 +346,7 @@ static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)
346346
*/
347347
bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
348348
{
349-
long pagesize = getpagesize();
349+
long pagesize = qemu_real_host_page_size;
350350
int ufd = -1;
351351
bool ret = false; /* Error unless we change it */
352352
void *testarea = NULL;

‎monitor/misc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ static uint64_t vtop(void *ptr, Error **errp)
862862
uint64_t pinfo;
863863
uint64_t ret = -1;
864864
uintptr_t addr = (uintptr_t) ptr;
865-
uintptr_t pagesize = getpagesize();
865+
uintptr_t pagesize = qemu_real_host_page_size;
866866
off_t offset = addr / pagesize * sizeof(pinfo);
867867
int fd;
868868

‎target/ppc/kvm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ void kvm_check_mmu(PowerPCCPU *cpu, Error **errp)
411411
* will be a normal mapping, not a special hugepage one used
412412
* for RAM.
413413
*/
414-
if (getpagesize() < 0x10000) {
414+
if (qemu_real_host_page_size < 0x10000) {
415415
error_setg(errp,
416416
"KVM can't supply 64kiB CI pages, which guest expects");
417417
}

‎tests/vhost-user-bridge.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ vubr_queue_set_started(VuDev *dev, int qidx, bool started)
468468

469469
if (started && vubr->notifier.fd >= 0) {
470470
vu_set_queue_host_notifier(dev, vq, vubr->notifier.fd,
471-
getpagesize(),
472-
qidx * getpagesize());
471+
qemu_real_host_page_size,
472+
qidx * qemu_real_host_page_size);
473473
}
474474

475475
if (qidx % 2 == 1) {
@@ -594,7 +594,7 @@ static void *notifier_thread(void *arg)
594594
{
595595
VuDev *dev = (VuDev *)arg;
596596
VubrDev *vubr = container_of(dev, VubrDev, vudev);
597-
int pagesize = getpagesize();
597+
int pagesize = qemu_real_host_page_size;
598598
int qidx;
599599

600600
while (true) {
@@ -630,7 +630,7 @@ vubr_host_notifier_setup(VubrDev *dev)
630630
void *addr;
631631
int fd;
632632

633-
length = getpagesize() * VHOST_USER_BRIDGE_MAX_QUEUES;
633+
length = qemu_real_host_page_size * VHOST_USER_BRIDGE_MAX_QUEUES;
634634

635635
fd = mkstemp(template);
636636
if (fd < 0) {

‎util/mmap-alloc.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ size_t qemu_fd_getpagesize(int fd)
4848
#endif
4949
#endif
5050

51-
return getpagesize();
51+
return qemu_real_host_page_size;
5252
}
5353

5454
size_t qemu_mempath_getpagesize(const char *mem_path)
@@ -79,7 +79,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
7979
#endif
8080
#endif
8181

82-
return getpagesize();
82+
return qemu_real_host_page_size;
8383
}
8484

8585
void *qemu_ram_mmap(int fd,
@@ -114,7 +114,7 @@ void *qemu_ram_mmap(int fd,
114114
*/
115115
flags = MAP_PRIVATE;
116116
pagesize = qemu_fd_getpagesize(fd);
117-
if (fd == -1 || pagesize == getpagesize()) {
117+
if (fd == -1 || pagesize == qemu_real_host_page_size) {
118118
guardfd = -1;
119119
flags |= MAP_ANONYMOUS;
120120
} else {
@@ -123,7 +123,7 @@ void *qemu_ram_mmap(int fd,
123123
}
124124
#else
125125
guardfd = -1;
126-
pagesize = getpagesize();
126+
pagesize = qemu_real_host_page_size;
127127
flags = MAP_PRIVATE | MAP_ANONYMOUS;
128128
#endif
129129

@@ -205,7 +205,7 @@ void qemu_ram_munmap(int fd, void *ptr, size_t size)
205205
#if defined(__powerpc64__) && defined(__linux__)
206206
pagesize = qemu_fd_getpagesize(fd);
207207
#else
208-
pagesize = getpagesize();
208+
pagesize = qemu_real_host_page_size;
209209
#endif
210210
munmap(ptr, size + pagesize);
211211
}

‎util/oslib-posix.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ void *qemu_alloc_stack(size_t *sz)
617617
#ifdef CONFIG_DEBUG_STACK_USAGE
618618
void *ptr2;
619619
#endif
620-
size_t pagesz = getpagesize();
620+
size_t pagesz = qemu_real_host_page_size;
621621
#ifdef _SC_THREAD_STACK_MIN
622622
/* avoid stacks smaller than _SC_THREAD_STACK_MIN */
623623
long min_stack_sz = sysconf(_SC_THREAD_STACK_MIN);
@@ -679,7 +679,7 @@ void qemu_free_stack(void *stack, size_t sz)
679679
unsigned int usage;
680680
void *ptr;
681681

682-
for (ptr = stack + getpagesize(); ptr < stack + sz;
682+
for (ptr = stack + qemu_real_host_page_size; ptr < stack + sz;
683683
ptr += sizeof(uint32_t)) {
684684
if (*(uint32_t *)ptr != 0xdeadbeaf) {
685685
break;

‎util/oslib-win32.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ void os_mem_prealloc(int fd, char *area, size_t memory, int smp_cpus,
554554
Error **errp)
555555
{
556556
int i;
557-
size_t pagesize = getpagesize();
557+
size_t pagesize = qemu_real_host_page_size;
558558

559559
memory = (memory + pagesize - 1) & -pagesize;
560560
for (i = 0; i < memory / pagesize; i++) {

0 commit comments

Comments
 (0)