From f55d18d86a11dfcfa020cfad45b76c0967fea377 Mon Sep 17 00:00:00 2001 From: Vaibhav Gogte Date: Wed, 5 Aug 2026 14:26:23 -0700 Subject: [PATCH] Add opt-in library to re-enable generic sharded transfer caches. PiperOrigin-RevId: 959870601 --- tcmalloc/BUILD | 11 ++++++++ tcmalloc/transfer_cache.h | 9 +++++- .../want_generic_sharded_transfer_cache.cc | 28 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tcmalloc/want_generic_sharded_transfer_cache.cc diff --git a/tcmalloc/BUILD b/tcmalloc/BUILD index f35e78665..96dacddca 100644 --- a/tcmalloc/BUILD +++ b/tcmalloc/BUILD @@ -1716,3 +1716,14 @@ cc_library( ], alwayslink = 1, ) + +cc_library( + name = "want_generic_sharded_transfer_cache", + srcs = ["want_generic_sharded_transfer_cache.cc"], + copts = ["-g0"] + TCMALLOC_DEFAULT_COPTS, + visibility = ["//tcmalloc/testing:__pkg__"], + deps = [ + "@com_google_absl//absl/base:core_headers", + ], + alwayslink = 1, +) diff --git a/tcmalloc/transfer_cache.h b/tcmalloc/transfer_cache.h index 57d84212d..8044f2c18 100644 --- a/tcmalloc/transfer_cache.h +++ b/tcmalloc/transfer_cache.h @@ -72,10 +72,17 @@ class StaticForwarder { std::align_val_t alignment = kAlignment); }; +extern "C" ABSL_ATTRIBUTE_WEAK bool +default_want_generic_sharded_transfer_cache(); + class ShardedStaticForwarder : public StaticForwarder { public: static void Init() { - use_generic_cache_ = false; + use_generic_cache_ = + (default_want_generic_sharded_transfer_cache != nullptr && + default_want_generic_sharded_transfer_cache()) && + !IsExperimentActive( + Experiment::TEST_ONLY_TCMALLOC_SHARDED_TRANSFER_CACHE); // Traditionally, we enable sharded transfer cache for large size // classes alone. enable_cache_for_large_classes_only_ = IsExperimentActive( diff --git a/tcmalloc/want_generic_sharded_transfer_cache.cc b/tcmalloc/want_generic_sharded_transfer_cache.cc new file mode 100644 index 000000000..a9b3fab2c --- /dev/null +++ b/tcmalloc/want_generic_sharded_transfer_cache.cc @@ -0,0 +1,28 @@ +// Copyright 2026 The TCMalloc Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/base/attributes.h" + +namespace tcmalloc { +namespace tcmalloc_internal { + +// This - if linked into a binary - allows generic sharded transfer cache to be +// enabled. +extern "C" ABSL_ATTRIBUTE_UNUSED bool +default_want_generic_sharded_transfer_cache() { + return true; +} + +} // namespace tcmalloc_internal +} // namespace tcmalloc