diff --git a/tcmalloc/static_vars.cc b/tcmalloc/static_vars.cc index 38fe08595..12e76c002 100644 --- a/tcmalloc/static_vars.cc +++ b/tcmalloc/static_vars.cc @@ -17,6 +17,7 @@ #include #include +#include #include "absl/base/attributes.h" #include "absl/base/const_init.h" @@ -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() { diff --git a/tcmalloc/testing/want_pow2below64_size_classes_helper.cc b/tcmalloc/testing/want_pow2below64_size_classes_helper.cc new file mode 100644 index 000000000..1142b7ef5 --- /dev/null +++ b/tcmalloc/testing/want_pow2below64_size_classes_helper.cc @@ -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 + +#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 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; +}