Skip to content

Commit

Permalink
Allow metadata tagging to be controlled by experiment.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 665513238
Change-Id: Id6de7c01be3baf5668885612177a83fcdc6bbb16
  • Loading branch information
Nelson Liang authored and copybara-github committed Aug 20, 2024
1 parent d3686f4 commit daada54
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions tcmalloc/experiment_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum class Experiment : int {
// clang-format off
TEST_ONLY_TCMALLOC_POW2_SIZECLASS,
TEST_ONLY_TCMALLOC_SHARDED_TRANSFER_CACHE,
TCMALLOC_METADATA_HUGEPAGE, // TODO(b/345239704): Complete experiment.
TEST_ONLY_TCMALLOC_HUGE_CACHE_RELEASE_30S, // TODO(b/319872040): Complete experiment.
TEST_ONLY_TCMALLOC_REUSE_SIZE_CLASSES, // TODO(b/358126781): Complete experiment.
TCMALLOC_HUGE_REGION_DEMAND_BASED_RELEASE, // TODO(b/328440160): Complete experiment.
Expand All @@ -43,6 +44,7 @@ struct ExperimentConfig {
inline constexpr ExperimentConfig experiments[] = {
{Experiment::TEST_ONLY_TCMALLOC_POW2_SIZECLASS, "TEST_ONLY_TCMALLOC_POW2_SIZECLASS"},
{Experiment::TEST_ONLY_TCMALLOC_SHARDED_TRANSFER_CACHE, "TEST_ONLY_TCMALLOC_SHARDED_TRANSFER_CACHE"},
{Experiment::TCMALLOC_METADATA_HUGEPAGE, "TCMALLOC_METADATA_HUGEPAGE"},
{Experiment::TEST_ONLY_TCMALLOC_HUGE_CACHE_RELEASE_30S, "TEST_ONLY_TCMALLOC_HUGE_CACHE_RELEASE_30S"},
{Experiment::TEST_ONLY_TCMALLOC_REUSE_SIZE_CLASSES, "TEST_ONLY_TCMALLOC_REUSE_SIZE_CLASSES"},
{Experiment::TCMALLOC_HUGE_REGION_DEMAND_BASED_RELEASE, "TCMALLOC_HUGE_REGION_DEMAND_BASED_RELEASE"},
Expand Down
20 changes: 19 additions & 1 deletion tcmalloc/parameters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ static std::atomic<bool>& huge_region_demand_based_release_enabled() {
return v;
}

// As set_metadata_hugepage is determined at runtime, we cannot require constant
// initialization for the atomic. This avoids an initialization order fiasco.
static std::atomic<bool>& tag_metadata_hugepage_enabled() {
ABSL_CONST_INIT static absl::once_flag flag;
ABSL_CONST_INIT static std::atomic<bool> v{true};
absl::base_internal::LowLevelCallOnce(&flag, [&]() {
if (IsExperimentActive(Experiment::TCMALLOC_METADATA_HUGEPAGE)) {
v.store(false, std::memory_order_relaxed);
}
});
return v;
}

// As resize_size_class_max_capacity_enabled() is determined at runtime, we
// cannot require constant initialization for the atomic. This avoids an
// initialization order fiasco.
Expand Down Expand Up @@ -291,6 +304,10 @@ bool Parameters::huge_region_demand_based_release() {
std::memory_order_relaxed);
}

bool Parameters::tag_metadata_separately() {
return tag_metadata_hugepage_enabled().load(std::memory_order_relaxed);
}

bool Parameters::resize_size_class_max_capacity() {
return resize_size_class_max_capacity_enabled().load(
std::memory_order_relaxed);
Expand Down Expand Up @@ -504,7 +521,8 @@ void TCMalloc_Internal_SetReleasePagesFromHugeRegionEnabled(bool v) {
}

void TCMalloc_Internal_SetTagMetadataSeparatelyEnabled(bool v) {
Parameters::tag_metadata_separately_.store(v, std::memory_order_relaxed);
tcmalloc::tcmalloc_internal::tag_metadata_hugepage_enabled().store(
v, std::memory_order_relaxed);
}

void TCMalloc_Internal_SetResizeSizeClassMaxCapacityEnabled(bool v) {
Expand Down
4 changes: 1 addition & 3 deletions tcmalloc/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ class Parameters {
return release_pages_from_huge_region_.load(std::memory_order_relaxed);
}

static bool tag_metadata_separately() {
return tag_metadata_separately_.load(std::memory_order_relaxed);
}
static bool tag_metadata_separately();

static void set_tag_metadata_separately(bool value) {
TCMalloc_Internal_SetTagMetadataSeparatelyEnabled(value);
Expand Down

0 comments on commit daada54

Please sign in to comment.