Skip to content

Commit 12ce17c

Browse files
committed
Use HUGE PAGES for opcahce SHM, if available.
1 parent f610712 commit 12ce17c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

ext/opcache/shared_alloc_mmap.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_
4646
shared_segment = (zend_shared_segment *)((char *)(*shared_segments_p) + sizeof(void *));
4747
(*shared_segments_p)[0] = shared_segment;
4848

49+
#ifdef MAP_HUGETLB
50+
/* Try to allocate huge pages first to reduce dTLB misses.
51+
* OS has to be configured properly
52+
* (e.g. https://wiki.debian.org/Hugepages#Enabling_HugeTlbPage)
53+
* You may verify huge page usage with the following command:
54+
* `grep "Huge" /proc/meminfo`
55+
*/
56+
shared_segment->p = mmap(0, requested_size, PROT_READ | PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS|MAP_HUGETLB, -1, 0);
57+
if (shared_segment->p != MAP_FAILED) {
58+
shared_segment->pos = 0;
59+
shared_segment->size = requested_size;
60+
61+
return ALLOC_SUCCESS;
62+
}
63+
#endif
64+
4965
shared_segment->p = mmap(0, requested_size, PROT_READ | PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
5066
if (shared_segment->p == MAP_FAILED) {
5167
*error_in = "mmap";

0 commit comments

Comments
 (0)