[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-cvs
Subject:    [PHP-CVS] [php-src] master: Support zend alloc USE_ZEND_ALLOC_HUGE_PAGES option on MacOS
From:       David CARLIER via Jakub Zelenka <noreply () php ! net>
Date:       2022-04-29 21:17:33
Message-ID: Y1WZdEmrf0oRloXJhfwlfcQgWokh5UoFYgdJ8seA () main ! php ! net
[Download RAW message or body]

Author: David CARLIER (devnexen)
Committer: Jakub Zelenka (bukka)
Date: 2022-04-29T22:12:25+01:00

Commit: https://github.com/php/php-src/commit/31692a16af0685979286b064b87e41dba987e7b1
Raw diff: https://github.com/php/php-src/commit/31692a16af0685979286b064b87e41dba987e7b1.diff

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.

Changed paths:
  M  NEWS
  M  Zend/zend_alloc.c


Diff:

diff --git a/NEWS b/NEWS
index 580b8ba811b0..8599a72c5545 100644
--- a/NEWS
+++ b/NEWS
@@ -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)
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c
index e2d06c1762dd..3511c48a76f5 100644
--- a/Zend/zend_alloc.c
+++ b/Zend/zend_alloc.c
@@ -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
 }

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic