Skip to content

Commit

Permalink
minor, refactor, whitespace-only, nfc: clang-format the repo
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 719350703
Change-Id: I17e91e9a7982f7364e8c5f75b940d7166312ad8f
  • Loading branch information
patrickxia authored and copybara-github committed Jan 24, 2025
1 parent 5c2a858 commit c64aca4
Show file tree
Hide file tree
Showing 28 changed files with 143 additions and 165 deletions.
1 change: 0 additions & 1 deletion tcmalloc/background.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.


#include <algorithm>
#include <cstddef>

Expand Down
3 changes: 1 addition & 2 deletions tcmalloc/central_freelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ inline void CentralFreeList<Forwarder>::Init(size_t size_class)
objects_per_span_ =
pages_per_span_.in_bytes() / (object_size_ ? object_size_ : 1);
size_reciprocal_ = Span::CalcReciprocal(object_size_);
use_all_buckets_for_few_object_spans_ =
objects_per_span_ <= 2 * kNumLists;
use_all_buckets_for_few_object_spans_ = objects_per_span_ <= 2 * kNumLists;

// Records nonempty_ list index associated with the span with
// objects_per_span_ number of allocated objects. Refer to the comment in
Expand Down
2 changes: 1 addition & 1 deletion tcmalloc/deallocation_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "tcmalloc/deallocation_profiler.h"

#include <algorithm>
#include <cmath> // for std::lround
#include <cmath> // for std::lround
#include <cstddef>
#include <cstdint> // for uintptr_t
#include <cstring>
Expand Down
1 change: 0 additions & 1 deletion tcmalloc/global_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ void ExtractStats(TCMallocStats* r, uint64_t* class_count,
} else {
r->pagemap_root_bytes_res = 0;
}

}

