Support zend alloc USE_ZEND_ALLOC_HUGE_PAGES option on MacOS

ZEND_MM_CHUNK_SIZE fits the VM_FLAGS_SUPERPAGE_SIZE_2MB special
file descriptor for mmap call.
This commit is contained in:
David CARLIER 2021-12-21 08:29:09 +00:00 committed by Jakub Zelenka
parent 5147f4c6f3
commit 31692a16af
No known key found for this signature in database
GPG key ID: 1C0779DC5C0A9DE4
2 changed files with 11 additions and 3 deletions

1
NEWS
View file

@ -9,6 +9,7 @@ PHP NEWS
. Fixed bug #81380 (Observer may not be initialized properly). (krakjoe)
. Fixed bug GH-7771 (Fix filename/lineno of constant expressions). (ilutov)
. Fixed bug GH-7792 (Improve class type in error messages). (ilutov)
. Support huge pages on MacOS. (David CARLIER)
- Curl:
. Added support for CURLOPT_XFERINFOFUNCTION. (David Carlier)

View file

@ -464,9 +464,16 @@ static void *zend_mm_mmap(size_t size)
#else
void *ptr;
#ifdef MAP_HUGETLB
#if defined(MAP_HUGETLB) || defined(VM_FLAGS_SUPERPAGE_SIZE_2MB)
if (zend_mm_use_huge_pages && size == ZEND_MM_CHUNK_SIZE) {
ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_HUGETLB, -1, 0);
int fd = -1;
int mflags = MAP_PRIVATE | MAP_ANON;
#if defined(MAP_HUGETLB)
mflags |= MAP_HUGETLB;
#else
fd = VM_FLAGS_SUPERPAGE_SIZE_2MB;
#endif
ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, mflags, fd, 0);
if (ptr != MAP_FAILED) {
return ptr;
}
@ -671,7 +678,7 @@ static zend_always_inline void zend_mm_hugepage(void* ptr, size_t size)
#elif defined(HAVE_MEMCNTL)
struct memcntl_mha m = {.mha_cmd = MHA_MAPSIZE_VA, .mha_pagesize = ZEND_MM_CHUNK_SIZE, .mha_flags = 0};
(void)memcntl(ptr, size, MC_HAT_ADVISE, (char *)&m, 0, 0);
#else
#elif !defined(VM_FLAGS_SUPERPAGE_SIZE_2MB) && !defined(MAP_ALIGNED_SUPER)
zend_error_noreturn(E_WARNING, "huge_pages: thp unsupported on this platform");
#endif
}