From ced9c522b348880695d787d7323c4e958f711192 Mon Sep 17 00:00:00 2001 From: PeterYang12 Date: Mon, 27 Nov 2023 18:12:02 -0800 Subject: [PATCH] Enhance moving PHP code pages into huge pages The former implementation of huge pages for PHP code segments may fail to map in certain scenarios. For instance, if the initial 'r-x-' segment is not PHP, it will result in a failure to map into huge pages. Consequently, the optimization for huge pages with PHP code will no longer be effective. This patch improves the implementation by accurately matching all 'r-x-' segments until it locates the PHP code segment. Subsequently, it performs the necessary huge page mapping. Signed-off-by: PeterYang12 Reviewed-by: chen-hu-97 --- ext/opcache/ZendAccelerator.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 7201e2e91dfd..b9149fa1fa12 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -3019,11 +3019,16 @@ static void accel_move_code_to_huge_pages(void) long unsigned int start, end, offset, inode; char perm[5], dev[10], name[MAXPATHLEN]; int ret; - - while (1) { - ret = fscanf(f, "%lx-%lx %4s %lx %9s %lu %s\n", &start, &end, perm, &offset, dev, &inode, name); - if (ret == 7) { - if (perm[0] == 'r' && perm[1] == '-' && perm[2] == 'x' && name[0] == '/') { + extern char *__progname; + char buffer[MAXPATHLEN]; + + while (fgets(buffer, MAXPATHLEN, f)) { + ret = sscanf(buffer, "%lx-%lx %4s %lx %9s %lu %s\n", &start, &end, perm, &offset, dev, &inode, name); + if (ret >= 6) { + /* try to find the php text segment and map it into huge pages + Lines without 'name' are going to be skipped */ + if (ret > 6 && perm[0] == 'r' && perm[1] == '-' && perm[2] == 'x' && name[0] == '/' \ + && strstr(name, __progname)) { long unsigned int seg_start = ZEND_MM_ALIGNED_SIZE_EX(start, huge_page_size); long unsigned int seg_end = (end & ~(huge_page_size-1L)); long unsigned int real_end; @@ -3042,8 +3047,6 @@ static void accel_move_code_to_huge_pages(void) } break; } - } else { - break; } } fclose(f);