Skip to content

Commit 404f1d3

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix phpGH-11715: opcache.interned_strings_buffer either has no effect or opcache_get_status() / phpinfo() is wrong
2 parents 88fab26 + ee3f932 commit 404f1d3

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ PHP NEWS
99
. Fix use-of-uninitialized-value in hash_pbkdf2(), fix missing $options
1010
parameter in signature. (ilutov)
1111

12+
- Opcache:
13+
. Fixed bug GH-11715 (opcache.interned_strings_buffer either has no effect or
14+
opcache_get_status() / phpinfo() is wrong). (nielsdos)
15+
1216
03 Aug 2023, PHP 8.2.9
1317

1418
- Build:

ext/opcache/ZendAccelerator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,7 +2858,7 @@ static int zend_accel_init_shm(void)
28582858
zend_shared_alloc_lock();
28592859

28602860
if (ZCG(accel_directives).interned_strings_buffer) {
2861-
accel_shared_globals_size = ZCG(accel_directives).interned_strings_buffer * 1024 * 1024;
2861+
accel_shared_globals_size = sizeof(zend_accel_shared_globals) + ZCG(accel_directives).interned_strings_buffer * 1024 * 1024;
28622862
} else {
28632863
/* Make sure there is always at least one interned string hash slot,
28642864
* so the table can be queried unconditionally. */
@@ -2899,7 +2899,7 @@ static int zend_accel_init_shm(void)
28992899
ZCSG(interned_strings).top =
29002900
ZCSG(interned_strings).start;
29012901
ZCSG(interned_strings).end =
2902-
(zend_string*)((char*)accel_shared_globals +
2902+
(zend_string*)((char*)(accel_shared_globals + 1) + /* table data is stored after accel_shared_globals */
29032903
ZCG(accel_directives).interned_strings_buffer * 1024 * 1024);
29042904
ZCSG(interned_strings).saved_top = NULL;
29052905

ext/opcache/tests/gh11715.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
GH-11715 (opcache.interned_strings_buffer either has no effect or opcache_get_status() / phpinfo() is wrong)
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable=1
7+
opcache.enable_cli=1
8+
opcache.interned_strings_buffer=16
9+
--FILE--
10+
<?php
11+
12+
$info = opcache_get_status()['interned_strings_usage'];
13+
var_dump($info['used_memory'] + $info['free_memory']);
14+
var_dump($info['buffer_size']);
15+
16+
?>
17+
--EXPECT--
18+
int(16777216)
19+
int(16777216)

ext/opcache/zend_accelerator_module.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#define STRING_NOT_NULL(s) (NULL == (s)?"":s)
4141
#define MIN_ACCEL_FILES 200
4242
#define MAX_ACCEL_FILES 1000000
43-
#define MAX_INTERNED_STRINGS_BUFFER_SIZE ((zend_long)((UINT32_MAX-PLATFORM_ALIGNMENT)/(1024*1024)))
43+
#define MAX_INTERNED_STRINGS_BUFFER_SIZE ((zend_long)((UINT32_MAX-PLATFORM_ALIGNMENT-sizeof(zend_accel_shared_globals))/(1024*1024)))
4444
#define TOKENTOSTR(X) #X
4545

4646
static zif_handler orig_file_exists = NULL;
@@ -507,7 +507,7 @@ void zend_accel_info(ZEND_MODULE_INFO_FUNC_ARGS)
507507
snprintf(buf, sizeof(buf), "%zu", ZSMMG(wasted_shared_memory));
508508
php_info_print_table_row(2, "Wasted memory", buf);
509509
if (ZCSG(interned_strings).start && ZCSG(interned_strings).end) {
510-
snprintf(buf, sizeof(buf), "%zu", (size_t)((char*)ZCSG(interned_strings).top - (char*)ZCSG(interned_strings).start));
510+
snprintf(buf, sizeof(buf), "%zu", (size_t)((char*)ZCSG(interned_strings).top - (char*)(accel_shared_globals + 1)));
511511
php_info_print_table_row(2, "Interned Strings Used memory", buf);
512512
snprintf(buf, sizeof(buf), "%zu", (size_t)((char*)ZCSG(interned_strings).end - (char*)ZCSG(interned_strings).top));
513513
php_info_print_table_row(2, "Interned Strings Free memory", buf);
@@ -648,8 +648,8 @@ ZEND_FUNCTION(opcache_get_status)
648648
zval interned_strings_usage;
649649

650650
array_init(&interned_strings_usage);
651-
add_assoc_long(&interned_strings_usage, "buffer_size", (char*)ZCSG(interned_strings).end - (char*)ZCSG(interned_strings).start);
652-
add_assoc_long(&interned_strings_usage, "used_memory", (char*)ZCSG(interned_strings).top - (char*)ZCSG(interned_strings).start);
651+
add_assoc_long(&interned_strings_usage, "buffer_size", (char*)ZCSG(interned_strings).end - (char*)(accel_shared_globals + 1));
652+
add_assoc_long(&interned_strings_usage, "used_memory", (char*)ZCSG(interned_strings).top - (char*)(accel_shared_globals + 1));
653653
add_assoc_long(&interned_strings_usage, "free_memory", (char*)ZCSG(interned_strings).end - (char*)ZCSG(interned_strings).top);
654654
add_assoc_long(&interned_strings_usage, "number_of_strings", ZCSG(interned_strings).nNumOfElements);
655655
add_assoc_zval(return_value, "interned_strings_usage", &interned_strings_usage);

0 commit comments

Comments
 (0)