Skip to content

Commit 566100d

Browse files
authored
Enhance moving PHP code pages into huge pages (#12806)
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. Reviewed-by: chen-hu-97 <hu1.chen@intel.com> Signed-off-by: PeterYang12 <yuhan.yang@intel.com>
1 parent 407fba9 commit 566100d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,11 +3019,16 @@ static void accel_move_code_to_huge_pages(void)
30193019
long unsigned int start, end, offset, inode;
30203020
char perm[5], dev[10], name[MAXPATHLEN];
30213021
int ret;
3022-
3023-
while (1) {
3024-
ret = fscanf(f, "%lx-%lx %4s %lx %9s %lu %s\n", &start, &end, perm, &offset, dev, &inode, name);
3025-
if (ret == 7) {
3026-
if (perm[0] == 'r' && perm[1] == '-' && perm[2] == 'x' && name[0] == '/') {
3022+
extern char *__progname;
3023+
char buffer[MAXPATHLEN];
3024+
3025+
while (fgets(buffer, MAXPATHLEN, f)) {
3026+
ret = sscanf(buffer, "%lx-%lx %4s %lx %9s %lu %s\n", &start, &end, perm, &offset, dev, &inode, name);
3027+
if (ret >= 6) {
3028+
/* try to find the php text segment and map it into huge pages
3029+
Lines without 'name' are going to be skipped */
3030+
if (ret > 6 && perm[0] == 'r' && perm[1] == '-' && perm[2] == 'x' && name[0] == '/' \
3031+
&& strstr(name, __progname)) {
30273032
long unsigned int seg_start = ZEND_MM_ALIGNED_SIZE_EX(start, huge_page_size);
30283033
long unsigned int seg_end = (end & ~(huge_page_size-1L));
30293034
long unsigned int real_end;
@@ -3042,8 +3047,6 @@ static void accel_move_code_to_huge_pages(void)
30423047
}
30433048
break;
30443049
}
3045-
} else {
3046-
break;
30473050
}
30483051
}
30493052
fclose(f);

0 commit comments

Comments
 (0)