void ExtractTCMallocStats(TCMallocStats* r, bool report_residence) {
Expand Down
10 changes: 5 additions & 5 deletions tcmalloc/guarded_page_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ class GuardedPageAllocator {
// is detected.
SlotMetadata* data_;

uintptr_t pages_base_addr_; // Points to start of mapped region.
uintptr_t pages_end_addr_; // Points to the end of mapped region.
uintptr_t first_page_addr_; // Points to first page returnable by Allocate.
uintptr_t pages_base_addr_; // Points to start of mapped region.
uintptr_t pages_end_addr_; // Points to the end of mapped region.
uintptr_t first_page_addr_; // Points to first page returnable by Allocate.
size_t max_allocated_pages_; // Max number of pages to allocate at once.
size_t total_pages_; // Size of the page pool to allocate from.
size_t page_size_; // Size of pages we allocate.
size_t total_pages_; // Size of the page pool to allocate from.
size_t page_size_; // Size of pages we allocate.
Random rand_;

// True if this object has been fully initialized.
Expand Down
30 changes: 12 additions & 18 deletions tcmalloc/guarded_page_allocator_profile_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ TEST_F(GuardedPageAllocatorProfileTest, Guarded) {
AllocateUntilGuarded();
auto token = MallocExtension::StartAllocationProfiling();

AllocateGuardableUntil(1051, [&](void* alloc) -> NextSteps {
return {true, true};
});
AllocateGuardableUntil(
1051, [&](void* alloc) -> NextSteps { return {true, true}; });

auto profile = std::move(token).Stop();
ExamineSamples(profile, Profile::Sample::GuardedStatus::Guarded);
Expand All @@ -118,9 +117,8 @@ TEST_F(GuardedPageAllocatorProfileTest, NotAttempted) {
auto token = MallocExtension::StartAllocationProfiling();

constexpr size_t alloc_size = 2 * 1024 * 1024;
AllocateUntil(alloc_size, [&](void* alloc) -> NextSteps {
return {true, true};
});
AllocateUntil(alloc_size,
[&](void* alloc) -> NextSteps { return {true, true}; });

auto profile = std::move(token).Stop();
ExamineSamples(profile, Profile::Sample::GuardedStatus::NotAttempted,
Expand All @@ -141,9 +139,8 @@ TEST_F(GuardedPageAllocatorProfileTest, LargerThanOnePage) {
auto token = MallocExtension::StartAllocationProfiling();

constexpr size_t alloc_size = kPageSize + 1;
AllocateUntil(alloc_size, [&](void* alloc) -> NextSteps {
return {true, true};
});
AllocateUntil(alloc_size,
[&](void* alloc) -> NextSteps { return {true, true}; });

auto profile = std::move(token).Stop();
ExamineSamples(profile, Profile::Sample::GuardedStatus::LargerThanOnePage,
Expand All @@ -163,9 +160,8 @@ TEST_F(GuardedPageAllocatorProfileTest, Disabled) {
ScopedProfileSamplingInterval profile_sampling_interval(1);
auto token = MallocExtension::StartAllocationProfiling();

AllocateGuardableUntil(1024, [&](void* alloc) -> NextSteps {
return {true, true};
});
AllocateGuardableUntil(
1024, [&](void* alloc) -> NextSteps { return {true, true}; });

auto profile = std::move(token).Stop();
ExamineSamples(profile, Profile::Sample::GuardedStatus::Disabled);
Expand Down Expand Up @@ -250,9 +246,8 @@ TEST_F(GuardedPageAllocatorProfileTest, TooSmall) {

// Next sampled allocation should be too small
constexpr size_t alloc_size = 0;
AllocateGuardableUntil(alloc_size, [&](void* alloc) -> NextSteps {
return {true, true};
});
AllocateGuardableUntil(
alloc_size, [&](void* alloc) -> NextSteps { return {true, true}; });

auto profile = std::move(token).Stop();
ExamineSamples(profile, Profile::Sample::GuardedStatus::TooSmall,
Expand Down Expand Up @@ -301,9 +296,8 @@ TEST_F(GuardedPageAllocatorProfileTest, NeverSample) {
auto token = MallocExtension::StartAllocationProfiling();

// This will not succeed in guarding anything.
int alloc_count = AllocateGuardableUntil(1025, [&](void* alloc) -> NextSteps {
return {true, true};
});
int alloc_count = AllocateGuardableUntil(
1025, [&](void* alloc) -> NextSteps { return {true, true}; });
ASSERT_EQ(alloc_count, 1);

auto profile = std::move(token).Stop();
Expand Down
4 changes: 1 addition & 3 deletions tcmalloc/huge_allocator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ class HugeAllocatorTest : public testing::TestWithParam<bool> {
vm_allocator_.backing_.resize(1024);
}

~HugeAllocatorTest() override {
vm_allocator_.backing_.clear();
}
~HugeAllocatorTest() override { vm_allocator_.backing_.clear(); }

size_t* GetActual(HugePage p) { return &vm_allocator_.backing_[p.index()]; }

Expand Down
175 changes: 87 additions & 88 deletions tcmalloc/huge_page_filler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1688,24 +1688,23 @@ TEST_P(FillerTest, CheckPreviouslyReleasedStats) {
Printer printer(&*buffer.begin(), buffer.size());
filler_.Print(&printer, true);
}
buffer.resize(strlen(buffer.c_str()));
EXPECT_THAT(buffer, testing::HasSubstr(
"HugePageFiller: 0 hugepages became full after "
"being previously released, "
"out of which 0 pages are hugepage backed."));

// Repopulate.
ASSERT_TRUE(!tiny1.empty());
half =
AllocateVectorWithSpanAllocInfo(N / 2, tiny1.front().span_alloc_info);
EXPECT_EQ(ReleasePages(kMaxValidPages), Length(0));
EXPECT_EQ(filler_.previously_released_huge_pages(), NHugePages(1));
buffer.resize(1024 * 1024);
{
PageHeapSpinLockHolder l;
Printer printer(&*buffer.begin(), buffer.size());
filler_.Print(&printer, true);
}
buffer.resize(strlen(buffer.c_str()));
EXPECT_THAT(buffer, testing::HasSubstr(
"HugePageFiller: 0 hugepages became full after "
"being previously released, "
"out of which 0 pages are hugepage backed."));

// Repopulate.
ASSERT_TRUE(!tiny1.empty());
half = AllocateVectorWithSpanAllocInfo(N / 2, tiny1.front().span_alloc_info);
EXPECT_EQ(ReleasePages(kMaxValidPages), Length(0));
EXPECT_EQ(filler_.previously_released_huge_pages(), NHugePages(1));
buffer.resize(1024 * 1024);
{
PageHeapSpinLockHolder l;
Printer printer(&*buffer.begin(), buffer.size());
filler_.Print(&printer, true);
}

buffer.resize(strlen(buffer.c_str()));
EXPECT_THAT(buffer,
Expand Down Expand Up @@ -2084,76 +2083,76 @@ TEST_P(FillerTest, SkipPartialAllocSubrelease_SpansAllocated) {
// in demand and tries to subrelease. Finally, it waits for time interval c to
// generate the highest peak for evaluating subrelease correctness. Skip
// subrelease selects those demand points using provided time intervals.
const auto demand_pattern =
[&](absl::Duration a, absl::Duration b, absl::Duration c,
SkipSubreleaseIntervals intervals, bool expected_subrelease) {
const Length N = kPagesPerHugePage;
// First peak: min_demand 3/4N, max_demand 1N.
std::vector<PAlloc> peak1a =
AllocateVectorWithSpanAllocInfo(3 * N / 4, info);
ASSERT_TRUE(!peak1a.empty());
std::vector<PAlloc> peak1b = AllocateVectorWithSpanAllocInfo(
N / 4, peak1a.front().span_alloc_info);
Advance(a);
// Second peak: min_demand 0, max_demand 2N.
DeleteVector(peak1a);
DeleteVector(peak1b);

std::vector<PAlloc> half = AllocateVectorWithSpanAllocInfo(N / 2, info);
ASSERT_TRUE(!half.empty());
std::vector<PAlloc> tiny1 = AllocateVectorWithSpanAllocInfo(
N / 4, half.front().span_alloc_info);
std::vector<PAlloc> tiny2 = AllocateVectorWithSpanAllocInfo(
N / 4, half.front().span_alloc_info);

// To force a peak, we allocate 3/4 and 1/4 of a huge page. This is
// necessary after we delete `half` below, as a half huge page for the
// peak would fill into the gap previously occupied by it.
std::vector<PAlloc> peak2a =
AllocateVectorWithSpanAllocInfo(3 * N / 4, info);
ASSERT_TRUE(!peak2a.empty());
std::vector<PAlloc> peak2b = AllocateVectorWithSpanAllocInfo(
N / 4, peak2a.front().span_alloc_info);
EXPECT_EQ(filler_.used_pages(), 2 * N);
DeleteVector(peak2a);
DeleteVector(peak2b);
Advance(b);
DeleteVector(half);
EXPECT_EQ(filler_.free_pages(), Length(N / 2));
// The number of released pages is limited to the number of free pages.
EXPECT_EQ(expected_subrelease ? N / 2 : Length(0),
ReleasePartialPages(10 * N, intervals));

Advance(c);
half = AllocateVectorWithSpanAllocInfo(N / 2,
half.front().span_alloc_info);
// Third peak: min_demand 1/2N, max_demand (2+1/2)N.
std::vector<PAlloc> peak3a =
AllocateVectorWithSpanAllocInfo(3 * N / 4, info);
ASSERT_TRUE(!peak3a.empty());
std::vector<PAlloc> peak3b = AllocateVectorWithSpanAllocInfo(
N / 4, peak3a.front().span_alloc_info);

std::vector<PAlloc> peak4a =
AllocateVectorWithSpanAllocInfo(3 * N / 4, info);
ASSERT_TRUE(!peak4a.empty());
std::vector<PAlloc> peak4b = AllocateVectorWithSpanAllocInfo(
N / 4, peak4a.front().span_alloc_info);

DeleteVector(half);
DeleteVector(tiny1);
DeleteVector(tiny2);
DeleteVector(peak3a);
DeleteVector(peak3b);
DeleteVector(peak4a);
DeleteVector(peak4b);

EXPECT_EQ(filler_.used_pages(), Length(0));
EXPECT_EQ(filler_.unmapped_pages(), Length(0));
EXPECT_EQ(filler_.free_pages(), Length(0));

EXPECT_EQ(Length(0), ReleasePartialPages(10 * N));
};
const auto demand_pattern = [&](absl::Duration a, absl::Duration b,
absl::Duration c,
SkipSubreleaseIntervals intervals,
bool expected_subrelease) {
const Length N = kPagesPerHugePage;
// First peak: min_demand 3/4N, max_demand 1N.
std::vector<PAlloc> peak1a =
AllocateVectorWithSpanAllocInfo(3 * N / 4, info);
ASSERT_TRUE(!peak1a.empty());
std::vector<PAlloc> peak1b =
AllocateVectorWithSpanAllocInfo(N / 4, peak1a.front().span_alloc_info);
Advance(a);
// Second peak: min_demand 0, max_demand 2N.
DeleteVector(peak1a);
DeleteVector(peak1b);

std::vector<PAlloc> half = AllocateVectorWithSpanAllocInfo(N / 2, info);
ASSERT_TRUE(!half.empty());
std::vector<PAlloc> tiny1 =
AllocateVectorWithSpanAllocInfo(N / 4, half.front().span_alloc_info);
std::vector<PAlloc> tiny2 =
AllocateVectorWithSpanAllocInfo(N / 4, half.front().span_alloc_info);

// To force a peak, we allocate 3/4 and 1/4 of a huge page. This is
// necessary after we delete `half` below, as a half huge page for the
// peak would fill into the gap previously occupied by it.
std::vector<PAlloc> peak2a =
AllocateVectorWithSpanAllocInfo(3 * N / 4, info);
ASSERT_TRUE(!peak2a.empty());
std::vector<PAlloc> peak2b =
AllocateVectorWithSpanAllocInfo(N / 4, peak2a.front().span_alloc_info);
EXPECT_EQ(filler_.used_pages(), 2 * N);
DeleteVector(peak2a);
DeleteVector(peak2b);
Advance(b);
DeleteVector(half);
EXPECT_EQ(filler_.free_pages(), Length(N / 2));
// The number of released pages is limited to the number of free pages.
EXPECT_EQ(expected_subrelease ? N / 2 : Length(0),
ReleasePartialPages(10 * N, intervals));

Advance(c);
half = AllocateVectorWithSpanAllocInfo(N / 2, half.front().span_alloc_info);
// Third peak: min_demand 1/2N, max_demand (2+1/2)N.
std::vector<PAlloc> peak3a =
AllocateVectorWithSpanAllocInfo(3 * N / 4, info);
ASSERT_TRUE(!peak3a.empty());
std::vector<PAlloc> peak3b =
AllocateVectorWithSpanAllocInfo(N / 4, peak3a.front().span_alloc_info);

std::vector<PAlloc> peak4a =
AllocateVectorWithSpanAllocInfo(3 * N / 4, info);
ASSERT_TRUE(!peak4a.empty());
std::vector<PAlloc> peak4b =
AllocateVectorWithSpanAllocInfo(N / 4, peak4a.front().span_alloc_info);

DeleteVector(half);
DeleteVector(tiny1);
DeleteVector(tiny2);
DeleteVector(peak3a);
DeleteVector(peak3b);
DeleteVector(peak4a);
DeleteVector(peak4b);

EXPECT_EQ(filler_.used_pages(), Length(0));
EXPECT_EQ(filler_.unmapped_pages(), Length(0));
EXPECT_EQ(filler_.free_pages(), Length(0));

EXPECT_EQ(Length(0), ReleasePartialPages(10 * N));
};

{
// Uses peak interval for skipping subrelease. We should correctly skip
Expand Down
8 changes: 2 additions & 6 deletions tcmalloc/huge_page_subrelease.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ struct SkipSubreleaseIntervals {
};

struct SubreleaseStats {
Length total_pages_subreleased; // cumulative since startup
Length total_pages_subreleased; // cumulative since startup
Length total_partial_alloc_pages_subreleased; // cumulative since startup
Length num_pages_subreleased;
Length num_partial_alloc_pages_subreleased;
Expand Down Expand Up @@ -458,11 +458,7 @@ class SubreleaseStatsTracker {
// We collect subrelease statistics at four "interesting points" within each
// time step: at min/max demand of pages and at min/max use of hugepages. This
// allows us to approximate the envelope of the different metrics.
enum StatsType {
kStatsAtMinDemand,
kStatsAtMaxDemand,
kNumStatsTypes
};
enum StatsType { kStatsAtMinDemand, kStatsAtMaxDemand, kNumStatsTypes };

struct SubreleaseStatsEntry {
// Collect stats at "interesting points" (minimum/maximum page demand
Expand Down
4 changes: 2 additions & 2 deletions tcmalloc/internal/allocation_guard_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ TEST(AllocationGuard, Noncooperative) {
TEST(AllocationGuard, CooperativeDeathTest) {
absl::base_internal::SpinLock lock;

EXPECT_DEBUG_DEATH({ AllocationGuardSpinLockHolder h(&lock); },
"SIGABRT received");
EXPECT_DEBUG_DEATH(
{ AllocationGuardSpinLockHolder h(&lock); }, "SIGABRT received");
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion tcmalloc/internal/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
#define TCMALLOC_GLIBC_PREREQ(major, minor) \
((__GLIBC__ * 100 + __GLIBC_MINOR__) >= ((major)*100 + (minor)))
((__GLIBC__ * 100 + __GLIBC_MINOR__) >= ((major) * 100 + (minor)))
#else
#define TCMALLOC_GLIBC_PREREQ(major, minor) 0
#endif
Expand Down
1 change: 0 additions & 1 deletion tcmalloc/internal/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#ifndef TCMALLOC_INTERNAL_DECLARATIONS_H_
#define TCMALLOC_INTERNAL_DECLARATIONS_H_


#if !defined(__cpp_sized_deallocation)

void operator delete(void*, std::size_t) noexcept;
Expand Down
4 changes: 2 additions & 2 deletions tcmalloc/internal/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ const T& FormatConvert(const T& v) {
// Print into buffer
class Printer {
private:
char* buf_; // Where should we write next
size_t left_; // Space left in buffer (including space for \0)
char* buf_; // Where should we write next
size_t left_; // Space left in buffer (including space for \0)
size_t required_; // Space we needed to complete all printf calls up to this
// point

Expand Down
1 change: 0 additions & 1 deletion tcmalloc/internal/memory_stats_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <stdint.h>
#include <unistd.h>


#include "gtest/gtest.h"

namespace tcmalloc {
Expand Down
Loading

0 comments on commit c64aca4

Please sign in to comment.