PA: Remove thread_local in parition_alloc_base PlatformThread::CurrentId
This change removes the thread_local caching mechanism for thread IDs
within partition_alloc::internal::base::PlatformThread::CurrentId.
While base/threading/platform_thread_posix.cc utilizes thread_local for
caching, doing so within PartitionAlloc's context can lead to reentrancy
issues, because accessing thread_local storage can trigger calls to the
underlying memory allocator. This reentrancy was observed to cause
crashes, particularly with multiple ThreadCache support, as detailed in
b/476192650. Here, PlatformThread::CurrentId() is called in the
ThreadCache constructor within ThreadCache::Create.
partition_alloc::internal::base::PlatformThread::CurrentId is called
relatively infrequently compared to the general
base::PlatformThread::CurrentId.
- During ThreadCache::Create (a few times per thread, unless we support tens of thread caches per thread).
- In NotifyThreadCreated/NotifyThreadDestoyed.
- In GetStackEnd (only when dumping stack trace).
Thus, the performance benefit provided by thread_local is outweighed by
the risks associated with potential allocator reentrancy.
Bug: 476192650
Change-Id: Id597dcab3d98462746a80eb8f83a5372c05e424d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7488430
Reviewed-by: Benoit Lize <lizeb@chromium.org>
Commit-Queue: Ayumi Ono <ayumiohno@google.com>
Reviewed-by: Stephen Nusko <nuskos@chromium.org>
Reviewed-by: Mikihito Matsuura <mikt@google.com>
Cr-Commit-Position: refs/heads/main@{#1571955}
NOKEYCHECK=True
GitOrigin-RevId: 447f4d309c4a18d2123f16004d24e1eadd2c4fd5
1 file changed