Repository navigation
Add 2-line write prefetch option in TCMalloc per-CPU slab Pop. - #1942
Draft
copybara-service[bot] wants to merge 1 commit into
Draft
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
`TcmallocSlab::Pop` currently issues a single read-intent prefetch for the first byte of the next object on the per-CPU freelist (`PrefetchNextObject`). Freshly allocated memory is written before it is read—so a shared-state read prefetch still incurs a store-upgrade stall—and allocations spanning multiple cache lines or straddling a cache-line boundary miss on their second cache line. Forward the requested allocation size through `CpuCache::AllocateFast`, `AllocateSlow`, and `AllocateSlowNoHooks` to `TcmallocSlab::Pop` and, when compiled with `-DTCMALLOC_INTERNAL_WRITE_PREFETCH=1` (disabled by default for rollout), issue write-intent prefetches (`PrefetchWT0`) at `prefetch_target` and branchlessly (`CMOV`/`CSEL`) at `prefetch_target + std::min<uint32_t>(size, ABSL_CACHELINE_SIZE + 1) - 1`. Single-line objects prefetch the same line (or a straddled second line), larger objects prefetch the second cache line, and test-only `CpuCache::Allocate` passes the size-class size. Add the `write_prefetch` build and test variant to cover the enabled path. PiperOrigin-RevId: 1020697409
copybara-service
Bot
force-pushed
the
test_1020697409
branch
from
November 18, 2026 16:27
f4b016e to
878dc13
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add 2-line write prefetch option in TCMalloc per-CPU slab Pop.
TcmallocSlab::Popcurrently issues a single read-intent prefetch for the first byte of the next object on the per-CPU freelist (PrefetchNextObject). Freshly allocated memory is written before it is read—so a shared-state read prefetch still incurs a store-upgrade stall—and allocations spanning multiple cache lines or straddling a cache-line boundary miss on their second cache line.Forward the requested allocation size through
CpuCache::AllocateFast,AllocateSlow, andAllocateSlowNoHookstoTcmallocSlab::Popand, when compiled with-DTCMALLOC_INTERNAL_WRITE_PREFETCH=1(disabled by default for rollout), issue write-intent prefetches (PrefetchWT0) atprefetch_targetand branchlessly (CMOV/CSEL) atprefetch_target + std::min<uint32_t>(size, ABSL_CACHELINE_SIZE + 1) - 1. Single-line objects prefetch the same line (or a straddled second line), larger objects prefetch the second cache line, and test-onlyCpuCache::Allocatepasses the size-class size. Add thewrite_prefetchbuild and test variant to cover the enabled path.