Consolidate PartitionAlloc TLS into a single structure. [chromium/src : main]

0 views
Skip to first unread message

Mikihito Matsuura (Gerrit)

unread,
Jul 18, 2026, 5:53:57 PM (14 hours ago) Jul 18
to android-bu...@system.gserviceaccount.com, Chromium LUCI CQ, chromium...@chromium.org, Kentaro Hara, glazuno...@chromium.org, grt+...@chromium.org, mpdento...@chromium.org, chrome-b...@google.com, jessemcke...@google.com, roblia...@chromium.org, bartek...@chromium.org, lize...@chromium.org, lizeb...@chromium.org, wfh+...@chromium.org
Attention needed from Mikihito Matsuura

Mikihito Matsuura voted and added 6 comments

Votes added by Mikihito Matsuura

Commit-Queue+1

6 comments

File base/allocator/partition_allocator/src/partition_alloc/internal/partition_root_internal.h
Line 1820, Patchset 29 (Latest): GetThreadCache(size_details.bucket_index);
Mikihito Matsuura . unresolved

Passing `size_details.bucket_index` here is likely a mistake because it restricts the ThreadCache lookup based on the size of the allocation. The `SchedulerLoopQuarantine` branch has its own size limits and is completely decoupled from the ThreadCache bucket limits.\n\nIn `Free()` (line 710), you are correctly using `GetThreadCache()` (which defaults to bucket 0) to get the quarantine branch, so this should also use `GetThreadCache()` to be consistent and ensure large allocations check the correct branch.

File base/allocator/partition_allocator/src/partition_alloc/internal/thread_cache_internal.h
Line 387, Patchset 29 (Latest): uint16_t active_bucket_count_ = 0;
Mikihito Matsuura . unresolved

`active_bucket_count_` is read in the fast path `ThreadCache::Get()` without locks, but can be updated concurrently by `ThreadCacheRegistry::SetActiveBucketCount`. This constitutes a data race, which is Undefined Behavior in C++.\n\nConsider using `std::atomic<uint16_t>` with `std::memory_order_relaxed` here to avoid tearing and conform to the C++ memory model.

File base/allocator/partition_allocator/src/partition_alloc/internal/tls_win.cc
Line 62, Patchset 29 (Latest): }
Mikihito Matsuura . unresolved

Adding `|| IsTombstone(value)` here is recommended to mirror the POSIX implementation. If `PartitionTlsOnThreadExit` is somehow called again when the key is already tombstoned (e.g., during teardown after test execution), `value` could be `kTombstone`, bypassing the null check and crashing later on `PA_DCHECK`.

Line 70, Patchset 29 (Latest): PartitionTlsSet(g_tls_key, nullptr);
Mikihito Matsuura . unresolved

This should be set to `kTombstone` instead of `nullptr`, matching the POSIX implementation.\nSetting it to `nullptr` means that any calls to `GetTls()` during `~ThreadCache()` on component builds will see a null pointer and trigger `GetTlsSlowPath()`, which will improperly allocate a new `Tls` structure during thread destruction.\n\nAlso, `g_tls.state = TlsState::kTombstone;` should be moved here before the loop, so that non-component builds correctly return `nullptr` from `GetTls()` during destruction.

Line 86, Patchset 29 (Latest): PartitionTlsSet(g_tls_key, reinterpret_cast<void*>(
Mikihito Matsuura . unresolved

If you move `g_tls.state = TlsState::kTombstone;` and set `g_tls_key` to `kTombstone` before the loop, you can remove this block and the duplicate `PartitionTlsSet` call at the end of the function.

File base/allocator/partition_allocator/src/partition_alloc/thread_cache.cc
Line 512, Patchset 29 (Latest): active_bucket_count_ = ThreadCacheRegistry::Instance().active_bucket_count_;
Mikihito Matsuura . unresolved

Reading `active_bucket_count_` here outside of the registry lock causes a race condition. If `ThreadCacheRegistry::SetActiveBucketCount` runs between this read and `RegisterThreadCache`, this new thread cache will miss the update and retain the old `active_bucket_count_` indefinitely since it's not yet in the list.\n\nYou should set the thread cache's `active_bucket_count_` inside `RegisterThreadCache()` while holding the lock, rather than doing it here.

Open in Gerrit

Related details

Attention is currently required from:
  • Mikihito Matsuura
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I6135ae95ab55fe15365fb74bc7c2a8b34469bc49
Gerrit-Change-Number: 8097911
Gerrit-PatchSet: 29
Gerrit-Owner: Mikihito Matsuura <mi...@google.com>
Gerrit-Reviewer: Mikihito Matsuura <mi...@google.com>
Gerrit-CC: Kentaro Hara <har...@chromium.org>
Gerrit-Attention: Mikihito Matsuura <mi...@google.com>
Gerrit-Comment-Date: Sat, 18 Jul 2026 21:53:19 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages