Skip to content

Commit 010468f

Browse files
TCMalloc Teamcopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 831070869 Change-Id: I80107296e0a36cc057f3f221b20c889eac02100c
1 parent 4c55431 commit 010468f

File tree

5 files changed

+47
-17
lines changed

5 files changed

+47
-17
lines changed

tcmalloc/experiment_config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ namespace tcmalloc {
2323
enum class Experiment : int {
2424
// clang-format off
2525
// go/keep-sorted start
26-
TCMALLOC_EXTENDED_PRIORITY_LISTS_V1, // TODO: b/437412600 - Complete experiment.
26+
TCMALLOC_COLLAPSE_HEURISTICS, // TODO: b/456564608 - Complete experiment.
27+
TCMALLOC_EXTENDED_PRIORITY_LISTS_V1, // TODO: b/437412600 - Complete experiment.
2728
TCMALLOC_RELEASE_FREE_SWAPPED, // TODO: b/438767733 - Complete experiment.
2829
TEST_ONLY_L3_AWARE, // TODO: b/239977380 - Complete experiment.
2930
TEST_ONLY_MM_VCPU, // TODO: b/245776120 - Complete experiment.
@@ -48,6 +49,7 @@ struct ExperimentConfig {
4849
// clang-format off
4950
inline constexpr ExperimentConfig experiments[] = {
5051
// go/keep-sorted start
52+
{Experiment::TCMALLOC_COLLAPSE_HEURISTICS, "TCMALLOC_COLLAPSE_HEURISTICS"},
5153
{Experiment::TCMALLOC_EXTENDED_PRIORITY_LISTS_V1, "TCMALLOC_EXTENDED_PRIORITY_LISTS_V1"},
5254
{Experiment::TCMALLOC_RELEASE_FREE_SWAPPED, "TCMALLOC_RELEASE_FREE_SWAPPED"},
5355
{Experiment::TEST_ONLY_L3_AWARE, "TEST_ONLY_L3_AWARE"},

tcmalloc/parameters.cc

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,16 @@ ABSL_CONST_INIT std::atomic<double>
200200
ABSL_CONST_INIT std::atomic<int64_t> Parameters::profile_sampling_interval_(
201201
kDefaultProfileSamplingInterval);
202202

203-
ABSL_CONST_INIT std::atomic<bool>
204-
Parameters::use_userspace_collapse_heuristics_(false);
203+
static std::atomic<bool>& use_userspace_collapse_heuristics_enabled() {
204+
ABSL_CONST_INIT static absl::once_flag flag;
205+
ABSL_CONST_INIT static std::atomic<bool> v{false};
206+
absl::base_internal::LowLevelCallOnce(&flag, [&]() {
207+
if (IsExperimentActive(Experiment::TCMALLOC_COLLAPSE_HEURISTICS)) {
208+
v.store(true, std::memory_order_relaxed);
209+
}
210+
});
211+
return v;
212+
}
205213

206214
static std::atomic<bool>& release_free_swapped_enabled() {
207215
ABSL_CONST_INIT static absl::once_flag flag;
@@ -247,6 +255,11 @@ bool Parameters::usermode_hugepage_collapse() {
247255
return usermode_hugepage_collapse_enabled_.load(std::memory_order_relaxed);
248256
}
249257

258+
bool Parameters::use_userspace_collapse_heuristics() {
259+
return use_userspace_collapse_heuristics_enabled().load(
260+
std::memory_order_relaxed);
261+
}
262+
250263
bool Parameters::release_free_swapped() {
251264
return release_free_swapped_enabled().load(std::memory_order_relaxed);
252265
}
@@ -273,10 +286,6 @@ int32_t Parameters::max_per_cpu_cache_size() {
273286
return tc_globals.cpu_cache().CacheLimit();
274287
}
275288

276-
bool TCMalloc_Internal_GetUseUserspaceCollapseHeuristics() {
277-
return Parameters::use_userspace_collapse_heuristics();
278-
}
279-
280289
int ABSL_ATTRIBUTE_WEAK default_want_disable_dynamic_slabs();
281290

282291
// TODO(b/271475288): remove the default_want_disable_dynamic_slabs opt-out
@@ -568,9 +577,13 @@ void TCMalloc_Internal_SetReleaseFreeSwapped(bool v) {
568577
v, std::memory_order_relaxed);
569578
}
570579

580+
bool TCMalloc_Internal_GetUseUserspaceCollapseHeuristics() {
581+
return Parameters::use_userspace_collapse_heuristics();
582+
}
583+
571584
void TCMalloc_Internal_SetUseUserspaceCollapseHeuristics(bool v) {
572-
Parameters::use_userspace_collapse_heuristics_.store(
573-
v, std::memory_order_relaxed);
585+
tcmalloc::tcmalloc_internal::use_userspace_collapse_heuristics_enabled()
586+
.store(v, std::memory_order_relaxed);
574587
}
575588

576589
} // extern "C"

tcmalloc/parameters.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ class Parameters {
9999

100100
static bool release_free_swapped();
101101

102-
static bool use_userspace_collapse_heuristics() {
103-
return use_userspace_collapse_heuristics_.load(std::memory_order_relaxed);
104-
}
102+
static bool use_userspace_collapse_heuristics();
105103

106104
static bool release_pages_from_huge_region() {
107105
return release_pages_from_huge_region_.load(std::memory_order_relaxed);
@@ -224,7 +222,6 @@ class Parameters {
224222
static std::atomic<double> per_cpu_caches_dynamic_slab_grow_threshold_;
225223
static std::atomic<double> per_cpu_caches_dynamic_slab_shrink_threshold_;
226224
static std::atomic<bool> usermode_hugepage_collapse_enabled_;
227-
static std::atomic<bool> use_userspace_collapse_heuristics_;
228225
};
229226

230227
} // namespace tcmalloc_internal

tcmalloc/testing/get_stats_test.cc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ TEST_F(GetStatsTest, Pbtxt) {
133133
} else {
134134
EXPECT_THAT(buf, HasSubstr("release_free_swapped: false"));
135135
}
136-
EXPECT_THAT(buf, HasSubstr("use_userspace_collapse_heuristics: false"));
136+
if (IsExperimentActive(Experiment::TCMALLOC_COLLAPSE_HEURISTICS)) {
137+
EXPECT_THAT(buf, HasSubstr("use_userspace_collapse_heuristics: true"));
138+
} else {
139+
EXPECT_THAT(buf, HasSubstr("use_userspace_collapse_heuristics: false"));
140+
}
137141
if (IsExperimentActive(
138142
Experiment::TEST_ONLY_TCMALLOC_EXTENDED_PRIORITY_LISTS_V1) ||
139143
IsExperimentActive(Experiment::TCMALLOC_EXTENDED_PRIORITY_LISTS_V1)) {
@@ -219,9 +223,17 @@ TEST_F(GetStatsTest, Parameters) {
219223
EXPECT_THAT(buf,
220224
HasSubstr(R"(PARAMETER tcmalloc_release_free_swapped 0)"));
221225
}
222-
EXPECT_THAT(
223-
buf,
224-
HasSubstr(R"(PARAMETER tcmalloc_use_userspace_collapse_heuristics 0)"));
226+
if (IsExperimentActive(Experiment::TCMALLOC_COLLAPSE_HEURISTICS)) {
227+
EXPECT_THAT(
228+
buf,
229+
HasSubstr(
230+
R"(PARAMETER tcmalloc_use_userspace_collapse_heuristics 1)"));
231+
} else {
232+
EXPECT_THAT(
233+
buf,
234+
HasSubstr(
235+
R"(PARAMETER tcmalloc_use_userspace_collapse_heuristics 0)"));
236+
}
225237
if (IsExperimentActive(
226238
Experiment::TEST_ONLY_TCMALLOC_EXTENDED_PRIORITY_LISTS_V1) ||
227239
IsExperimentActive(Experiment::TCMALLOC_EXTENDED_PRIORITY_LISTS_V1)) {

tcmalloc/variants.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ test_variants = [
265265
"deps": ["//tcmalloc:common_8k_pages"],
266266
"env": {"BORG_EXPERIMENTS": "TEST_ONLY_TCMALLOC_EXTENDED_PRIORITY_LISTS_V1"},
267267
},
268+
{
269+
"name": "tcmalloc_collapse_heuristics",
270+
"malloc": "//tcmalloc",
271+
"deps": ["//tcmalloc:common_8k_pages"],
272+
"env": {"BORG_EXPERIMENTS": "TCMALLOC_COLLAPSE_HEURISTICS"},
273+
},
268274
{
269275
"name": "tcmalloc_release_free_swapped",
270276
"malloc": "//tcmalloc",

0 commit comments

Comments
 (0)