opcache: scripts loaded from file_cache report memory_consumption 0 (and add nothing to wasted_memory) if their .bin was written while SHM was full
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Ambito
- backend, performance
Direzione di ricerca
Start by reading zend_file_cache_script_load() and how dynamic_members.memory_consumption is restored when a cached script is loaded into SHM. Use the reproduction commands in the issue to create .bin files while SHM is full, then load them with more memory and check opcache_get_status() and invalidation's wasted_memory. Done means loaded scripts report their allocated memory and invalidation accounts for it.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
Description
With opcache.file_cache enabled, a script that cannot be stored in shared memory (SHM full) is compiled and written to the file cache only. Its .bin then carries memory_consumption = 0. When a later process with free SHM loads that .bin into shared memory, the entry keeps reporting memory_consumption: 0 in opcache_get_status(), although it occupies real shared memory.
Two effects:
opcache_get_status()['scripts']under-reports. On a production server (PHP 8.5.4, FPM,memory_consumption=2560), 42,535 of 54,864 cached scripts report 0, and the per-script sum is 419 MB whileused_memoryis 2,558 MB.opcache_invalidate()(and timestamp-based invalidation) of such a script adds 0 towasted_memory. Waste is under-counted,max_wasted_percentageis never reached, and a full cache does not schedule its restart. On the server above, the cache stayed full at 0.07% wasted while files were being updated.
A .bin written with opcache.file_cache_only=1 has the same effect.
Reproduce
<?php
// repro.php
$dir = __DIR__ . '/src';
if (!is_dir($dir)) {
mkdir($dir);
for ($i = 0; $i < 200; $i++) {
$body = "<?php\nfunction f$i() { return [" . implode(',', array_map(fn($n) => "'k{$i}_$n' => $n", range(1, 2000))) . "]; }\n";
file_put_contents("$dir/s$i.php", $body);
}
}
foreach (glob("$dir/*.php") as $f) opcache_compile_file($f);
$s = opcache_get_status(true);
$zero = array_keys(array_filter($s['scripts'], fn($x) => $x['memory_consumption'] === 0));
printf("cache_full=%s cached=%d zero=%d\n", var_export($s['cache_full'], true), count($s['scripts']), count($zero));
if ($zero) {
$w0 = opcache_get_status(false)['memory_usage']['wasted_memory'];
foreach ($zero as $k) opcache_invalidate($k, true);
printf("invalidating the %d zero-size scripts added %d bytes to wasted_memory\n", count($zero), opcache_get_status(false)['memory_usage']['wasted_memory'] - $w0);
}
mkdir fc
O="-n -d opcache.enable_cli=1 -d opcache.file_cache=$PWD/fc -d opcache.interned_strings_buffer=1"
php $O -d opcache.memory_consumption=8 repro.php # pass 1: SHM too small, all .bin files written
php $O -d opcache.memory_consumption=128 repro.php # pass 2: everything fits, loaded from file_cache
Output:
cache_full=false cached=45 zero=0
cache_full=false cached=201 zero=156
invalidating the 156 zero-size scripts added 0 bytes to wasted_memory
Expected: pass 2 reports zero=0, and invalidation adds the scripts' real size to wasted_memory.
Control: running both passes with 128 MB and a fresh file_cache directory gives zero=0 both times, and invalidating a sized script adds its full size to wasted_memory.
Possible cause (not verified against the source)
It looks as if, when a .bin is loaded into SHM in zend_file_cache_script_load(), dynamic_members.memory_consumption is taken from the stored script and never set from the size actually allocated. A script that was never persisted to SHM was stored with 0. Setting it from the allocated size (e.g. ZEND_ALIGNED_SIZE(script->size)) on the SHM path would fix both effects.
PHP Version
PHP 8.5.4 (cli) (built: Oct 19 2026 14:35:18) (NTS)
Operating System
Ubuntu 26.04
- Lingua principale
- C
- Stelle
- 41.8k
- Fork
- 8.6k
- Merge medio
- 2g 15h
- PR unite (30g)
- 125
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di php/php-src
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
ext/openssl: 8.2.31+/8.3.31+ fail to build against OpenSSL 1.0.2 (ASN1_STRING_get0_data in xp_ssl.c)ApertaExtension: openssl Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
php/php-src#25402 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
php/php-src#25397 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
SNMP accepts malformed remote portsForse già presa @somethingwithproof l’ha presa 21 giorni fa. Aperta
Difficoltà 2/5 Mezza giornata Idoneità per principianti 62/100
php/php-src#25137 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
ZIP/ZIPS decode dereferences NULL when the cached libdeflate decompressor can't be allocated (3.5 regression)Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
AcademySoftwareFoundation/openexr#2884 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
python-pillow/Pillow#10590 ·
I maintainer di solito rispondono entro 1 giorno
-
status: needs-triage type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
openwrt/packages#31407 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno