Skip to content

Commit 31692a1

Browse files
devnexenbukka
authored andcommitted
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.
1 parent 5147f4c commit 31692a1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ PHP NEWS
99
. Fixed bug #81380 (Observer may not be initialized properly). (krakjoe)
1010
. Fixed bug GH-7771 (Fix filename/lineno of constant expressions). (ilutov)
1111
. Fixed bug GH-7792 (Improve class type in error messages). (ilutov)
12+
. Support huge pages on MacOS. (David CARLIER)
1213

1314
- Curl:
1415
. Added support for CURLOPT_XFERINFOFUNCTION. (David Carlier)

Zend/zend_alloc.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,16 @@ static void *zend_mm_mmap(size_t size)
464464
#else
465465
void *ptr;
466466

467-
#ifdef MAP_HUGETLB
467+
#if defined(MAP_HUGETLB) || defined(VM_FLAGS_SUPERPAGE_SIZE_2MB)
468468
if (zend_mm_use_huge_pages && size == ZEND_MM_CHUNK_SIZE) {
469-
ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_HUGETLB, -1, 0);
469+
int fd = -1;
470+
int mflags = MAP_PRIVATE | MAP_ANON;
471+
#if defined(MAP_HUGETLB)
472+
mflags |= MAP_HUGETLB;
473+
#else
474+
fd = VM_FLAGS_SUPERPAGE_SIZE_2MB;
475+
#endif
476+
ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, mflags, fd, 0);
470477
if (ptr != MAP_FAILED) {
471478
return ptr;
472479
}
@@ -671,7 +678,7 @@ static zend_always_inline void zend_mm_hugepage(void* ptr, size_t size)
671678
#elif defined(HAVE_MEMCNTL)
672679
struct memcntl_mha m = {.mha_cmd = MHA_MAPSIZE_VA, .mha_pagesize = ZEND_MM_CHUNK_SIZE, .mha_flags = 0};
673680
(void)memcntl(ptr, size, MC_HAT_ADVISE, (char *)&m, 0, 0);
674-
#else
681+
#elif !defined(VM_FLAGS_SUPERPAGE_SIZE_2MB) && !defined(MAP_ALIGNED_SUPER)
675682
zend_error_noreturn(E_WARNING, "huge_pages: thp unsupported on this platform");
676683
#endif
677684
}

0 commit comments

Comments
 (0)