]> granicus.if.org Git - php/commitdiff
Make MADV_HUGEPAGE conditional on USE_ZEND_ALLOC_HUGE_PAGES
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 18 Feb 2019 13:01:45 +0000 (14:01 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 18 Feb 2019 13:03:07 +0000 (14:03 +0100)
There have been multiple reports of large slowdowns due to the
use of MADV_HUGEPAGE, so make it conditional on
USE_ZEND_ALLOC_HUGE_PAGES, just like MAP_HUGETLB already is.

Zend/zend_alloc.c

index 5b79d3cf0bd52affa9ffe25a22ac65b7acc15a5c..3744a83c84e46adc54b1f3ad71a7ebf9353ecb2d 100644 (file)
@@ -193,9 +193,7 @@ typedef struct  _zend_mm_free_slot zend_mm_free_slot;
 typedef struct  _zend_mm_chunk     zend_mm_chunk;
 typedef struct  _zend_mm_huge_list zend_mm_huge_list;
 
-#ifdef MAP_HUGETLB
 int zend_mm_use_huge_pages = 0;
-#endif
 
 /*
  * Memory is retrived from OS by chunks of fixed size 2MB.
@@ -712,7 +710,9 @@ static void *zend_mm_chunk_alloc_int(size_t size, size_t alignment)
                return NULL;
        } else if (ZEND_MM_ALIGNED_OFFSET(ptr, alignment) == 0) {
 #ifdef MADV_HUGEPAGE
-           madvise(ptr, size, MADV_HUGEPAGE);
+               if (zend_mm_use_huge_pages) {
+                       madvise(ptr, size, MADV_HUGEPAGE);
+               }
 #endif
                return ptr;
        } else {
@@ -743,7 +743,9 @@ static void *zend_mm_chunk_alloc_int(size_t size, size_t alignment)
                        zend_mm_munmap((char*)ptr + size, alignment - REAL_PAGE_SIZE);
                }
 # ifdef MADV_HUGEPAGE
-           madvise(ptr, size, MADV_HUGEPAGE);
+               if (zend_mm_use_huge_pages) {
+                       madvise(ptr, size, MADV_HUGEPAGE);
+               }
 # endif
 #endif
                return ptr;
@@ -2600,8 +2602,9 @@ ZEND_API void shutdown_memory_manager(int silent, int full_shutdown)
 
 static void alloc_globals_ctor(zend_alloc_globals *alloc_globals)
 {
+       char *tmp;
 #if ZEND_MM_CUSTOM
-       char *tmp = getenv("USE_ZEND_ALLOC");
+       tmp = getenv("USE_ZEND_ALLOC");
 
        if (tmp && !zend_atoi(tmp, 0)) {
                alloc_globals->mm_heap = malloc(sizeof(zend_mm_heap));
@@ -2613,12 +2616,10 @@ static void alloc_globals_ctor(zend_alloc_globals *alloc_globals)
                return;
        }
 #endif
-#ifdef MAP_HUGETLB
        tmp = getenv("USE_ZEND_ALLOC_HUGE_PAGES");
        if (tmp && zend_atoi(tmp, 0)) {
                zend_mm_use_huge_pages = 1;
        }
-#endif
        ZEND_TSRMLS_CACHE_UPDATE();
        alloc_globals->mm_heap = zend_mm_init();
 }