Skip to content

Commit

Permalink
Opt out for reuse size classes.
Browse files Browse the repository at this point in the history
This implements an opt out for reuse size classes. By setting TCMALLOC_LEGACY_SIZE_CLASSES="pow2below64", this falls back to the previous behavior that uses legacy pow2 below64 size classes.

PiperOrigin-RevId: 713375923
Change-Id: If371d18a097459d43093eee6f1d4e0f80459d22a
  • Loading branch information
v-gogte authored and copybara-github committed Jan 8, 2025
1 parent c73e577 commit ad08636
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 6 deletions.
29 changes: 23 additions & 6 deletions tcmalloc/static_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stddef.h>

#include <atomic>
#include <cstring>

#include "absl/base/attributes.h"
#include "absl/base/const_init.h"
Expand Down Expand Up @@ -172,16 +173,32 @@ int ABSL_ATTRIBUTE_WEAK default_want_legacy_size_classes();
SizeClassConfiguration Static::size_class_configuration() {
if (IsExperimentActive(Experiment::TEST_ONLY_TCMALLOC_POW2_SIZECLASS)) {
return SizeClassConfiguration::kPow2Only;
} else if (default_want_legacy_size_classes != nullptr &&
default_want_legacy_size_classes() > 0) {
// TODO(b/242710633): remove this opt out.
}

// TODO(b/242710633): remove this opt out.
if (default_want_legacy_size_classes != nullptr &&
default_want_legacy_size_classes() > 0) {
return SizeClassConfiguration::kLegacy;
} else if (IsExperimentActive(
Experiment::TEST_ONLY_TCMALLOC_REUSE_SIZE_CLASSES)) {
}

if (IsExperimentActive(Experiment::TEST_ONLY_TCMALLOC_REUSE_SIZE_CLASSES)) {
return SizeClassConfiguration::kReuse;
} else {
}

const char* e = thread_safe_getenv("TCMALLOC_LEGACY_SIZE_CLASSES");
if (e == nullptr) {
// TODO(b/358126781): Change this to use reuse size classes.
return SizeClassConfiguration::kPow2Below64;
} else if (!strcmp(e, "pow2below64")) {
return SizeClassConfiguration::kPow2Below64;
} else if (!strcmp(e, "0")) {
// TODO(b/358126781): Change this to use reuse size classes.
return SizeClassConfiguration::kPow2Below64;
} else {
TC_BUG("bad TCMALLOC_LEGACY_SIZE_CLASSES env var '%s'", e);
}
// TODO(b/358126781): Change this to use reuse size classes.
return SizeClassConfiguration::kPow2Below64;
}

ABSL_ATTRIBUTE_COLD ABSL_ATTRIBUTE_NOINLINE void Static::SlowInitIfNecessary() {
Expand Down
39 changes: 39 additions & 0 deletions tcmalloc/testing/want_pow2below64_size_classes_helper.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2019 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 <cstdio>

#include "absl/types/span.h"
#include "tcmalloc/common.h"
#include "tcmalloc/internal/logging.h"
#include "tcmalloc/sizemap.h"
#include "tcmalloc/static_vars.h"

int main(int argc, char** argv) {
const size_t kExpectedClasses[] = {0, 8, 16, 32, 64, 72, 80, 88};

absl::Span<const size_t> classes = absl::MakeSpan(kExpectedClasses);

TC_CHECK_LE(classes.size(), tcmalloc::tcmalloc_internal::kNumClasses);
for (int c = 0; c < classes.size(); ++c) {
if (tcmalloc::tcmalloc_internal::Static::sizemap().class_to_size(c) !=
classes[c]) {
printf("Other");
return 0;
}
}
printf("Pow2Below64");

return 0;
}

0 comments on commit ad08636

Please sign in to comment.