diff options
author | Maria Matejka <mq@ucw.cz> | 2022-03-09 09:13:31 +0100 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2022-03-09 09:13:31 +0100 |
commit | 0c59f7ff0112abd1261afb8f21b7c00fc5e37885 (patch) | |
tree | 729362d6345c02a59c1b46ae777b039873dd040e /sysdep/unix | |
parent | c20506dc07e1b99cf1d9f2cf9d00e9211cd9e2f4 (diff) |
Revert "Bound allocated pages to resource pools with page caches to avoid unnecessary syscalls"
This reverts commit 7f0e59820899c30a243c18556ce2e3fb72d6d221.
Diffstat (limited to 'sysdep/unix')
-rw-r--r-- | sysdep/unix/alloc.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/sysdep/unix/alloc.c b/sysdep/unix/alloc.c index f6296afe..c525f713 100644 --- a/sysdep/unix/alloc.c +++ b/sysdep/unix/alloc.c @@ -16,36 +16,41 @@ #include <sys/mman.h> #endif -long page_size = 0; - #ifdef HAVE_MMAP +static u64 page_size = 0; static _Bool use_fake = 0; #else -static _Bool use_fake = 1; +static const u64 page_size = 4096; /* Fake page size */ #endif -void resource_sys_init(void) +u64 get_page_size(void) { -#ifdef HAVE_MMAP - if (!(page_size = sysconf(_SC_PAGESIZE))) - die("System page size must be non-zero"); + if (page_size) + return page_size; - if ((u64_popcount(page_size) > 1) || (page_size > 16384)) +#ifdef HAVE_MMAP + if (page_size = sysconf(_SC_PAGESIZE)) { -#endif - /* Too big or strange page, use the aligned allocator instead */ - page_size = 4096; - use_fake = 1; + if ((u64_popcount(page_size) > 1) || (page_size > 16384)) + { + /* Too big or strange page, use the aligned allocator instead */ + page_size = 4096; + use_fake = 1; + } + return page_size; } + + bug("Page size must be non-zero"); +#endif } void * -alloc_sys_page(void) +alloc_page(void) { #ifdef HAVE_MMAP if (!use_fake) { - void *ret = mmap(NULL, page_size, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + void *ret = mmap(NULL, get_page_size(), PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (ret == MAP_FAILED) bug("mmap(%lu) failed: %m", page_size); return ret; @@ -61,12 +66,12 @@ alloc_sys_page(void) } void -free_sys_page(void *ptr) +free_page(void *ptr) { #ifdef HAVE_MMAP if (!use_fake) { - if (munmap(ptr, page_size) < 0) + if (munmap(ptr, get_page_size()) < 0) bug("munmap(%p) failed: %m", ptr); } else |