Skip to content

JIT: Fix state left by killed processes - #25842

Open
dunglas wants to merge 2 commits into
php:PHP-8.4from
dunglas:fix/opcache-kill-safety-2
Open

dunglas wants to merge 2 commits into
php:PHP-8.4from
dunglas:fix/opcache-kill-safety-2

Conversation

@dunglas

@dunglas dunglas commented Nov 27, 2026

Copy link
Copy Markdown
Member

In #25785 (review), @arnaud-lb pointed out some more places where a process killed in the middle of an update leaves the shm of OPcache half updated.

This PR fixes them, and one more in the tracing JIT.
Two other cases are handled by #25258 #25509.

Problems have been reproduced using GDB (breaking and sending the signal) with FPM, and fixes work as expected.

This is part of the reliability work to remove Zend Signals: #25627

This needs a careful review because I'm not familiar with this part of the code base and this is tricky to get right.

When the JIT runs out of root traces, zend_jit_stop_counter_handlers()
restores the original VM handlers of every cached script. It set
jit_counters_stopped before doing so. If the process was killed in the
loop, by SIGKILL or the OOM killer, later calls returned early and the
remaining counting handlers stayed until the next restart: each hot
loop or function still entered the tracer once before being
blacklisted, and the cold ones kept paying for the counters.

Set the flag after the loop, which can safely run again.

Reported by Arnaud Le Blanc in php#25785.

/* Clean up used op_arrays */
while (num_op_arrays > 0) {
op_array = op_arrays[--num_op_arrays];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like op_arrays is unused after this change, so we could remove it in master.

Comment thread ext/opcache/jit/zend_jit.c Resolved
Comment thread ext/opcache/jit/zend_jit.c Resolved
Comment thread ext/opcache/jit/zend_jit_trace.c Resolved
Comment thread ext/opcache/jit/zend_jit_trace.c Resolved
Comment thread ext/opcache/jit/zend_jit_trace.c Resolved
The JIT builds the SSA, call graph and return info of the functions it
compiles in their func_info in shared memory, from process-local arena
memory, and clears them once done. The function JIT does so with the
triggers that compile at run time (first execution, profiling or hot
counters), the tracing JIT for every function a trace goes through. If
the process was killed in between, by SIGKILL or the OOM killer, these
func_infos kept pointers into the arena of the dead process until the
server was restarted. Compiling a caller of such a function crashed, a
trace entering it took its SSA as already built, and type inference
read its stale return info.

Record each func_info in a list in shared memory before writing to it,
and reset the listed ones at the start and at the end of every
compilation, in all JIT modes. With ZEND_CALL_TREE, the function JIT
writes only to the func_info of the function it compiles, so its
cleanup no longer walks the callees. That walk also cleared
ZEND_FUNC_JITED on every callee, so a worker that waited for the lock
compiled again a callee compiled meanwhile.

Reported by Arnaud Le Blanc in php#25785.
@dunglas
dunglas force-pushed the fix/opcache-kill-safety-2 branch from 281e1a2 to 677d089 Compare November 27, 2026 22:13
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