From fe6501ee51bd42cbd600c5923471f62ef0667ec0 Mon Sep 17 00:00:00 2001 From: Chris Kennelly Date: Thu, 9 Jul 2026 12:03:23 -0700 Subject: [PATCH] De-std::atomic Span::allocated_. This prevents the compiler from merging redundant load/store operations. This is especially pronounced on InsertRange, while RemoveRange appears to have enough memory pressure that we will need to spill anyways. Since the turndown of the fragmentation profile, we no longer need to keep `Span::Allocated()` safe for accessing across threads so an ordinary integer will suffice. PiperOrigin-RevId: 945244330 --- tcmalloc/span.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tcmalloc/span.h b/tcmalloc/span.h index a7a90998f..b90a9c33c 100644 --- a/tcmalloc/span.h +++ b/tcmalloc/span.h @@ -304,7 +304,18 @@ class ABSL_CACHELINE_ALIGNED Span final : public SpanList::Elem { uint16_t embed_count_; uint16_t freelist_; }; - std::atomic allocated_; // Number of non-free objects +#ifdef TCMALLOC_INTERNAL_LEGACY_LOCKING + std::atomic +#else + struct { + uint16_t value; + + uint16_t load(std::memory_order) const { return value; } + + void store(uint16_t v, std::memory_order) { value = v; } + } +#endif + allocated_; // Number of non-free objects #ifndef TCMALLOC_INTERNAL_LEGACY_LOCKING uint8_t cache_size_; #else