Skip to content

Commit

Permalink
Clean up experiment for hugepaging tcmalloc metadata.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 684573208
Change-Id: I17b9c5e332b4ac63ae532e680259fffa95d3e2cb
  • Loading branch information
Nelson Liang authored and copybara-github committed Oct 10, 2024
1 parent 47871ba commit f3e160c
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 59 deletions.
2 changes: 0 additions & 2 deletions tcmalloc/experiment_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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 @@ -45,7 +44,6 @@ 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
27 changes: 0 additions & 27 deletions tcmalloc/parameters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,6 @@ 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;
}

// Configures short and long intervals to zero by default. We expect to set them
// to the non-zero durations once the feature is no longer experimental.
static std::atomic<int64_t>& skip_subrelease_short_interval_ns() {
Expand Down Expand Up @@ -284,7 +271,6 @@ ABSL_CONST_INIT std::atomic<bool> Parameters::per_cpu_caches_dynamic_slab_(
true);
ABSL_CONST_INIT std::atomic<MadvisePreference> Parameters::madvise_(
MadvisePreference::kDontNeed);
ABSL_CONST_INIT std::atomic<bool> Parameters::tag_metadata_separately_(true);
ABSL_CONST_INIT std::atomic<tcmalloc::hot_cold_t>
Parameters::min_hot_access_hint_(kDefaultMinHotAccessHint);
ABSL_CONST_INIT std::atomic<double>
Expand Down Expand Up @@ -339,10 +325,6 @@ 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::dense_trackers_sorted_on_spans_allocated() {
ABSL_CONST_INIT static absl::once_flag flag;
ABSL_CONST_INIT static std::atomic<bool> v{false};
Expand Down Expand Up @@ -510,10 +492,6 @@ bool TCMalloc_Internal_GetReleasePagesFromHugeRegionEnabled() {
return Parameters::release_pages_from_huge_region();
}

bool TCMalloc_Internal_GetTagMetadataSeparatelyEnabled() {
return Parameters::tag_metadata_separately();
}

bool TCMalloc_Internal_GetResizeSizeClassMaxCapacityEnabled() {
return Parameters::resize_size_class_max_capacity();
}
Expand Down Expand Up @@ -583,11 +561,6 @@ void TCMalloc_Internal_SetReleasePagesFromHugeRegionEnabled(bool v) {
std::memory_order_relaxed);
}

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

void TCMalloc_Internal_SetResizeSizeClassMaxCapacityEnabled(bool v) {
Parameters::resize_size_class_max_capacity_.store(v,
std::memory_order_relaxed);
Expand Down
8 changes: 0 additions & 8 deletions tcmalloc/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ class Parameters {
return release_pages_from_huge_region_.load(std::memory_order_relaxed);
}

static bool tag_metadata_separately();

static void set_tag_metadata_separately(bool value) {
TCMalloc_Internal_SetTagMetadataSeparatelyEnabled(value);
}

static bool resize_size_class_max_capacity() {
return resize_size_class_max_capacity_.load(std::memory_order_relaxed);
}
Expand Down Expand Up @@ -230,7 +224,6 @@ class Parameters {
friend void ::TCMalloc_Internal_SetHugeCacheDemandBasedRelease(bool v);
friend void ::TCMalloc_Internal_SetHugeRegionDemandBasedRelease(bool v);
friend void ::TCMalloc_Internal_SetReleasePagesFromHugeRegionEnabled(bool v);
friend void ::TCMalloc_Internal_SetTagMetadataSeparatelyEnabled(bool v);
friend void ::TCMalloc_Internal_SetResizeSizeClassMaxCapacityEnabled(bool v);
friend void ::TCMalloc_Internal_SetMaxPerCpuCacheSize(int32_t v);
friend void ::TCMalloc_Internal_SetMaxTotalThreadCacheBytes(int64_t v);
Expand Down Expand Up @@ -272,7 +265,6 @@ class Parameters {
static std::atomic<bool> huge_cache_demand_based_release_;
static std::atomic<bool> release_pages_from_huge_region_;
static std::atomic<bool> resize_size_class_max_capacity_;
static std::atomic<bool> tag_metadata_separately_;
static std::atomic<int64_t> profile_sampling_interval_;
static std::atomic<bool> per_cpu_caches_dynamic_slab_;
static std::atomic<MadvisePreference> madvise_;
Expand Down
5 changes: 1 addition & 4 deletions tcmalloc/system-alloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,7 @@ static AddressRegionFactory::UsageHint TagToHint(MemoryTag tag) {
case MemoryTag::kCold:
return UsageHint::kInfrequentAccess;
case MemoryTag::kMetadata:
if (Parameters::tag_metadata_separately()) {
return UsageHint::kMetadata;
}
return UsageHint::kInfrequentAllocation;
return UsageHint::kMetadata;
}

ASSUME(false);
Expand Down
19 changes: 1 addition & 18 deletions tcmalloc/testing/system-alloc_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "tcmalloc/internal/logging.h"
#include "tcmalloc/internal/proc_maps.h"
#include "tcmalloc/malloc_extension.h"
#include "tcmalloc/parameters.h"

#ifndef PR_SET_VMA
#define PR_SET_VMA 0x53564d41
Expand Down Expand Up @@ -224,9 +223,8 @@ TEST(Basic, RetryFailTest) {
free(q);
}

// Verify when tag_metadata_separately is true, the usage hint is kMetadata.
// Verify default behavior for tcmalloc metadata utilizes usage hint kMetadata.
TEST(UsageHint, VerifyUsageHintkMetadataTest) {
Parameters::set_tag_metadata_separately(true);
MallocExtension::SetRegionFactory(&f);
// Need a large enough size to trigger the system allocator,
// 2.0 is an arbitrary number. Else it would continue to use the previous
Expand All @@ -238,21 +236,6 @@ TEST(UsageHint, VerifyUsageHintkMetadataTest) {
::operator delete(ptr);
}

// Verify that when tag_metadata_separately is false, the usage hint is
// kInfrequentAllocation.
TEST(UsageHint, WhenNotTaggingMetadataSeparately) {
Parameters::set_tag_metadata_separately(false);
MallocExtension::SetRegionFactory(&f);
// Need a large enough size to trigger the system allocator,
// 2.0 is an arbitrary number. Else it would continue to use the previous
// hugepage region and a new usage hint wouldn't be assigned
void* ptr = ::operator new(kMinMmapAlloc * 2.0);
EXPECT_EQ(f.usage_hint_,
AddressRegionFactory::UsageHint::kInfrequentAllocation)
<< "Usage hint is " << hintToString(f.usage_hint_);
::operator delete(ptr);
}

} // namespace
} // namespace tcmalloc_internal
} // namespace tcmalloc

0 comments on commit f3e160c

Please sign in to comment.