Skip to content

Commit

Permalink
Internal change.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 689041019
Change-Id: I8c670892c99ceb7c4c4c91fbabc01c5f33f675ef
  • Loading branch information
v-gogte authored and copybara-github committed Oct 23, 2024
1 parent eafcc39 commit f186aa0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
27 changes: 6 additions & 21 deletions tcmalloc/parameters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "tcmalloc/huge_page_aware_allocator.h"
#include "tcmalloc/internal/allocation_guard.h"
#include "tcmalloc/internal/config.h"
#include "tcmalloc/internal/environment.h"
#include "tcmalloc/internal/logging.h"
#include "tcmalloc/internal_malloc_extension.h"
#include "tcmalloc/malloc_extension.h"
Expand Down Expand Up @@ -209,23 +208,10 @@ absl::Duration Parameters::huge_cache_release_time() {
return absl::Seconds(v.load(std::memory_order_relaxed));
}

// As background_release_rate() is determined at runtime, we cannot require
// constant initialization for the atomic. This avoids an initialization order
// fiasco.
static std::atomic<MallocExtension::BytesPerSecond>& malloc_release_rate() {
ABSL_CONST_INIT static absl::once_flag flag;
ABSL_CONST_INIT static std::atomic<MallocExtension::BytesPerSecond>
v(MallocExtension::BytesPerSecond{0});

absl::base_internal::LowLevelCallOnce(&flag, [&]() {
});

return v;
}

MallocExtension::BytesPerSecond Parameters::background_release_rate() {
return malloc_release_rate().load(std::memory_order_relaxed);
}
ABSL_CONST_INIT std::atomic<MallocExtension::BytesPerSecond>
Parameters::background_release_rate_(MallocExtension::BytesPerSecond{
0
});

ABSL_CONST_INIT std::atomic<int64_t> Parameters::guarded_sampling_interval_(
DefaultOrDebugValue(/*default_val=*/50, /*debug_val=*/5) *
Expand Down Expand Up @@ -446,9 +432,8 @@ void MallocExtension_Internal_SetBackgroundReleaseRate(
}

void TCMalloc_Internal_SetBackgroundReleaseRate(size_t value) {
tcmalloc::tcmalloc_internal::malloc_release_rate().store(
static_cast<tcmalloc::MallocExtension::BytesPerSecond>(value),
std::memory_order_relaxed);
Parameters::background_release_rate_.store(
static_cast<tcmalloc::MallocExtension::BytesPerSecond>(value));
}

uint64_t TCMalloc_Internal_GetHeapSizeHardLimit() {
Expand Down
5 changes: 4 additions & 1 deletion tcmalloc/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ namespace tcmalloc_internal {

class Parameters {
public:
static MallocExtension::BytesPerSecond background_release_rate();
static MallocExtension::BytesPerSecond background_release_rate() {
return background_release_rate_.load(std::memory_order_relaxed);
}

static void set_background_release_rate(
MallocExtension::BytesPerSecond value) {
Expand Down Expand Up @@ -256,6 +258,7 @@ class Parameters {
tcmalloc::tcmalloc_internal::MadvisePreference v);
friend void ::TCMalloc_Internal_SetMinHotAccessHint(uint8_t v);

static std::atomic<MallocExtension::BytesPerSecond> background_release_rate_;
static std::atomic<int64_t> guarded_sampling_interval_;
static std::atomic<uint32_t> max_span_cache_size_;
static std::atomic<uint32_t> max_span_cache_array_size_;
Expand Down
2 changes: 0 additions & 2 deletions tcmalloc/testing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ create_tcmalloc_testsuite(
srcs = ["default_parameters_test.cc"],
copts = TCMALLOC_DEFAULT_COPTS,
deps = [
"//tcmalloc:experiment",
"//tcmalloc:malloc_extension",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/time",
Expand Down Expand Up @@ -773,7 +772,6 @@ create_tcmalloc_testsuite(
],
deps = [
":testutil",
"//tcmalloc:experiment",
"//tcmalloc:malloc_extension",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
Expand Down
10 changes: 5 additions & 5 deletions tcmalloc/testing/default_parameters_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

#include "absl/strings/str_format.h"
#include "absl/time/time.h"
#include "tcmalloc/experiment.h"
#include "tcmalloc/experiment_config.h"
#include "tcmalloc/malloc_extension.h"

namespace tcmalloc {
Expand Down Expand Up @@ -48,6 +46,9 @@ constexpr absl::Duration kDefaultSkipSubreleaseShortInterval =
absl::Seconds(60)
#endif
;
constexpr MallocExtension::BytesPerSecond kDefaultBackgroundReleaseRate{
0
};
constexpr absl::Duration kDefaultSkipSubreleaseLongInterval =
#if defined(TCMALLOC_INTERNAL_SMALL_BUT_SLOW)
absl::ZeroDuration()
Expand Down Expand Up @@ -81,12 +82,11 @@ bool TestGuardedSamplingInterval() {
}

bool TestBackgroundReleaseRate() {
MallocExtension::BytesPerSecond expected_release_rate{0};

auto extension_value = MallocExtension::GetBackgroundReleaseRate();
if (extension_value != expected_release_rate) {
if (extension_value != kDefaultBackgroundReleaseRate) {
absl::FPrintF(stderr, "BackgroundReleaseRate: got %d, want %d\n",
extension_value, expected_release_rate);
extension_value, kDefaultBackgroundReleaseRate);
return false;
}

Expand Down
2 changes: 0 additions & 2 deletions tcmalloc/testing/malloc_extension_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "tcmalloc/cpu_cache.h"
#include "tcmalloc/experiment.h"
#include "tcmalloc/experiment_config.h"
#include "tcmalloc/static_vars.h"
#include "tcmalloc/testing/testutil.h"

Expand Down

0 comments on commit f186aa0

Please sign in to comment.