Skip to content

Commit 9f6d44e

Browse files
committed
Move blocking/unblocking of signals out of hot path in ZendAccelerator.c
This code courtesy of Nikita Popov. Apparently, it vastly reduces the performance load of sigprocmask syscalls caused by removal of Zend signal handling.
1 parent 9467fc8 commit 9f6d44e

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,6 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
21182118
return NULL;
21192119
}
21202120

2121-
HANDLE_BLOCK_INTERRUPTIONS();
21222121
SHM_UNPROTECT();
21232122

21242123
/* If script is found then validate_timestamps if option is enabled */
@@ -2167,7 +2166,9 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
21672166

21682167
/* Check the second level cache */
21692168
if (!persistent_script && ZCG(accel_directives).file_cache) {
2169+
HANDLE_BLOCK_INTERRUPTIONS();
21702170
persistent_script = zend_file_cache_script_load(file_handle);
2171+
HANDLE_UNBLOCK_INTERRUPTIONS();
21712172
}
21722173

21732174
/* If script was not found or invalidated by validate_timestamps */
@@ -2181,33 +2182,31 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
21812182
/* No memory left. Behave like without the Accelerator */
21822183
if (ZSMMG(memory_exhausted) || ZCSG(restart_pending)) {
21832184
SHM_PROTECT();
2184-
HANDLE_UNBLOCK_INTERRUPTIONS();
21852185
if (ZCG(accel_directives).file_cache) {
21862186
return file_cache_compile_file(file_handle, type);
21872187
}
21882188
return accelerator_orig_compile_file(file_handle, type);
21892189
}
21902190

21912191
SHM_PROTECT();
2192-
HANDLE_UNBLOCK_INTERRUPTIONS();
21932192
persistent_script = opcache_compile_file(file_handle, type, key, &op_array);
2194-
HANDLE_BLOCK_INTERRUPTIONS();
21952193
SHM_UNPROTECT();
21962194

21972195
/* Try and cache the script and assume that it is returned from_shared_memory.
21982196
* If it isn't compile_and_cache_file() changes the flag to 0
21992197
*/
22002198
from_shared_memory = 0;
22012199
if (persistent_script) {
2200+
HANDLE_BLOCK_INTERRUPTIONS();
22022201
persistent_script = cache_script_in_shared_memory(persistent_script, key, key ? key_length : 0, &from_shared_memory);
2202+
HANDLE_UNBLOCK_INTERRUPTIONS();
22032203
}
22042204

22052205
/* Caching is disabled, returning op_array;
22062206
* or something went wrong during compilation, returning NULL
22072207
*/
22082208
if (!persistent_script) {
22092209
SHM_PROTECT();
2210-
HANDLE_UNBLOCK_INTERRUPTIONS();
22112210
return op_array;
22122211
}
22132212
if (from_shared_memory) {
@@ -2262,10 +2261,9 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
22622261
persistent_script->dynamic_members.last_used = ZCG(request_time);
22632262

22642263
SHM_PROTECT();
2265-
HANDLE_UNBLOCK_INTERRUPTIONS();
22662264

2267-
/* Fetch jit auto globals used in the script before execution */
2268-
if (persistent_script->ping_auto_globals_mask) {
2265+
/* Fetch jit auto globals used in the script before execution */
2266+
if (persistent_script->ping_auto_globals_mask) {
22692267
zend_accel_set_auto_globals(persistent_script->ping_auto_globals_mask);
22702268
}
22712269

0 commit comments

Comments
 (0)