Skip to content

[WIP] Attempt to fix opcache_reset() races #14803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: PHP-8.2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -2064,6 +2064,8 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
}

if (file_handle->opened_path) {
zend_shared_alloc_lock();

Comment on lines +2067 to +2068
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please think about a different solution. This one should make a big slowdown.

opcache should be able to do lock-free cache lookups.
Probably, the modification of ZCSG(hash) should be done more careful (to keep consistency for concurrent readers)

bucket = zend_accel_hash_find_entry(&ZCSG(hash), file_handle->opened_path);

if (bucket) {
Expand All @@ -2072,13 +2074,13 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
if (key && !persistent_script->corrupted) {
HANDLE_BLOCK_INTERRUPTIONS();
SHM_UNPROTECT();
zend_shared_alloc_lock();
zend_accel_add_key(key, bucket);
zend_shared_alloc_unlock();
SHM_PROTECT();
HANDLE_UNBLOCK_INTERRUPTIONS();
}
}

zend_shared_alloc_unlock();
}
}
}
Expand Down Expand Up @@ -2543,15 +2545,19 @@ static zend_string* persistent_zend_resolve_path(zend_string *filename)
/* lookup by "not-real" path */
key = accel_make_persistent_key(filename);
if (key) {
zend_shared_alloc_lock();
zend_accel_hash_entry *bucket = zend_accel_hash_find_entry(&ZCSG(hash), key);
if (bucket != NULL) {
zend_persistent_script *persistent_script = (zend_persistent_script *)bucket->data;
if (!persistent_script->corrupted) {
ZCG(cache_opline) = EG(current_execute_data) ? EG(current_execute_data)->opline : NULL;
ZCG(cache_persistent_script) = persistent_script;
return zend_string_copy(persistent_script->script.filename);
zend_string *str = zend_string_copy(persistent_script->script.filename);
zend_shared_alloc_unlock();
return str;
}
}
zend_shared_alloc_unlock();
} else {
ZCG(cache_opline) = NULL;
ZCG(cache_persistent_script) = NULL;
Expand All @@ -2564,6 +2570,7 @@ static zend_string* persistent_zend_resolve_path(zend_string *filename)

if (resolved_path) {
/* lookup by real path */
zend_shared_alloc_lock();
zend_accel_hash_entry *bucket = zend_accel_hash_find_entry(&ZCSG(hash), resolved_path);
if (bucket) {
zend_persistent_script *persistent_script = (zend_persistent_script *)bucket->data;
Expand All @@ -2572,19 +2579,19 @@ static zend_string* persistent_zend_resolve_path(zend_string *filename)
/* add another "key" for the same bucket */
HANDLE_BLOCK_INTERRUPTIONS();
SHM_UNPROTECT();
zend_shared_alloc_lock();
zend_accel_add_key(key, bucket);
zend_shared_alloc_unlock();
SHM_PROTECT();
HANDLE_UNBLOCK_INTERRUPTIONS();
} else {
ZSTR_LEN(&ZCG(key)) = 0;
}
zend_shared_alloc_unlock();
ZCG(cache_opline) = EG(current_execute_data) ? EG(current_execute_data)->opline : NULL;
ZCG(cache_persistent_script) = persistent_script;
return resolved_path;
}
}
zend_shared_alloc_unlock();
}

ZCG(cache_opline) = NULL;
Expand Down
Loading