perf: ZTS: move AG and SCNG into native __thread storage, replay of #22231#22595
perf: ZTS: move AG and SCNG into native __thread storage, replay of #22231#22595henderkes wants to merge 1 commit into
Conversation
3a4c35a to
31eb0f9
Compare
31eb0f9 to
6287e33
Compare
| /* A __thread block of a foreign thread is inaccessible. */ | ||
| if (resource_types_table[i].tls_addr && !own_thread) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
/* A __thread block of a foreign thread is inaccessible. */
Is that because the thread may not exist anymore, or is there another reason?
We need to ensure that shutdown_memory_manager(CG(unclean_shutdown), 1); is called in php_module_shutdown. Currently we avoid calling it in ZTS builds because we rely on the TSRM dtor, I believe.
I would go as far as removing the dtor argument from ts_allocate_tls_id since it's not going to be called for most threads during tsrm_shutdown().
There was a problem hiding this comment.
Is that because the thread may not exist anymore, or is there another reason?
It's pointing to __thread memory of another thread, but the only way it got here is if a foreign thread already died, so we'd be accessing dangling memory. It's technically accessible but there's no telling what running the dtor would lead to.
We need to ensure that shutdown_memory_manager(CG(unclean_shutdown), 1); is called in php_module_shutdown. Currently we avoid calling it in ZTS builds because we rely on the TSRM dtor, I believe.
Is this a general request? I don't change the main thread shutdown path here (it gets dtor defined and is guaranteed to run its own thread). If it's just a general request, I would postpone that to a follow-up PR.
I would go as far as removing the dtor argument from ts_allocate_tls_id since it's not going to be called for most threads during tsrm_shutdown().
Can't currently do that for AG because it does pass and run the dtor.
So I largely copied the approach of #22231, but this time for AG and SCNG, because they're small in size (256 bytes, so we don't step back into the TLS surplus issue) and I don't need to touch the JIT.
EG and CG are "fine" to keep in the heap storage with the const offsets, because EG is mostly hot in dispatch and the __thread symbol is already kept loaded in the hybrid VM. For clang compile-heavy code still suffers a bit from tsrm_ls_cache base reloads, but I'm still brainstorming for that.
This mostly benefits the lexer and allocations.
@arnaud-lb