Skip to content

Commit 5b033b0

Browse files
committed
Fix zend_jit_stop_counter_handlers() performance issues with protect_memory=1
The function repeatedly calls mprotect() which is extremely slow. In our community build, the Laravel tests went from ~6 minutes to ~4 hours. This issue only occurs with opcache.protect_memory=1. Closes GH-11323
1 parent af72727 commit 5b033b0

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7175,8 +7175,6 @@ static void zend_jit_stop_hot_trace_counters(zend_op_array *op_array)
71757175
uint32_t i;
71767176

71777177
jit_extension = (zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(op_array);
7178-
zend_shared_alloc_lock();
7179-
SHM_UNPROTECT();
71807178
for (i = 0; i < op_array->last; i++) {
71817179
/* Opline with Jit-ed code handler is skipped. */
71827180
if (jit_extension->trace_info[i].trace_flags &
@@ -7188,8 +7186,6 @@ static void zend_jit_stop_hot_trace_counters(zend_op_array *op_array)
71887186
op_array->opcodes[i].handler = jit_extension->trace_info[i].orig_handler;
71897187
}
71907188
}
7191-
SHM_PROTECT();
7192-
zend_shared_alloc_unlock();
71937189
}
71947190

71957191
/* Get the tracing op_array. */
@@ -7228,6 +7224,9 @@ static void zend_jit_stop_persistent_script(zend_persistent_script *script)
72287224
/* Get all scripts which are accelerated by JIT */
72297225
static void zend_jit_stop_counter_handlers(void)
72307226
{
7227+
zend_shared_alloc_lock();
7228+
/* mprotect has an extreme overhead, avoid calls to it for every function. */
7229+
SHM_UNPROTECT();
72317230
for (uint32_t i = 0; i < ZCSG(hash).max_num_entries; i++) {
72327231
zend_accel_hash_entry *cache_entry;
72337232
for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) {
@@ -7237,6 +7236,8 @@ static void zend_jit_stop_counter_handlers(void)
72377236
zend_jit_stop_persistent_script(script);
72387237
}
72397238
}
7239+
SHM_PROTECT();
7240+
zend_shared_alloc_unlock();
72407241
}
72417242

72427243
static void zend_jit_blacklist_root_trace(const zend_op *opline, size_t offset)

0 commit comments

Comments
 (0)