Skip to content

Fix GH-25555: Set memory_consumption when loading file_cache script into SHM - #25583

Open
prateekbhujel wants to merge 1 commit into
php:PHP-8.5from
prateekbhujel:fix/gh25555-file-cache-shm-memory-consumption
Open

prateekbhujel wants to merge 1 commit into
php:PHP-8.5from
prateekbhujel:fix/gh25555-file-cache-shm-memory-consumption

Conversation

@prateekbhujel

Copy link
Copy Markdown
Contributor

When a script is written to opcache.file_cache without being stored in shared memory (because SHM was full or opcache.file_cache_only=1 was used), script->dynamic_members.memory_consumption in the serialized .bin file is 0.

When zend_file_cache_script_load_ex() later loads that .bin into shared memory (cache_it == true), set script->dynamic_members.memory_consumption = ZEND_ALIGNED_SIZE(script->size) so opcache_get_status() reports the allocated SHM size and invalidation accounts for it in wasted_memory.

Fixes GH-25555.

…t into SHM

When a script is written to opcache.file_cache without being stored in
shared memory (because SHM was full or opcache.file_cache_only=1 was
active), script->dynamic_members.memory_consumption in the serialized
.bin file is 0.

When zend_file_cache_script_load_ex() later loads that .bin into shared
memory (cache_it == true), initialize
script->dynamic_members.memory_consumption to
ZEND_ALIGNED_SIZE(script->size) so opcache_get_status() reports the
allocated SHM size and invalidation accounts for it in wasted_memory.

Closes phpGH-25555.
@AceMedia

Copy link
Copy Markdown

AI-assisted testing and drafting.

I've tested the one-line change in an isolated PHP 8.5.10 build on Linux aarch64, 64-bit NTS. This is a backport check against the release, rather than a build of the current PR branch.

Before the change, the SHM-full reproducer leaves 156 scripts reporting zero memory after the second pass. Invalidating those scripts adds zero bytes to wasted_memory. With the change, the second pass reports zero zero-size scripts. The fresh 128 MB/128 MB control also remains correct.

The supplied gh25555.phpt changes from failing to passing, including its check that invalidation adds the script's reported allocation to wasted_memory. The existing gh16979 file-cache check passes too. The file-cache permission test was skipped because this minimal build has neither posix nor pcntl.

I also reproduced the original accounting failure on packaged PHP 8.2.35, 8.3.32, 8.4.25 and 8.5.10 on the same machine. I set file_update_protection=0 so newly generated scripts were cached immediately. I haven't checked the patch on the other release branches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants