From 84b3dd5af7ebef1a2c9cdcb04e771982a7e627d7 Mon Sep 17 00:00:00 2001 From: Chris Kennelly CA Date: Tue, 8 Sep 2026 10:28:51 -0700 Subject: [PATCH] Fix off-by-one slab prefetch offset in x86-64 TcmallocSlab::Pop. Because current holds the pre-decrement index C (since cl/974318602 replaced dec %[current] with a memory RMW subl $0xffff0001), -16(%[scratch], %[current], 8) loads C - 2 into next. Prefetching scratch + (current - 2) * sizeof(void*) redundantly prefetches C - 2 instead of C - 3. Update x86-64 to prefetch C - 3 to match AArch64. PiperOrigin-RevId: 977988165 --- tcmalloc/internal/percpu_tcmalloc.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tcmalloc/internal/percpu_tcmalloc.h b/tcmalloc/internal/percpu_tcmalloc.h index 31502b42a..085002e5c 100644 --- a/tcmalloc/internal/percpu_tcmalloc.h +++ b/tcmalloc/internal/percpu_tcmalloc.h @@ -864,9 +864,9 @@ inline ABSL_ATTRIBUTE_ALWAYS_INLINE void* TcmallocSlab::Pop( TC_ASSERT(result); TSANAcquire(result); - // The next pop will be from current-1, but because we prefetch the previous - // element we've already just read that, so prefetch current-2. - PrefetchSlabMemory(scratch + (current - 2) * sizeof(void*)); + // The next pop will be from current-2, but because we prefetch the previous + // element we've already just read that, so prefetch current-3. + PrefetchSlabMemory(scratch + (current - 3) * sizeof(void*)); PrefetchNextObject(next); return AssumeNotNull(result); underflow_path: