Skip to content

Fix GH-9812: memory leak on repeated include with file_cache_only=1#22107

Open
pronskiy wants to merge 1 commit into
php:masterfrom
pronskiy:fix/gh-9812
Open

Fix GH-9812: memory leak on repeated include with file_cache_only=1#22107
pronskiy wants to merge 1 commit into
php:masterfrom
pronskiy:fix/gh-9812

Conversation

@pronskiy
Copy link
Copy Markdown
Member

With opcache.file_cache_only=1 every include allocates a fresh arena in zend_file_cache_script_load() and it leaks. Looks like zend_arena_release() only runs when cache_it is set, which is the SHM path. CG(arena) only resets at request shutdown, so I think memory just keeps growing.

My attempt: per-request hashtable in ZCG mapping resolved path -> zend_persistent_script. First include fills it, next ones should reuse the arena allocation. Freeing it in accel_post_deactivate seems to work since it runs before zend_arena_destroy and shutdown_memory_manager, so entries and buckets should still be alive.

Fixed GH-9812
Closes GH-9812

With opcache.file_cache_only=1 every include allocates a fresh
arena in zend_file_cache_script_load() and it leaks. Looks like
zend_arena_release() only runs when cache_it is set, which is the SHM
path. CG(arena) only resets at request shutdown, so I think memory just
keeps growing.

My attempt: per-request hashtable in ZCG, resolved path ->
zend_persistent_script. First include fills it, next ones should reuse
the arena allocation. Freeing it in
accel_post_deactivate seems to work since it runs before
zend_arena_destroy and shutdown_memory_manager, so entries and buckets
should still be alive.

Fixed phpGH-9812
Closes phpGH-9812
@pronskiy pronskiy marked this pull request as ready for review May 21, 2026 14:36
@pronskiy pronskiy requested a review from dstogov as a code owner May 21, 2026 14:36
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.

memory usage increasing when using opcache.enable_cli and opcache.file_cache_only

1 participant