Skip to content

Commit 928c422

Browse files
committed
Make MADV_HUGEPAGE conditional on USE_ZEND_ALLOC_HUGE_PAGES
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.
1 parent de73849 commit 928c422

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Zend/zend_alloc.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ typedef struct _zend_mm_free_slot zend_mm_free_slot;
193193
typedef struct _zend_mm_chunk zend_mm_chunk;
194194
typedef struct _zend_mm_huge_list zend_mm_huge_list;
195195

196-
#ifdef MAP_HUGETLB
197196
int zend_mm_use_huge_pages = 0;
198-
#endif
199197

200198
/*
201199
* 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)
712710
return NULL;
713711
} else if (ZEND_MM_ALIGNED_OFFSET(ptr, alignment) == 0) {
714712
#ifdef MADV_HUGEPAGE
715-
madvise(ptr, size, MADV_HUGEPAGE);
713+
if (zend_mm_use_huge_pages) {
714+
madvise(ptr, size, MADV_HUGEPAGE);
715+
}
716716
#endif
717717
return ptr;
718718
} else {
@@ -743,7 +743,9 @@ static void *zend_mm_chunk_alloc_int(size_t size, size_t alignment)
743743
zend_mm_munmap((char*)ptr + size, alignment - REAL_PAGE_SIZE);
744744
}
745745
# ifdef MADV_HUGEPAGE
746-
madvise(ptr, size, MADV_HUGEPAGE);
746+
if (zend_mm_use_huge_pages) {
747+
madvise(ptr, size, MADV_HUGEPAGE);
748+
}
747749
# endif
748750
#endif
749751
return ptr;
@@ -2600,8 +2602,9 @@ ZEND_API void shutdown_memory_manager(int silent, int full_shutdown)
26002602

26012603
static void alloc_globals_ctor(zend_alloc_globals *alloc_globals)
26022604
{
2605+
char *tmp;
26032606
#if ZEND_MM_CUSTOM
2604-
char *tmp = getenv("USE_ZEND_ALLOC");
2607+
tmp = getenv("USE_ZEND_ALLOC");
26052608

26062609
if (tmp && !zend_atoi(tmp, 0)) {
26072610
alloc_globals->mm_heap = malloc(sizeof(zend_mm_heap));
@@ -2613,12 +2616,10 @@ static void alloc_globals_ctor(zend_alloc_globals *alloc_globals)
26132616
return;
26142617
}
26152618
#endif
2616-
#ifdef MAP_HUGETLB
26172619
tmp = getenv("USE_ZEND_ALLOC_HUGE_PAGES");
26182620
if (tmp && zend_atoi(tmp, 0)) {
26192621
zend_mm_use_huge_pages = 1;
26202622
}
2621-
#endif
26222623
ZEND_TSRMLS_CACHE_UPDATE();
26232624
alloc_globals->mm_heap = zend_mm_init();
26242625
}

0 commit comments

Comments
 (0)