Skip to content

Commit 7f1fef9

Browse files
devnexennikic
authored andcommitted
Fix opcache huge page mapping on FreeBSD
Too much room were given process mappings and were not unmapped. Closes GH-4345.
1 parent 03846af commit 7f1fef9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,9 +2745,9 @@ static void accel_move_code_to_huge_pages(void)
27452745
size_t s = 0;
27462746
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_VMMAP, getpid()};
27472747
long unsigned int huge_page_size = 2 * 1024 * 1024;
2748-
if(sysctl(mib, 4, NULL, &s, NULL, 0) == 0) {
2748+
if (sysctl(mib, 4, NULL, &s, NULL, 0) == 0) {
27492749
s = s * 4 / 3;
2750-
void *addr = mmap(NULL, s * sizeof (struct kinfo_vmentry), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
2750+
void *addr = mmap(NULL, s, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
27512751
if (addr != MAP_FAILED) {
27522752
if (sysctl(mib, 4, addr, &s, NULL, 0) == 0) {
27532753
uintptr_t start = (uintptr_t)addr;
@@ -2766,11 +2766,14 @@ static void accel_move_code_to_huge_pages(void)
27662766
if (seg_end > seg_start) {
27672767
zend_accel_error(ACCEL_LOG_DEBUG, "remap to huge page %lx-%lx %s \n", seg_start, seg_end, entry->kve_path);
27682768
accel_remap_huge_pages((void*)seg_start, seg_end - seg_start, seg_end - seg_start, entry->kve_path, entry->kve_offset + seg_start - start);
2769+
// First relevant segment found is our binary
2770+
break;
27692771
}
27702772
}
27712773
start += sz;
27722774
}
27732775
}
2776+
munmap(addr, s);
27742777
}
27752778
}
27762779
#endif

0 commit comments

Comments
 (0)