From e859eace883c46dd025f5f9e494f6f690615070e Mon Sep 17 00:00:00 2001 From: Chris Kennelly Date: Sun, 25 Oct 2020 17:01:14 -0400 Subject: [PATCH] Apply clang-format to code. This commit is intended for testing the presubmit build. --- tcmalloc/central_freelist.h | 4 +- tcmalloc/central_freelist_test.cc | 2 +- tcmalloc/common.h | 2 +- tcmalloc/cpu_cache.cc | 4 +- tcmalloc/cpu_cache.h | 3 +- tcmalloc/guarded_page_allocator.cc | 4 +- tcmalloc/guarded_page_allocator_benchmark.cc | 5 +- tcmalloc/guarded_page_allocator_test.cc | 4 +- tcmalloc/huge_address_map_test.cc | 1 + tcmalloc/huge_allocator_test.cc | 2 +- tcmalloc/huge_cache_test.cc | 5 +- tcmalloc/huge_page_aware_allocator.cc | 3 +- tcmalloc/huge_page_aware_allocator_test.cc | 9 ++- tcmalloc/huge_page_filler.h | 2 +- tcmalloc/huge_page_filler_test.cc | 10 +-- tcmalloc/huge_region_test.cc | 4 +- tcmalloc/internal/bits_test.cc | 2 +- tcmalloc/internal/environment.cc | 2 +- tcmalloc/internal/environment.h | 2 +- tcmalloc/internal/linked_list.h | 4 +- tcmalloc/internal/linked_list_test.cc | 4 +- tcmalloc/internal/logging.cc | 13 +-- tcmalloc/internal/logging.h | 41 ++++------ tcmalloc/internal/mincore_benchmark.cc | 3 +- tcmalloc/internal/percpu.cc | 30 +++---- tcmalloc/internal/percpu.h | 2 +- tcmalloc/internal/percpu_tcmalloc.h | 33 ++++---- tcmalloc/internal/percpu_tcmalloc_test.cc | 67 ++++++++-------- tcmalloc/internal/proc_maps.cc | 4 +- tcmalloc/internal/proc_maps.h | 2 +- tcmalloc/internal/range_tracker_benchmark.cc | 2 +- tcmalloc/internal/range_tracker_test.cc | 4 +- tcmalloc/internal/util.cc | 18 ++--- tcmalloc/libc_override_gcc_and_weak.h | 4 +- tcmalloc/libc_override_glibc.h | 31 ++++---- tcmalloc/malloc_extension.cc | 8 +- tcmalloc/malloc_extension.h | 10 +-- .../malloc_extension_system_malloc_test.cc | 5 +- tcmalloc/malloc_extension_test.cc | 1 - tcmalloc/mock_central_freelist.h | 2 +- tcmalloc/mock_transfer_cache.h | 6 +- tcmalloc/page_allocator.cc | 3 +- tcmalloc/page_allocator_test.cc | 4 +- tcmalloc/page_heap.h | 1 - tcmalloc/page_heap_test.cc | 2 +- tcmalloc/pagemap.h | 4 +- tcmalloc/pagemap_test.cc | 6 +- tcmalloc/parameters.cc | 4 +- tcmalloc/profile_test.cc | 4 +- tcmalloc/realloc_test.cc | 12 +-- ..._classes_with_runtime_size_classes_test.cc | 3 +- tcmalloc/span_test.cc | 2 +- tcmalloc/stack_trace_table_test.cc | 4 +- tcmalloc/static_vars.cc | 9 +-- tcmalloc/stats.h | 6 +- tcmalloc/stats_test.cc | 2 +- tcmalloc/system-alloc.cc | 4 +- tcmalloc/system-alloc_test.cc | 2 +- tcmalloc/tcmalloc.cc | 79 +++++++++---------- tcmalloc/tcmalloc.h | 6 +- tcmalloc/tcmalloc_large_test.cc | 8 +- tcmalloc/testing/aligned_new_test.cc | 4 +- .../testing/current_allocated_bytes_test.cc | 6 +- tcmalloc/testing/default_parameters_test.cc | 7 +- .../testing/empirical_distributions_test.cc | 4 +- tcmalloc/testing/empirical_driver.cc | 1 - tcmalloc/testing/empirical_test.cc | 4 +- tcmalloc/testing/largesmall_frag_test.cc | 4 +- tcmalloc/testing/limit_test.cc | 4 +- tcmalloc/testing/markidle_test.cc | 4 +- tcmalloc/testing/memalign_test.cc | 30 +++---- tcmalloc/testing/memory_errors_test.cc | 8 +- tcmalloc/testing/releasing_test.cc | 2 +- tcmalloc/testing/sample_size_class_test.cc | 4 +- tcmalloc/testing/sampler_test.cc | 69 ++++++++-------- tcmalloc/testing/sampling_memusage_test.cc | 4 +- tcmalloc/testing/sampling_test.cc | 8 +- tcmalloc/testing/startup_size_test.cc | 3 +- tcmalloc/testing/tcmalloc_benchmark.cc | 2 +- tcmalloc/testing/tcmalloc_test.cc | 30 ++++--- tcmalloc/testing/testutil.cc | 3 +- tcmalloc/testing/testutil.h | 2 +- tcmalloc/testing/thread_ctor_test.cc | 4 +- tcmalloc/testing/thread_ctor_test_lib.cc | 8 +- tcmalloc/testing/thread_manager.h | 2 +- tcmalloc/testing/threadcachesize_test.cc | 2 +- tcmalloc/thread_cache.cc | 5 +- tcmalloc/thread_cache.h | 22 ++---- tcmalloc/thread_cache_test.cc | 2 +- tcmalloc/tracking.h | 8 +- tcmalloc/transfer_cache_test.cc | 4 +- 91 files changed, 360 insertions(+), 429 deletions(-) mode change 100755 => 100644 tcmalloc/testing/sampler_test.cc diff --git a/tcmalloc/central_freelist.h b/tcmalloc/central_freelist.h index f822fbd27..0945d8af4 100644 --- a/tcmalloc/central_freelist.h +++ b/tcmalloc/central_freelist.h @@ -65,9 +65,7 @@ class CentralFreeList { size_t OverheadBytes(); // My size class. - size_t size_class() const { - return size_class_; - } + size_t size_class() const { return size_class_; } SpanStats GetSpanStats() const; diff --git a/tcmalloc/central_freelist_test.cc b/tcmalloc/central_freelist_test.cc index 0db4eb5a2..9b6f82635 100644 --- a/tcmalloc/central_freelist_test.cc +++ b/tcmalloc/central_freelist_test.cc @@ -16,9 +16,9 @@ #include +#include "absl/random/random.h" #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "absl/random/random.h" #include "tcmalloc/common.h" #include "tcmalloc/static_vars.h" diff --git a/tcmalloc/common.h b/tcmalloc/common.h index b7c5868a9..6d83c9377 100644 --- a/tcmalloc/common.h +++ b/tcmalloc/common.h @@ -337,7 +337,7 @@ class SizeMap { public: // Constructor should do nothing since we rely on explicit Init() // call, which may or may not be called before the constructor runs. - SizeMap() { } + SizeMap() {} // Initialize the mapping arrays void Init(); diff --git a/tcmalloc/cpu_cache.cc b/tcmalloc/cpu_cache.cc index ddea5e0e1..fa14b1838 100644 --- a/tcmalloc/cpu_cache.cc +++ b/tcmalloc/cpu_cache.cc @@ -633,9 +633,7 @@ static void ActivatePerCPUCaches() { class PerCPUInitializer { public: - PerCPUInitializer() { - ActivatePerCPUCaches(); - } + PerCPUInitializer() { ActivatePerCPUCaches(); } }; static PerCPUInitializer module_enter_exit; diff --git a/tcmalloc/cpu_cache.h b/tcmalloc/cpu_cache.h index 4ba619007..c89fd3b29 100644 --- a/tcmalloc/cpu_cache.h +++ b/tcmalloc/cpu_cache.h @@ -34,7 +34,6 @@ namespace tcmalloc { - class CPUCache { public: enum class ActivationMode { @@ -258,5 +257,5 @@ inline bool UsePerCpuCache() { return false; } -}; // namespace tcmalloc +}; // namespace tcmalloc #endif // TCMALLOC_CPU_CACHE_H_ diff --git a/tcmalloc/guarded_page_allocator.cc b/tcmalloc/guarded_page_allocator.cc index d47a48051..acc904aef 100644 --- a/tcmalloc/guarded_page_allocator.cc +++ b/tcmalloc/guarded_page_allocator.cc @@ -426,7 +426,6 @@ static void RecordTestFailure(absl::string_view error) { // // error contains the type of error to record. static void RecordCrash(absl::string_view error) { - RecordBazelWarning(error); RecordTestFailure(error); } @@ -461,8 +460,7 @@ static void SegvHandler(int signo, siginfo_t *info, void *context) { std::tie(offset, size) = Static::guardedpage_allocator().GetAllocationOffsetAndSize(fault); - Log(kLog, __FILE__, __LINE__, - "*** GWP-ASan has detected a memory error ***"); + Log(kLog, __FILE__, __LINE__, "*** GWP-ASan has detected a memory error ***"); Log(kLog, __FILE__, __LINE__, ">>> Access at offset", offset, "into buffer of length", size); Log(kLog, __FILE__, __LINE__, diff --git a/tcmalloc/guarded_page_allocator_benchmark.cc b/tcmalloc/guarded_page_allocator_benchmark.cc index 986a96b0a..a82cee0e5 100644 --- a/tcmalloc/guarded_page_allocator_benchmark.cc +++ b/tcmalloc/guarded_page_allocator_benchmark.cc @@ -12,12 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "tcmalloc/guarded_page_allocator.h" - #include -#include "benchmark/benchmark.h" #include "absl/base/internal/spinlock.h" +#include "benchmark/benchmark.h" +#include "tcmalloc/guarded_page_allocator.h" #include "tcmalloc/internal/logging.h" namespace tcmalloc { diff --git a/tcmalloc/guarded_page_allocator_test.cc b/tcmalloc/guarded_page_allocator_test.cc index 4206d6677..88f61f377 100644 --- a/tcmalloc/guarded_page_allocator_test.cc +++ b/tcmalloc/guarded_page_allocator_test.cc @@ -25,8 +25,6 @@ #include // NOLINT(build/c++11) #include -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/base/internal/spinlock.h" #include "absl/base/internal/sysinfo.h" #include "absl/container/flat_hash_set.h" @@ -34,6 +32,8 @@ #include "absl/strings/str_cat.h" #include "absl/time/clock.h" #include "absl/time/time.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "tcmalloc/common.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/static_vars.h" diff --git a/tcmalloc/huge_address_map_test.cc b/tcmalloc/huge_address_map_test.cc index 405fbb5b9..1d8469bc8 100644 --- a/tcmalloc/huge_address_map_test.cc +++ b/tcmalloc/huge_address_map_test.cc @@ -15,6 +15,7 @@ #include "tcmalloc/huge_address_map.h" #include + #include #include "gmock/gmock.h" diff --git a/tcmalloc/huge_allocator_test.cc b/tcmalloc/huge_allocator_test.cc index 1d73f2caa..8666b53fa 100644 --- a/tcmalloc/huge_allocator_test.cc +++ b/tcmalloc/huge_allocator_test.cc @@ -23,11 +23,11 @@ #include #include -#include "gtest/gtest.h" #include "absl/base/internal/cycleclock.h" #include "absl/random/random.h" #include "absl/time/clock.h" #include "absl/time/time.h" +#include "gtest/gtest.h" #include "tcmalloc/huge_pages.h" #include "tcmalloc/internal/logging.h" diff --git a/tcmalloc/huge_cache_test.cc b/tcmalloc/huge_cache_test.cc index 7de09e6ed..8ac21e717 100644 --- a/tcmalloc/huge_cache_test.cc +++ b/tcmalloc/huge_cache_test.cc @@ -23,14 +23,14 @@ #include #include -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/base/internal/cycleclock.h" #include "absl/memory/memory.h" #include "absl/random/random.h" #include "absl/strings/str_cat.h" #include "absl/time/clock.h" #include "absl/time/time.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "tcmalloc/huge_pages.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/stats.h" @@ -514,7 +514,6 @@ TEST_F(HugeCacheTest, Usage) { } class MinMaxTrackerTest : public testing::Test { - protected: void Advance(absl::Duration d) { clock_ += absl::ToDoubleSeconds(d) * GetFakeClockFrequency(); diff --git a/tcmalloc/huge_page_aware_allocator.cc b/tcmalloc/huge_page_aware_allocator.cc index 943f2d768..8f744655d 100644 --- a/tcmalloc/huge_page_aware_allocator.cc +++ b/tcmalloc/huge_page_aware_allocator.cc @@ -215,7 +215,8 @@ Span *HugePageAwareAllocator::AllocLarge(Length n, bool *from_released) { // typically faster and usually more space efficient, but it's sometimes // catastrophic. // - // See https://github.com/google/tcmalloc/tree/master/docs/regions-are-not-optional.md + // See + // https://github.com/google/tcmalloc/tree/master/docs/regions-are-not-optional.md // // So test directly if we're in the bad case--almost no binaries are. // If not, just fall back to direct allocation (and hope we do hit that case!) diff --git a/tcmalloc/huge_page_aware_allocator_test.cc b/tcmalloc/huge_page_aware_allocator_test.cc index 04b5e99c0..04fbe23c4 100644 --- a/tcmalloc/huge_page_aware_allocator_test.cc +++ b/tcmalloc/huge_page_aware_allocator_test.cc @@ -29,9 +29,6 @@ #include #include -#include "benchmark/benchmark.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/base/attributes.h" #include "absl/base/const_init.h" #include "absl/base/internal/spinlock.h" @@ -45,6 +42,9 @@ #include "absl/synchronization/barrier.h" #include "absl/synchronization/mutex.h" #include "absl/time/time.h" +#include "benchmark/benchmark.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "tcmalloc/common.h" #include "tcmalloc/huge_pages.h" #include "tcmalloc/internal/logging.h" @@ -169,7 +169,8 @@ class HugePageAwareAllocatorTest : public ::testing::Test { // TODO(b/128521238): scalable RNG absl::base_internal::SpinLockHolder h(&lock_); if (absl::Bernoulli(rng_, 1.0 / 1000)) { - Length n = Length(1024) * (1 + absl::LogUniform(rng_, 0, (1 << 8) - 1)); + Length n = + Length(1024) * (1 + absl::LogUniform(rng_, 0, (1 << 8) - 1)); n += Length(absl::Uniform(rng_, 0, 1024)); return n; } diff --git a/tcmalloc/huge_page_filler.h b/tcmalloc/huge_page_filler.h index 3c234817d..9e3e9fc88 100644 --- a/tcmalloc/huge_page_filler.h +++ b/tcmalloc/huge_page_filler.h @@ -1871,7 +1871,7 @@ inline void HugePageFiller::PrintInPbtxt(PbtxtRegion *hpaa) const { hpaa->PrintI64( "filler_hugepageable_used_bytes", static_cast(hugepage_frac() * - static_cast(allocated_.in_bytes()))); + static_cast(allocated_.in_bytes()))); hpaa->PrintI64("filler_num_pages_subreleased", subrelease_stats_.total_pages_subreleased.raw_num()); hpaa->PrintI64("filler_num_hugepages_broken", diff --git a/tcmalloc/huge_page_filler_test.cc b/tcmalloc/huge_page_filler_test.cc index add23b62f..a66e0449e 100644 --- a/tcmalloc/huge_page_filler_test.cc +++ b/tcmalloc/huge_page_filler_test.cc @@ -28,9 +28,6 @@ #include #include -#include "benchmark/benchmark.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/algorithm/container.h" #include "absl/base/internal/sysinfo.h" #include "absl/base/thread_annotations.h" @@ -46,6 +43,9 @@ #include "absl/synchronization/mutex.h" #include "absl/time/clock.h" #include "absl/time/time.h" +#include "benchmark/benchmark.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "tcmalloc/common.h" #include "tcmalloc/huge_pages.h" #include "tcmalloc/internal/logging.h" @@ -684,9 +684,7 @@ class FillerTest : public testing::TestWithParam { ResetClock(); } - ~FillerTest() override { - EXPECT_EQ(NHugePages(0), filler_.size()); - } + ~FillerTest() override { EXPECT_EQ(NHugePages(0), filler_.size()); } struct PAlloc { FakeTracker *pt; diff --git a/tcmalloc/huge_region_test.cc b/tcmalloc/huge_region_test.cc index 87914ef94..999861fe6 100644 --- a/tcmalloc/huge_region_test.cc +++ b/tcmalloc/huge_region_test.cc @@ -21,11 +21,11 @@ #include #include -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/random/random.h" #include "absl/time/clock.h" #include "absl/time/time.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "tcmalloc/common.h" #include "tcmalloc/huge_pages.h" #include "tcmalloc/internal/logging.h" diff --git a/tcmalloc/internal/bits_test.cc b/tcmalloc/internal/bits_test.cc index ccce1ef10..c1d3dce0a 100644 --- a/tcmalloc/internal/bits_test.cc +++ b/tcmalloc/internal/bits_test.cc @@ -18,9 +18,9 @@ #include #include +#include "absl/random/random.h" #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "absl/random/random.h" namespace tcmalloc { namespace tcmalloc_internal { diff --git a/tcmalloc/internal/environment.cc b/tcmalloc/internal/environment.cc index 1cee4d688..556e61b4c 100644 --- a/tcmalloc/internal/environment.cc +++ b/tcmalloc/internal/environment.cc @@ -24,7 +24,7 @@ namespace tcmalloc_internal { // return a const pointer into it. // e.g. { "SHELL=/bin/bash", "MY_ENV_VAR=1", "" } extern "C" char **environ; -const char* thread_safe_getenv(const char *env_var) { +const char *thread_safe_getenv(const char *env_var) { int var_len = strlen(env_var); char **envv = environ; diff --git a/tcmalloc/internal/environment.h b/tcmalloc/internal/environment.h index b0564c8eb..2f8fc18e9 100644 --- a/tcmalloc/internal/environment.h +++ b/tcmalloc/internal/environment.h @@ -30,7 +30,7 @@ namespace tcmalloc_internal { // from thread_safe_getenv() may be safely queried in a multi-threaded context. // If you have explicit synchronization with changes environment variables then // any copies of the returned pointer must be invalidated across modification. -const char* thread_safe_getenv(const char *env_var); +const char* thread_safe_getenv(const char* env_var); } // namespace tcmalloc_internal } // namespace tcmalloc diff --git a/tcmalloc/internal/linked_list.h b/tcmalloc/internal/linked_list.h index ee80ac85f..ecfd4a230 100644 --- a/tcmalloc/internal/linked_list.h +++ b/tcmalloc/internal/linked_list.h @@ -28,11 +28,11 @@ namespace tcmalloc { inline ABSL_ATTRIBUTE_ALWAYS_INLINE void *SLL_Next(void *t) { - return *(reinterpret_cast(t)); + return *(reinterpret_cast(t)); } inline void ABSL_ATTRIBUTE_ALWAYS_INLINE SLL_SetNext(void *t, void *n) { - *(reinterpret_cast(t)) = n; + *(reinterpret_cast(t)) = n; } inline void ABSL_ATTRIBUTE_ALWAYS_INLINE SLL_Push(void **list, void *element) { diff --git a/tcmalloc/internal/linked_list_test.cc b/tcmalloc/internal/linked_list_test.cc index fb8ade468..6051efca2 100644 --- a/tcmalloc/internal/linked_list_test.cc +++ b/tcmalloc/internal/linked_list_test.cc @@ -19,10 +19,10 @@ #include #include -#include "benchmark/benchmark.h" -#include "gtest/gtest.h" #include "absl/container/node_hash_set.h" #include "absl/random/random.h" +#include "benchmark/benchmark.h" +#include "gtest/gtest.h" #include "tcmalloc/internal/mock_span.h" namespace tcmalloc { diff --git a/tcmalloc/internal/logging.cc b/tcmalloc/internal/logging.cc index 4f8f006a2..5f80dcd53 100644 --- a/tcmalloc/internal/logging.cc +++ b/tcmalloc/internal/logging.cc @@ -38,7 +38,7 @@ ABSL_CONST_INIT static absl::base_internal::SpinLock crash_lock( static bool crashed = false; static const size_t kStatsBufferSize = 16 << 10; -static char stats_buffer[kStatsBufferSize] = { 0 }; +static char stats_buffer[kStatsBufferSize] = {0}; namespace tcmalloc { @@ -67,14 +67,9 @@ static Logger FormatLog(bool with_stack, const char* filename, int line, Logger state; state.p_ = state.buf_; state.end_ = state.buf_ + sizeof(state.buf_); - state.AddStr(filename, strlen(filename)) - && state.AddStr(":", 1) - && state.AddNum(line, 10) - && state.AddStr("]", 1) - && state.Add(a) - && state.Add(b) - && state.Add(c) - && state.Add(d); + state.AddStr(filename, strlen(filename)) && state.AddStr(":", 1) && + state.AddNum(line, 10) && state.AddStr("]", 1) && state.Add(a) && + state.Add(b) && state.Add(c) && state.Add(d); if (with_stack) { state.trace.depth = diff --git a/tcmalloc/internal/logging.h b/tcmalloc/internal/logging.h index 6a063c4cc..129fd6c1c 100644 --- a/tcmalloc/internal/logging.h +++ b/tcmalloc/internal/logging.h @@ -43,7 +43,6 @@ static constexpr int kMaxStackDepth = 64; // size/depth are made the same size as a pointer so that some generic // code below can conveniently cast them back and forth to void*. struct StackTrace { - // For small sampled objects, we allocate a full span to hold the // sampled object. However to avoid disturbing fragmentation // profiles, in such cases we also allocate a small proxy object @@ -74,8 +73,8 @@ struct StackTrace { }; enum LogMode { - kLog, // Just print the message - kLogWithStack, // Print the message and a stack trace + kLog, // Just print the message + kLogWithStack, // Print the message and a stack trace }; class Logger; @@ -83,25 +82,19 @@ class Logger; // A LogItem holds any of the argument types that can be passed to Log() class LogItem { public: - LogItem() : tag_(kEnd) { } - LogItem(const char* v) : tag_(kStr) { u_.str = v; } - LogItem(int v) : tag_(kSigned) { u_.snum = v; } - LogItem(long v) : tag_(kSigned) { u_.snum = v; } - LogItem(long long v) : tag_(kSigned) { u_.snum = v; } - LogItem(unsigned int v) : tag_(kUnsigned) { u_.unum = v; } - LogItem(unsigned long v) : tag_(kUnsigned) { u_.unum = v; } + LogItem() : tag_(kEnd) {} + LogItem(const char* v) : tag_(kStr) { u_.str = v; } + LogItem(int v) : tag_(kSigned) { u_.snum = v; } + LogItem(long v) : tag_(kSigned) { u_.snum = v; } + LogItem(long long v) : tag_(kSigned) { u_.snum = v; } + LogItem(unsigned int v) : tag_(kUnsigned) { u_.unum = v; } + LogItem(unsigned long v) : tag_(kUnsigned) { u_.unum = v; } LogItem(unsigned long long v) : tag_(kUnsigned) { u_.unum = v; } - LogItem(const void* v) : tag_(kPtr) { u_.ptr = v; } + LogItem(const void* v) : tag_(kPtr) { u_.ptr = v; } private: friend class Logger; - enum Tag { - kStr, - kSigned, - kUnsigned, - kPtr, - kEnd - }; + enum Tag { kStr, kSigned, kUnsigned, kPtr, kEnd }; Tag tag_; union { const char* str; @@ -111,9 +104,9 @@ class LogItem { } u_; }; -extern void Log(LogMode mode, const char* filename, int line, - LogItem a, LogItem b = LogItem(), - LogItem c = LogItem(), LogItem d = LogItem()); +extern void Log(LogMode mode, const char* filename, int line, LogItem a, + LogItem b = LogItem(), LogItem c = LogItem(), + LogItem d = LogItem()); enum CrashMode { kCrash, // Print the message and crash @@ -141,7 +134,7 @@ extern void (*log_message_writer)(const char* msg, int length); #ifndef NDEBUG #define ASSERT(cond) CHECK_CONDITION(cond) #else -#define ASSERT(cond) ((void) 0) +#define ASSERT(cond) ((void)0) #endif // Our wrapper for __builtin_assume, allowing us to check the assumption on @@ -164,8 +157,8 @@ extern void (*log_message_writer)(const char* msg, int length); // Print into buffer class TCMalloc_Printer { private: - char* buf_; // Where should we write next - int left_; // Space left in buffer (including space for \0) + char* buf_; // Where should we write next + int left_; // Space left in buffer (including space for \0) int required_; // Space we needed to complete all printf calls up to this // point diff --git a/tcmalloc/internal/mincore_benchmark.cc b/tcmalloc/internal/mincore_benchmark.cc index 555e546e2..d284ba030 100644 --- a/tcmalloc/internal/mincore_benchmark.cc +++ b/tcmalloc/internal/mincore_benchmark.cc @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "tcmalloc/internal/mincore.h" - #include #include @@ -25,6 +23,7 @@ #include "absl/memory/memory.h" #include "benchmark/benchmark.h" #include "tcmalloc/internal/logging.h" +#include "tcmalloc/internal/mincore.h" namespace tcmalloc { namespace { diff --git a/tcmalloc/internal/percpu.cc b/tcmalloc/internal/percpu.cc index 397d532d6..48151337f 100644 --- a/tcmalloc/internal/percpu.cc +++ b/tcmalloc/internal/percpu.cc @@ -40,23 +40,19 @@ namespace percpu { // Restartable Sequence (RSEQ) extern "C" { - // We provide a per-thread value (defined in percpu_.c) which both tracks - // thread-local initialization state and (with RSEQ) provides an atomic - // in-memory reference for this thread's execution CPU. This value is only - // valid when the thread is currently executing - // Possible values: - // Unavailable/uninitialized: - // { kCpuIdUnsupported, kCpuIdUninitialized } - // Initialized, available: - // [0, NumCpus()) (Always updated at context-switch) +// We provide a per-thread value (defined in percpu_.c) which both tracks +// thread-local initialization state and (with RSEQ) provides an atomic +// in-memory reference for this thread's execution CPU. This value is only +// valid when the thread is currently executing +// Possible values: +// Unavailable/uninitialized: +// { kCpuIdUnsupported, kCpuIdUninitialized } +// Initialized, available: +// [0, NumCpus()) (Always updated at context-switch) ABSL_PER_THREAD_TLS_KEYWORD ABSL_ATTRIBUTE_WEAK volatile kernel_rseq __rseq_abi = { - 0, - static_cast(kCpuIdUninitialized), - 0, - 0, - {0, 0}, - {{kCpuIdUninitialized, kCpuIdUninitialized}}, + 0, static_cast(kCpuIdUninitialized), 0, 0, + {0, 0}, {{kCpuIdUninitialized, kCpuIdUninitialized}}, }; ABSL_PER_THREAD_TLS_KEYWORD ABSL_ATTRIBUTE_WEAK volatile uint32_t @@ -105,9 +101,7 @@ static bool InitThreadPerCpu() { return false; } -bool UsingFlatVirtualCpus() { - return false; -} +bool UsingFlatVirtualCpus() { return false; } static void InitPerCpu() { CHECK_CONDITION(absl::base_internal::NumCPUs() <= diff --git a/tcmalloc/internal/percpu.h b/tcmalloc/internal/percpu.h index 3524c021b..728dca20f 100644 --- a/tcmalloc/internal/percpu.h +++ b/tcmalloc/internal/percpu.h @@ -318,7 +318,7 @@ inline int CompareAndSwapUnsafe(int target_cpu, std::atomic *p, default: __builtin_unreachable(); } -#else // !TCMALLOC_PERCPU_USE_RSEQ +#else // !TCMALLOC_PERCPU_USE_RSEQ __builtin_unreachable(); #endif // !TCMALLOC_PERCPU_USE_RSEQ } diff --git a/tcmalloc/internal/percpu_tcmalloc.h b/tcmalloc/internal/percpu_tcmalloc.h index 3ef67fa7d..c1e5e8f36 100644 --- a/tcmalloc/internal/percpu_tcmalloc.h +++ b/tcmalloc/internal/percpu_tcmalloc.h @@ -329,13 +329,14 @@ static inline ABSL_ATTRIBUTE_ALWAYS_INLINE int TcmallocSlab_Push( "5:\n" : #if !TCMALLOC_PERCPU_USE_RSEQ_ASM_GOTO - [overflow] "=@ccae"(overflow) + [ overflow ] "=@ccae"(overflow) #endif - : [rseq_abi] "r"(&__rseq_abi), - [rseq_cs_offset] "n"(offsetof(kernel_rseq, rseq_cs)), - [rseq_cpu_offset] "r"(tcmalloc_virtual_cpu_id_offset), - [rseq_sig] "in"(TCMALLOC_PERCPU_RSEQ_SIGNATURE), [shift] "in"(Shift), - [slabs] "r"(slabs), [cl] "r"(cl), [item] "r"(item) + : [ rseq_abi ] "r"(&__rseq_abi), + [ rseq_cs_offset ] "n"(offsetof(kernel_rseq, rseq_cs)), + [ rseq_cpu_offset ] "r"(tcmalloc_virtual_cpu_id_offset), + [ rseq_sig ] "in"(TCMALLOC_PERCPU_RSEQ_SIGNATURE), + [ shift ] "in"(Shift), [ slabs ] "r"(slabs), [ cl ] "r"(cl), + [ item ] "r"(item) : "cc", "memory", "r10", "r11" #if TCMALLOC_PERCPU_USE_RSEQ_ASM_GOTO : overflow_label @@ -454,16 +455,16 @@ static inline ABSL_ATTRIBUTE_ALWAYS_INLINE void* TcmallocSlab_Pop( "mov %w[current], (%[scratch], %[cl], 8)\n" // Commit "5:\n" - : [result] "=&r"(result), + : [ result ] "=&r"(result), #if !TCMALLOC_PERCPU_USE_RSEQ_ASM_GOTO_OUTPUT - [underflow] "=@ccbe"(underflow), + [ underflow ] "=@ccbe"(underflow), #endif - [scratch] "=&r"(scratch), [current] "=&r"(current) - : [rseq_abi] "r"(&__rseq_abi), - [rseq_cs_offset] "n"(offsetof(kernel_rseq, rseq_cs)), - [rseq_cpu_offset] "r"(tcmalloc_virtual_cpu_id_offset), - [rseq_sig] "n"(TCMALLOC_PERCPU_RSEQ_SIGNATURE), [shift] "n"(Shift), - [slabs] "r"(slabs), [cl] "r"(cl) + [ scratch ] "=&r"(scratch), [ current ] "=&r"(current) + : [ rseq_abi ] "r"(&__rseq_abi), + [ rseq_cs_offset ] "n"(offsetof(kernel_rseq, rseq_cs)), + [ rseq_cpu_offset ] "r"(tcmalloc_virtual_cpu_id_offset), + [ rseq_sig ] "n"(TCMALLOC_PERCPU_RSEQ_SIGNATURE), + [ shift ] "n"(Shift), [ slabs ] "r"(slabs), [ cl ] "r"(cl) : "cc", "memory" #if TCMALLOC_PERCPU_USE_RSEQ_ASM_GOTO_OUTPUT : underflow_path @@ -537,7 +538,7 @@ inline size_t TcmallocSlab::PushBatch(size_t cl, default: __builtin_unreachable(); } -#else // !TCMALLOC_PERCPU_USE_RSEQ +#else // !TCMALLOC_PERCPU_USE_RSEQ __builtin_unreachable(); #endif // !TCMALLOC_PERCPU_USE_RSEQ } else { @@ -577,7 +578,7 @@ inline size_t TcmallocSlab::PopBatch(size_t cl, void** batch, // PopBatch is implemented in assembly, msan does not know that the returned // batch is initialized. ANNOTATE_MEMORY_IS_INITIALIZED(batch, n * sizeof(batch[0])); -#else // !TCMALLOC_PERCPU_USE_RSEQ +#else // !TCMALLOC_PERCPU_USE_RSEQ __builtin_unreachable(); #endif // !TCMALLOC_PERCPU_USE_RSEQ } else { diff --git a/tcmalloc/internal/percpu_tcmalloc_test.cc b/tcmalloc/internal/percpu_tcmalloc_test.cc index 0174cc625..b23c9aa74 100644 --- a/tcmalloc/internal/percpu_tcmalloc_test.cc +++ b/tcmalloc/internal/percpu_tcmalloc_test.cc @@ -23,9 +23,6 @@ #include // NOLINT(build/c++11) #include -#include "benchmark/benchmark.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/base/internal/sysinfo.h" #include "absl/container/fixed_array.h" #include "absl/container/flat_hash_set.h" @@ -37,6 +34,9 @@ #include "absl/time/clock.h" #include "absl/time/time.h" #include "absl/types/span.h" +#include "benchmark/benchmark.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "tcmalloc/internal/config.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/internal/util.h" @@ -89,9 +89,7 @@ void RunOnSingleCpuWithRemoteCpu(std::function test) { // Equivalent to RunOnSingleCpuWithRemoteCpu, except that only the CPU the // functor is executing on is passed. void RunOnSingleCpu(std::function test) { - auto wrapper = [&test] (int this_cpu, int unused) { - return test(this_cpu); - }; + auto wrapper = [&test](int this_cpu, int unused) { return test(this_cpu); }; RunOnSingleCpuWithRemoteCpu(wrapper); } @@ -322,8 +320,7 @@ TEST_P(TcmallocSlabTest, Unit) { // This is imperfect but the window between operations below is small. We // can make this more precise around individual operations if we see // measurable flakiness as a result. - if (aff.Tampered()) - break; + if (aff.Tampered()) break; #endif // Check new slab state. @@ -752,32 +749,32 @@ TEST(TcmallocSlab, CriticalSectionMetadata) { const kernel_rseq_cs** cs_array_start = nullptr; const kernel_rseq_cs** cs_array_end = nullptr; - absl::debugging_internal::ForEachSection(fd, [&](const absl::string_view name, - const ElfW(Shdr) & hdr) { - uintptr_t start = relocation + reinterpret_cast(hdr.sh_addr); - uintptr_t end = - relocation + reinterpret_cast(hdr.sh_addr + hdr.sh_size); - - if (name == "__rseq_cs") { - EXPECT_EQ(cs_start, nullptr); - EXPECT_EQ(start % alignof(kernel_rseq_cs), 0); - EXPECT_EQ(end % alignof(kernel_rseq_cs), 0); - EXPECT_LT(start, end) << "__rseq_cs must not be empty"; - - cs_start = reinterpret_cast(start); - cs_end = reinterpret_cast(end); - } else if (name == "__rseq_cs_ptr_array") { - EXPECT_EQ(cs_array_start, nullptr); - EXPECT_EQ(start % alignof(kernel_rseq_cs*), 0); - EXPECT_EQ(end % alignof(kernel_rseq_cs*), 0); - EXPECT_LT(start, end) << "__rseq_cs_ptr_array must not be empty"; - - cs_array_start = reinterpret_cast(start); - cs_array_end = reinterpret_cast(end); - } + absl::debugging_internal::ForEachSection( + fd, [&](const absl::string_view name, const ElfW(Shdr) & hdr) { + uintptr_t start = relocation + reinterpret_cast(hdr.sh_addr); + uintptr_t end = + relocation + reinterpret_cast(hdr.sh_addr + hdr.sh_size); + + if (name == "__rseq_cs") { + EXPECT_EQ(cs_start, nullptr); + EXPECT_EQ(start % alignof(kernel_rseq_cs), 0); + EXPECT_EQ(end % alignof(kernel_rseq_cs), 0); + EXPECT_LT(start, end) << "__rseq_cs must not be empty"; + + cs_start = reinterpret_cast(start); + cs_end = reinterpret_cast(end); + } else if (name == "__rseq_cs_ptr_array") { + EXPECT_EQ(cs_array_start, nullptr); + EXPECT_EQ(start % alignof(kernel_rseq_cs*), 0); + EXPECT_EQ(end % alignof(kernel_rseq_cs*), 0); + EXPECT_LT(start, end) << "__rseq_cs_ptr_array must not be empty"; + + cs_array_start = reinterpret_cast(start); + cs_array_end = reinterpret_cast(end); + } - return true; - }); + return true; + }); close(fd); @@ -805,7 +802,7 @@ TEST(TcmallocSlab, CriticalSectionMetadata) { static void BM_PushPop(benchmark::State& state) { CHECK_CONDITION(IsFast()); - RunOnSingleCpu([&] (int this_cpu) { + RunOnSingleCpu([&](int this_cpu) { const int kBatchSize = 32; TcmallocSlab slab; slab.Init( @@ -832,7 +829,7 @@ BENCHMARK(BM_PushPop); static void BM_PushPopBatch(benchmark::State& state) { CHECK_CONDITION(IsFast()); - RunOnSingleCpu([&] (int this_cpu) { + RunOnSingleCpu([&](int this_cpu) { const int kBatchSize = 32; TcmallocSlab slab; slab.Init( diff --git a/tcmalloc/internal/proc_maps.cc b/tcmalloc/internal/proc_maps.cc index 71bf9835e..4e42a610f 100644 --- a/tcmalloc/internal/proc_maps.cc +++ b/tcmalloc/internal/proc_maps.cc @@ -82,9 +82,7 @@ ProcMapsIterator::~ProcMapsIterator() { delete dynamic_buffer_; } -bool ProcMapsIterator::Valid() const { - return fd_ != -1; -} +bool ProcMapsIterator::Valid() const { return fd_ != -1; } bool ProcMapsIterator::NextExt(uint64_t* start, uint64_t* end, char** flags, uint64_t* offset, int64_t* inode, diff --git a/tcmalloc/internal/proc_maps.h b/tcmalloc/internal/proc_maps.h index e4e64e916..14c669cda 100644 --- a/tcmalloc/internal/proc_maps.h +++ b/tcmalloc/internal/proc_maps.h @@ -54,7 +54,7 @@ class ProcMapsIterator { char* etext_; // end of text char* nextline_; // start of next line char* ebuf_; // end of buffer (1 char for a nul) - int fd_; // filehandle on /proc/*/maps + int fd_; // filehandle on /proc/*/maps pid_t pid_; char flags_[10]; Buffer* dynamic_buffer_; // dynamically-allocated Buffer diff --git a/tcmalloc/internal/range_tracker_benchmark.cc b/tcmalloc/internal/range_tracker_benchmark.cc index 0ad5ae9cf..688e7981e 100644 --- a/tcmalloc/internal/range_tracker_benchmark.cc +++ b/tcmalloc/internal/range_tracker_benchmark.cc @@ -144,7 +144,7 @@ enum SearchDirection { }; template -ABSL_ATTRIBUTE_NOINLINE size_t ExamineDoFind(Bitmap *map, size_t index) { +ABSL_ATTRIBUTE_NOINLINE size_t ExamineDoFind(Bitmap* map, size_t index) { if (Dir == Forward) { if (Goal) { return map->FindSet(index); diff --git a/tcmalloc/internal/range_tracker_test.cc b/tcmalloc/internal/range_tracker_test.cc index 8b6b2b07a..ac047f642 100644 --- a/tcmalloc/internal/range_tracker_test.cc +++ b/tcmalloc/internal/range_tracker_test.cc @@ -18,12 +18,12 @@ #include #include -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/base/attributes.h" #include "absl/container/fixed_array.h" #include "absl/random/distributions.h" #include "absl/random/random.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" namespace tcmalloc { namespace { diff --git a/tcmalloc/internal/util.cc b/tcmalloc/internal/util.cc index 8e5f35ad6..330c18e6a 100644 --- a/tcmalloc/internal/util.cc +++ b/tcmalloc/internal/util.cc @@ -62,10 +62,8 @@ ssize_t signal_safe_write(int fd, const char *buf, size_t count, do { rc = write(fd, buf + total_bytes, count - total_bytes); - if (rc > 0) - total_bytes += rc; - } while ((rc > 0 && count > total_bytes ) || - (rc == -1 && errno == EINTR)); + if (rc > 0) total_bytes += rc; + } while ((rc > 0 && count > total_bytes) || (rc == -1 && errno == EINTR)); if (bytes_written != nullptr) *bytes_written = total_bytes; @@ -84,7 +82,8 @@ int signal_safe_poll(struct pollfd *fds, int nfds, absl::Duration timeout) { if (elapsed > absl::ZeroDuration()) ::absl::SleepFor(::absl::Milliseconds(1)); elapsed += absl::Milliseconds(1); - while ((rc = poll(fds, nfds, 0)) == -1 && errno == EINTR) {} + while ((rc = poll(fds, nfds, 0)) == -1 && errno == EINTR) { + } } return rc; @@ -105,19 +104,16 @@ ssize_t signal_safe_read(int fd, char *buf, size_t count, size_t *bytes_read) { do { rc = read(fd, buf + total_bytes, count - total_bytes); - if (rc > 0) - total_bytes += rc; + if (rc > 0) total_bytes += rc; - if (rc == 0) - break; // EOF + if (rc == 0) break; // EOF // try again if there's space to fill, no (non-interrupt) error, // and data is available. } while (total_bytes < count && (rc > 0 || errno == EINTR) && (signal_safe_poll(&pfd, 1, absl::ZeroDuration()) == 1 || total_bytes == 0)); - if (bytes_read) - *bytes_read = total_bytes; + if (bytes_read) *bytes_read = total_bytes; if (rc != -1 || errno == EINTR) rc = total_bytes; // return the cumulative bytes read diff --git a/tcmalloc/libc_override_gcc_and_weak.h b/tcmalloc/libc_override_gcc_and_weak.h index 3954424b5..b5a43d023 100644 --- a/tcmalloc/libc_override_gcc_and_weak.h +++ b/tcmalloc/libc_override_gcc_and_weak.h @@ -28,7 +28,7 @@ #include "tcmalloc/tcmalloc.h" #ifndef __GNUC__ -# error libc_override_gcc_and_weak.h is for gcc distributions only. +#error libc_override_gcc_and_weak.h is for gcc distributions only. #endif // visibility("default") ensures that these symbols are always exported, even @@ -108,6 +108,6 @@ struct mallinfo mallinfo(void) noexcept size_t malloc_size(void* p) noexcept TCMALLOC_ALIAS(TCMallocInternalMallocSize); size_t malloc_usable_size(void* p) noexcept TCMALLOC_ALIAS(TCMallocInternalMallocSize); -} // extern "C" +} // extern "C" #endif // TCMALLOC_LIBC_OVERRIDE_GCC_AND_WEAK_INL_H_ diff --git a/tcmalloc/libc_override_glibc.h b/tcmalloc/libc_override_glibc.h index 2d971cfa6..8e23b6eb7 100644 --- a/tcmalloc/libc_override_glibc.h +++ b/tcmalloc/libc_override_glibc.h @@ -23,7 +23,7 @@ #include "tcmalloc/tcmalloc.h" #ifndef __GLIBC__ -# error libc_override_glibc.h is for glibc distributions only. +#error libc_override_glibc.h is for glibc distributions only. #endif // In glibc, the memory-allocation methods are weak symbols, so we can @@ -40,7 +40,7 @@ // If we get here, we're a gcc system, so do all the overriding we do // with gcc. This does the overriding of all the 'normal' memory // allocation. -# include "libc_override_gcc_and_weak.h" +#include "libc_override_gcc_and_weak.h" // We also have to do some glibc-specific overriding. Some library // routines on RedHat 9 allocate memory using malloc() and free it @@ -68,11 +68,10 @@ void* __libc_pvalloc(size_t size) noexcept TCMALLOC_ALIAS(TCMallocInternalPvalloc); int __posix_memalign(void** r, size_t a, size_t s) noexcept TCMALLOC_ALIAS(TCMallocInternalPosixMemalign); -} // extern "C" +} // extern "C" #endif // #if defined(__GNUC__) && !defined(__MACH__) - // We also have to hook libc malloc. While our work with weak symbols // should make sure libc malloc is never called in most situations, it // can be worked around by shared libraries with the DEEPBIND @@ -80,18 +79,18 @@ int __posix_memalign(void** r, size_t a, size_t s) noexcept // routines even in that situation. In other situations, this hook // should never be called. extern "C" { -static void* glibc_override_malloc(size_t size, const void *caller) { +static void* glibc_override_malloc(size_t size, const void* caller) { return TCMallocInternalMalloc(size); } -static void* glibc_override_realloc(void *ptr, size_t size, - const void *caller) { +static void* glibc_override_realloc(void* ptr, size_t size, + const void* caller) { return TCMallocInternalRealloc(ptr, size); } -static void glibc_override_free(void *ptr, const void *caller) { +static void glibc_override_free(void* ptr, const void* caller) { TCMallocInternalFree(ptr); } static void* glibc_override_memalign(size_t align, size_t size, - const void *caller) { + const void* caller) { return TCMallocInternalMemalign(align, size); } @@ -104,18 +103,18 @@ static void* glibc_override_memalign(size_t align, size_t size, // Glibc-2.14 and above make __malloc_hook and friends volatile #ifndef __MALLOC_HOOK_VOLATILE -#define __MALLOC_HOOK_VOLATILE /**/ +#define __MALLOC_HOOK_VOLATILE /**/ #endif -void* (* __MALLOC_HOOK_VOLATILE __malloc_hook)(size_t, const void*) = +void* (*__MALLOC_HOOK_VOLATILE __malloc_hook)(size_t, const void*) = &glibc_override_malloc; -void* (* __MALLOC_HOOK_VOLATILE __realloc_hook)(void*, size_t, const void*) = +void* (*__MALLOC_HOOK_VOLATILE __realloc_hook)(void*, size_t, const void*) = &glibc_override_realloc; -void (* __MALLOC_HOOK_VOLATILE __free_hook)(void*, const void*) = - &glibc_override_free; -void* (* __MALLOC_HOOK_VOLATILE __memalign_hook)(size_t,size_t, const void*) = +void (*__MALLOC_HOOK_VOLATILE __free_hook)(void*, + const void*) = &glibc_override_free; +void* (*__MALLOC_HOOK_VOLATILE __memalign_hook)(size_t, size_t, const void*) = &glibc_override_memalign; -} // extern "C" +} // extern "C" #endif // TCMALLOC_LIBC_OVERRIDE_GLIBC_INL_H_ diff --git a/tcmalloc/malloc_extension.cc b/tcmalloc/malloc_extension.cc index 8a850fb9c..9d5f6aad9 100644 --- a/tcmalloc/malloc_extension.cc +++ b/tcmalloc/malloc_extension.cc @@ -239,7 +239,7 @@ void MallocExtension::SetProfileSamplingRate(int64_t rate) { MallocExtension_Internal_SetProfileSamplingRate(rate); } #endif - (void) rate; + (void)rate; } int64_t MallocExtension::GetGuardedSamplingRate() { @@ -262,7 +262,7 @@ void MallocExtension::SetGuardedSamplingRate(int64_t rate) { MallocExtension_Internal_SetGuardedSamplingRate(rate); #else - (void) rate; + (void)rate; #endif } @@ -306,7 +306,7 @@ void MallocExtension::SetMaxPerCpuCacheSize(int32_t value) { MallocExtension_Internal_SetMaxPerCpuCacheSize(value); #else - (void) value; + (void)value; #endif } @@ -330,7 +330,7 @@ void MallocExtension::SetMaxTotalThreadCacheBytes(int64_t value) { MallocExtension_Internal_SetMaxTotalThreadCacheBytes(value); #else - (void) value; + (void)value; #endif } diff --git a/tcmalloc/malloc_extension.h b/tcmalloc/malloc_extension.h index e0087f265..04ef318da 100644 --- a/tcmalloc/malloc_extension.h +++ b/tcmalloc/malloc_extension.h @@ -176,8 +176,8 @@ class MallocExtension final { // Gets a human readable description of the current state of the malloc data // structures. // - // See https://github.com/google/tcmalloc/tree/master/docs/stats.md for how to interpret these - // statistics. + // See https://github.com/google/tcmalloc/tree/master/docs/stats.md for how to + // interpret these statistics. static std::string GetStats(); // ------------------------------------------------------------------- @@ -362,11 +362,7 @@ class MallocExtension final { // new, or new[], and must refer to memory that is currently allocated (so, // for instance, you should not pass in a pointer after having called free() // on it). - enum class Ownership { - kUnknown = 0, - kOwned, - kNotOwned - }; + enum class Ownership { kUnknown = 0, kOwned, kNotOwned }; static Ownership GetOwnership(const void* p); // Type used by GetProperties. See comment on GetProperties. diff --git a/tcmalloc/malloc_extension_system_malloc_test.cc b/tcmalloc/malloc_extension_system_malloc_test.cc index 81e7afa01..da12ddca7 100644 --- a/tcmalloc/malloc_extension_system_malloc_test.cc +++ b/tcmalloc/malloc_extension_system_malloc_test.cc @@ -15,9 +15,9 @@ // These tests assume TCMalloc is not linked in, and therefore the features // exposed by MallocExtension should be no-ops, but otherwise safe to call. +#include "absl/random/random.h" #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "absl/random/random.h" #include "tcmalloc/malloc_extension.h" namespace tcmalloc { @@ -38,7 +38,8 @@ TEST(MallocExtension, SnapshotCurrentIsEmpty) { // All of the profiles should be empty. ProfileType types[] = { ProfileType::kHeap, - ProfileType::kFragmentation, ProfileType::kPeakHeap, + ProfileType::kFragmentation, + ProfileType::kPeakHeap, ProfileType::kAllocations, }; diff --git a/tcmalloc/malloc_extension_test.cc b/tcmalloc/malloc_extension_test.cc index 075a7877c..514c503f8 100644 --- a/tcmalloc/malloc_extension_test.cc +++ b/tcmalloc/malloc_extension_test.cc @@ -23,7 +23,6 @@ namespace tcmalloc { namespace { TEST(MallocExtension, BackgroundReleaseRate) { - // Mutate via MallocExtension. MallocExtension::SetBackgroundReleaseRate( MallocExtension::BytesPerSecond{100 << 20}); diff --git a/tcmalloc/mock_central_freelist.h b/tcmalloc/mock_central_freelist.h index d00213d0d..26d5d2b90 100644 --- a/tcmalloc/mock_central_freelist.h +++ b/tcmalloc/mock_central_freelist.h @@ -17,8 +17,8 @@ #include -#include "gmock/gmock.h" #include "absl/base/internal/spinlock.h" +#include "gmock/gmock.h" namespace tcmalloc { diff --git a/tcmalloc/mock_transfer_cache.h b/tcmalloc/mock_transfer_cache.h index 2ca3f4302..f160bdfe6 100644 --- a/tcmalloc/mock_transfer_cache.h +++ b/tcmalloc/mock_transfer_cache.h @@ -19,9 +19,9 @@ #include -#include "gmock/gmock.h" #include "absl/random/distributions.h" #include "absl/random/random.h" +#include "gmock/gmock.h" #include "tcmalloc/common.h" #include "tcmalloc/mock_central_freelist.h" @@ -117,9 +117,7 @@ class FakeTransferCacheEnvironment { cache_.Init(1); } - ~FakeTransferCacheEnvironment() { - Drain(); - } + ~FakeTransferCacheEnvironment() { Drain(); } void Shrink() { cache_.ShrinkCache(); } void Grow() { cache_.GrowCache(); } diff --git a/tcmalloc/page_allocator.cc b/tcmalloc/page_allocator.cc index 727724d8c..0f0364cdc 100644 --- a/tcmalloc/page_allocator.cc +++ b/tcmalloc/page_allocator.cc @@ -110,8 +110,7 @@ void PageAllocator::ShrinkToUsageLimit() { kCrash, __FILE__, __LINE__, "Hit hard tcmalloc heap limit (e.g. --tcmalloc_heap_size_hard_limit). " "Aborting.\nIt was most likely set to catch " - "allocations that would crash the process anyway. " - ); + "allocations that would crash the process anyway. "); } // Print logs once. diff --git a/tcmalloc/page_allocator_test.cc b/tcmalloc/page_allocator_test.cc index a3c772036..daf83c713 100644 --- a/tcmalloc/page_allocator_test.cc +++ b/tcmalloc/page_allocator_test.cc @@ -25,13 +25,13 @@ #include #include -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/base/internal/spinlock.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" #include "absl/time/clock.h" #include "absl/time/time.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/malloc_extension.h" #include "tcmalloc/page_allocator_test_util.h" diff --git a/tcmalloc/page_heap.h b/tcmalloc/page_heap.h index caf6faab1..0adea0295 100644 --- a/tcmalloc/page_heap.h +++ b/tcmalloc/page_heap.h @@ -82,7 +82,6 @@ class PageHeap final : public PageAllocatorInterface { ABSL_LOCKS_EXCLUDED(pageheap_lock) override; private: - // We segregate spans of a given size into two circular linked // lists: one for normal spans, and one for spans whose memory // has been returned to the system. diff --git a/tcmalloc/page_heap_test.cc b/tcmalloc/page_heap_test.cc index f30753dcd..981cea866 100644 --- a/tcmalloc/page_heap_test.cc +++ b/tcmalloc/page_heap_test.cc @@ -20,9 +20,9 @@ #include #include -#include "gtest/gtest.h" #include "absl/base/internal/spinlock.h" #include "absl/memory/memory.h" +#include "gtest/gtest.h" #include "tcmalloc/common.h" #include "tcmalloc/pagemap.h" #include "tcmalloc/static_vars.h" diff --git a/tcmalloc/pagemap.h b/tcmalloc/pagemap.h index d52b4f74f..f6e6b1752 100644 --- a/tcmalloc/pagemap.h +++ b/tcmalloc/pagemap.h @@ -72,7 +72,7 @@ class PageMap2 { void* hugepage[kLeafHugepages]; }; - Leaf* root_[kRootLength]; // Top-level node + Leaf* root_[kRootLength]; // Top-level node size_t bytes_used_; public: @@ -153,7 +153,7 @@ class PageMap2 { bool Ensure(Number start, size_t n) { ASSERT(n > 0); - for (Number key = start; key <= start + n - 1; ) { + for (Number key = start; key <= start + n - 1;) { const Number i1 = key >> kLeafBits; // Check for overflow diff --git a/tcmalloc/pagemap_test.cc b/tcmalloc/pagemap_test.cc index 71686c6b4..d389222ca 100644 --- a/tcmalloc/pagemap_test.cc +++ b/tcmalloc/pagemap_test.cc @@ -24,8 +24,8 @@ #include #include -#include "gtest/gtest.h" #include "absl/random/random.h" +#include "gtest/gtest.h" #include "tcmalloc/common.h" // Note: we leak memory every time a map is constructed, so do not @@ -35,9 +35,7 @@ namespace tcmalloc { namespace { // Pick span pointer to use for page numbered i -void* span(intptr_t i) { - return reinterpret_cast(i+1); -} +void* span(intptr_t i) { return reinterpret_cast(i + 1); } // Pick sizeclass to use for page numbered i uint8_t sc(intptr_t i) { return i % 16; } diff --git a/tcmalloc/parameters.cc b/tcmalloc/parameters.cc index 8a4249089..74485af01 100644 --- a/tcmalloc/parameters.cc +++ b/tcmalloc/parameters.cc @@ -62,9 +62,7 @@ void Parameters::set_hpaa_subrelease(bool value) { } ABSL_CONST_INIT std::atomic - Parameters::background_release_rate_(MallocExtension::BytesPerSecond{ - 0 - }); + Parameters::background_release_rate_(MallocExtension::BytesPerSecond{0}); ABSL_CONST_INIT std::atomic Parameters::guarded_sampling_rate_( 50 * kDefaultProfileSamplingRate); ABSL_CONST_INIT std::atomic Parameters::lazy_per_cpu_caches_enabled_( diff --git a/tcmalloc/profile_test.cc b/tcmalloc/profile_test.cc index d214b587e..fe8918fcc 100644 --- a/tcmalloc/profile_test.cc +++ b/tcmalloc/profile_test.cc @@ -24,10 +24,10 @@ #include #include -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/container/flat_hash_map.h" #include "absl/synchronization/blocking_counter.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "tcmalloc/internal/declarations.h" #include "tcmalloc/internal/linked_list.h" #include "tcmalloc/malloc_extension.h" diff --git a/tcmalloc/realloc_test.cc b/tcmalloc/realloc_test.cc index c8fd4589b..43eb0e05a 100644 --- a/tcmalloc/realloc_test.cc +++ b/tcmalloc/realloc_test.cc @@ -23,9 +23,9 @@ #include #include +#include "absl/random/random.h" #include "benchmark/benchmark.h" #include "gtest/gtest.h" -#include "absl/random/random.h" namespace tcmalloc { namespace { @@ -48,7 +48,7 @@ void ExpectValid(unsigned char* buffer, int n) { // Return the next interesting size/delta to check. Returns -1 if no more. int NextSize(int size) { if (size < 100) { - return size+1; + return size + 1; } else if (size < 100000) { // Find next power of two int power = 1; @@ -57,13 +57,13 @@ int NextSize(int size) { } // Yield (power-1, power, power+1) - if (size < power-1) { - return power-1; - } else if (size == power-1) { + if (size < power - 1) { + return power - 1; + } else if (size == power - 1) { return power; } else { assert(size == power); - return power+1; + return power + 1; } } else { return -1; diff --git a/tcmalloc/size_classes_with_runtime_size_classes_test.cc b/tcmalloc/size_classes_with_runtime_size_classes_test.cc index 0f5edb0b4..d1767bb5a 100644 --- a/tcmalloc/size_classes_with_runtime_size_classes_test.cc +++ b/tcmalloc/size_classes_with_runtime_size_classes_test.cc @@ -13,11 +13,12 @@ // limitations under the License. #include + #include -#include "gtest/gtest.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" +#include "gtest/gtest.h" #include "tcmalloc/common.h" #include "tcmalloc/size_class_info.h" #include "tcmalloc/span.h" diff --git a/tcmalloc/span_test.cc b/tcmalloc/span_test.cc index 2c1a4b42c..7ba64a2ff 100644 --- a/tcmalloc/span_test.cc +++ b/tcmalloc/span_test.cc @@ -19,10 +19,10 @@ #include #include -#include "gtest/gtest.h" #include "absl/base/internal/spinlock.h" #include "absl/container/flat_hash_set.h" #include "absl/random/random.h" +#include "gtest/gtest.h" #include "tcmalloc/common.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/static_vars.h" diff --git a/tcmalloc/stack_trace_table_test.cc b/tcmalloc/stack_trace_table_test.cc index f8fa4ba58..ad1684829 100644 --- a/tcmalloc/stack_trace_table_test.cc +++ b/tcmalloc/stack_trace_table_test.cc @@ -18,14 +18,14 @@ #include -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/base/attributes.h" #include "absl/base/internal/spinlock.h" #include "absl/base/macros.h" #include "absl/debugging/stacktrace.h" #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/static_vars.h" diff --git a/tcmalloc/static_vars.cc b/tcmalloc/static_vars.cc index bbbd39d62..224a0b0f1 100644 --- a/tcmalloc/static_vars.cc +++ b/tcmalloc/static_vars.cc @@ -69,11 +69,10 @@ size_t Static::metadata_bytes() { sizeof(pageheap_lock) + sizeof(arena_) + sizeof(sizemap_) + sizeof(transfer_cache_) + sizeof(cpu_cache_) + sizeof(span_allocator_) + sizeof(stacktrace_allocator_) + sizeof(threadcache_allocator_) + - sizeof(sampled_objects_) + sizeof(bucket_allocator_) + - sizeof(inited_) + sizeof(cpu_cache_active_) + sizeof(page_allocator_) + - sizeof(pagemap_) + sizeof(sampled_objects_size_) + - sizeof(peak_heap_tracker_) + sizeof(guarded_page_lock) + - sizeof(guardedpage_allocator_); + sizeof(sampled_objects_) + sizeof(bucket_allocator_) + sizeof(inited_) + + sizeof(cpu_cache_active_) + sizeof(page_allocator_) + sizeof(pagemap_) + + sizeof(sampled_objects_size_) + sizeof(peak_heap_tracker_) + + sizeof(guarded_page_lock) + sizeof(guardedpage_allocator_); const size_t allocated = arena().bytes_allocated() + AddressRegionFactory::InternalBytesAllocated(); diff --git a/tcmalloc/stats.h b/tcmalloc/stats.h index 54aabf8d0..d8d68fd87 100644 --- a/tcmalloc/stats.h +++ b/tcmalloc/stats.h @@ -67,9 +67,9 @@ inline SmallSpanStats operator+(SmallSpanStats lhs, SmallSpanStats rhs) { // Stats for free large spans (i.e., spans with more than kMaxPages pages). struct LargeSpanStats { - size_t spans = 0; // Number of such spans - Length normal_pages; // Combined page length of normal large spans - Length returned_pages; // Combined page length of unmapped spans + size_t spans = 0; // Number of such spans + Length normal_pages; // Combined page length of normal large spans + Length returned_pages; // Combined page length of unmapped spans LargeSpanStats &operator+=(LargeSpanStats rhs) { spans += rhs.spans; diff --git a/tcmalloc/stats_test.cc b/tcmalloc/stats_test.cc index dc3947fd8..1628e4d0d 100644 --- a/tcmalloc/stats_test.cc +++ b/tcmalloc/stats_test.cc @@ -17,10 +17,10 @@ #include #include -#include "gtest/gtest.h" #include "absl/base/internal/cycleclock.h" #include "absl/time/clock.h" #include "absl/time/time.h" +#include "gtest/gtest.h" #include "tcmalloc/huge_pages.h" namespace tcmalloc { diff --git a/tcmalloc/system-alloc.cc b/tcmalloc/system-alloc.cc index 870246a7a..5eef76e52 100644 --- a/tcmalloc/system-alloc.cc +++ b/tcmalloc/system-alloc.cc @@ -40,7 +40,7 @@ // On systems (like freebsd) that don't define MAP_ANONYMOUS, use the old // form of the name instead. #ifndef MAP_ANONYMOUS -# define MAP_ANONYMOUS MAP_ANON +#define MAP_ANONYMOUS MAP_ANON #endif // Solaris has a bug where it doesn't declare madvise() for C++. @@ -69,7 +69,7 @@ static_assert(kAddressBits <= 8 * sizeof(void*), // Structure for discovering alignment union MemoryAligner { - void* p; + void* p; double d; size_t s; } ABSL_CACHELINE_ALIGNED; diff --git a/tcmalloc/system-alloc_test.cc b/tcmalloc/system-alloc_test.cc index 1334d9a68..9ca21b35e 100644 --- a/tcmalloc/system-alloc_test.cc +++ b/tcmalloc/system-alloc_test.cc @@ -23,8 +23,8 @@ #include #include -#include "gtest/gtest.h" #include "absl/strings/str_format.h" +#include "gtest/gtest.h" #include "tcmalloc/common.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/malloc_extension.h" diff --git a/tcmalloc/tcmalloc.cc b/tcmalloc/tcmalloc.cc index 03e88f7d9..47fe6f472 100644 --- a/tcmalloc/tcmalloc.cc +++ b/tcmalloc/tcmalloc.cc @@ -13,8 +13,8 @@ // limitations under the License. // // tcmalloc is a fast malloc implementation. See -// https://github.com/google/tcmalloc/tree/master/docs/design.md for a high-level description of -// how this malloc works. +// https://github.com/google/tcmalloc/tree/master/docs/design.md for a +// high-level description of how this malloc works. // // SYNCHRONIZATION // 1. The thread-/cpu-specific lists are accessed without acquiring any locks. @@ -142,20 +142,20 @@ using tcmalloc::ThreadCache; // Extract interesting stats struct TCMallocStats { - uint64_t thread_bytes; // Bytes in thread caches - uint64_t central_bytes; // Bytes in central cache - uint64_t transfer_bytes; // Bytes in central transfer cache - uint64_t metadata_bytes; // Bytes alloced for metadata - uint64_t per_cpu_bytes; // Bytes in per-CPU cache - uint64_t pagemap_root_bytes_res; // Resident bytes of pagemap root node + uint64_t thread_bytes; // Bytes in thread caches + uint64_t central_bytes; // Bytes in central cache + uint64_t transfer_bytes; // Bytes in central transfer cache + uint64_t metadata_bytes; // Bytes alloced for metadata + uint64_t per_cpu_bytes; // Bytes in per-CPU cache + uint64_t pagemap_root_bytes_res; // Resident bytes of pagemap root node uint64_t percpu_metadata_bytes_res; // Resident bytes of the per-CPU metadata - AllocatorStats tc_stats; // ThreadCache objects - AllocatorStats span_stats; // Span objects - AllocatorStats stack_stats; // StackTrace objects - AllocatorStats bucket_stats; // StackTraceTable::Bucket objects - size_t pagemap_bytes; // included in metadata bytes - size_t percpu_metadata_bytes; // included in metadata bytes - tcmalloc::BackingStats pageheap; // Stats from page heap + AllocatorStats tc_stats; // ThreadCache objects + AllocatorStats span_stats; // Span objects + AllocatorStats stack_stats; // StackTrace objects + AllocatorStats bucket_stats; // StackTraceTable::Bucket objects + size_t pagemap_bytes; // included in metadata bytes + size_t percpu_metadata_bytes; // included in metadata bytes + tcmalloc::BackingStats pageheap; // Stats from page heap }; // Get stats into "r". Also, if class_count != NULL, class_count[k] @@ -198,7 +198,7 @@ static void ExtractStats(TCMallocStats* r, uint64_t* class_count, // Add stats from per-thread heaps r->thread_bytes = 0; - { // scope + { // scope absl::base_internal::SpinLockHolder h(&pageheap_lock); ThreadCache::GetThreadStats(&r->thread_bytes, class_count); r->tc_stats = ThreadCache::HeapStats(); @@ -260,12 +260,9 @@ static uint64_t StatSub(uint64_t a, uint64_t b) { // Return approximate number of bytes in use by app. static uint64_t InUseByApp(const TCMallocStats& stats) { return StatSub(stats.pageheap.system_bytes, - stats.thread_bytes + - stats.central_bytes + - stats.transfer_bytes + - stats.per_cpu_bytes + - stats.pageheap.free_bytes + - stats.pageheap.unmapped_bytes); + stats.thread_bytes + stats.central_bytes + + stats.transfer_bytes + stats.per_cpu_bytes + + stats.pageheap.free_bytes + stats.pageheap.unmapped_bytes); } static uint64_t VirtualMemoryUsed(const TCMallocStats& stats) { @@ -298,7 +295,8 @@ static void DumpStats(TCMalloc_Printer* out, int level) { static const double MiB = 1048576.0; out->printf( - "See https://github.com/google/tcmalloc/tree/master/docs/stats.md for an explanation of " + "See https://github.com/google/tcmalloc/tree/master/docs/stats.md for an " + "explanation of " "this page\n"); const uint64_t virtual_memory_used = VirtualMemoryUsed(stats); @@ -306,8 +304,7 @@ static void DumpStats(TCMalloc_Printer* out, int level) { const uint64_t bytes_in_use_by_app = InUseByApp(stats); #ifdef TCMALLOC_SMALL_BUT_SLOW - out->printf( - "NOTE: SMALL MEMORY MODEL IS IN USE, PERFORMANCE MAY SUFFER.\n"); + out->printf("NOTE: SMALL MEMORY MODEL IS IN USE, PERFORMANCE MAY SUFFER.\n"); #endif // clang-format off // Avoid clang-format complaining about the way that this text is laid out. @@ -1769,12 +1766,10 @@ bool CorrectAlignment(void* ptr, std::align_val_t alignment) { // Helpers for use by exported routines below or inside debugallocation.cc: -inline void do_malloc_stats() { - PrintStats(1); -} +inline void do_malloc_stats() { PrintStats(1); } inline int do_mallopt(int cmd, int value) { - return 1; // Indicates error + return 1; // Indicates error } #ifdef HAVE_STRUCT_MALLINFO @@ -1788,13 +1783,12 @@ inline struct mallinfo do_mallinfo() { // Unfortunately, the struct contains "int" field, so some of the // size values will be truncated. - info.arena = static_cast(stats.pageheap.system_bytes); - info.fsmblks = static_cast(stats.thread_bytes - + stats.central_bytes - + stats.transfer_bytes); - info.fordblks = static_cast(stats.pageheap.free_bytes + - stats.pageheap.unmapped_bytes); - info.uordblks = static_cast(InUseByApp(stats)); + info.arena = static_cast(stats.pageheap.system_bytes); + info.fsmblks = static_cast(stats.thread_bytes + stats.central_bytes + + stats.transfer_bytes); + info.fordblks = static_cast(stats.pageheap.free_bytes + + stats.pageheap.unmapped_bytes); + info.uordblks = static_cast(InUseByApp(stats)); return info; } @@ -1877,7 +1871,7 @@ fast_alloc(Policy policy, size_t size, CapacityPtr capacity = nullptr) { #ifndef TCMALLOC_DEPRECATED_PERTHREAD // The CPU cache should be ready. ret = Static::cpu_cache().Allocate(cl); -#else // !defined(TCMALLOC_DEPRECATED_PERTHREAD) +#else // !defined(TCMALLOC_DEPRECATED_PERTHREAD) // The ThreadCache should be ready. ASSERT(cache != nullptr); ret = cache->Allocate(cl); @@ -1946,8 +1940,8 @@ extern "C" ABSL_CACHELINE_ALIGNED void* TCMallocInternalNewAligned( #ifdef TCMALLOC_ALIAS extern "C" void* TCMallocInternalNewAligned_nothrow( size_t size, std::align_val_t alignment, const std::nothrow_t& nt) noexcept -// Note: we use malloc rather than new, as we are allowed to return nullptr. -// The latter crashes in that case. + // Note: we use malloc rather than new, as we are allowed to return nullptr. + // The latter crashes in that case. TCMALLOC_ALIAS(TCMallocInternalMalloc_aligned); #else extern "C" ABSL_ATTRIBUTE_SECTION( @@ -2279,8 +2273,7 @@ extern "C" void* TCMallocInternalAlignedAlloc(size_t align, extern "C" int TCMallocInternalPosixMemalign(void** result_ptr, size_t align, size_t size) noexcept { - if (((align % sizeof(void*)) != 0) || - ((align & (align - 1)) != 0) || + if (((align % sizeof(void*)) != 0) || ((align & (align - 1)) != 0) || (align == 0)) { return EINVAL; } @@ -2304,8 +2297,8 @@ extern "C" void* TCMallocInternalValloc(size_t size) noexcept { extern "C" void* TCMallocInternalPvalloc(size_t size) noexcept { // Round up size to a multiple of pagesize if (pagesize == 0) pagesize = getpagesize(); - if (size == 0) { // pvalloc(0) should allocate one page, according to - size = pagesize; // http://man.free4web.biz/man3/libmpatrol.3.html + if (size == 0) { // pvalloc(0) should allocate one page, according to + size = pagesize; // http://man.free4web.biz/man3/libmpatrol.3.html } size = (size + pagesize - 1) & ~(pagesize - 1); return fast_alloc(MallocPolicy().Nothrow().AlignAs(pagesize), size); diff --git a/tcmalloc/tcmalloc.h b/tcmalloc/tcmalloc.h index d74e421ce..a591c5226 100644 --- a/tcmalloc/tcmalloc.h +++ b/tcmalloc/tcmalloc.h @@ -32,8 +32,8 @@ // "This function will never throw an exception." It's an optional // optimization tool, but we may need to use it to match glibc prototypes. #include -#ifndef __THROW // I guess we're not on a glibc system -# define __THROW // __THROW is just an optimization, so ok to make it "" +#ifndef __THROW // I guess we're not on a glibc system +#define __THROW // __THROW is just an optimization, so ok to make it "" #endif #ifdef __cplusplus @@ -69,7 +69,7 @@ void TCMallocInternalMallocStats(void) __THROW int TCMallocInternalMallOpt(int cmd, int value) __THROW ABSL_ATTRIBUTE_SECTION(google_malloc); #if !defined(OS_FREEBSD) && !defined(OS_MACOSX) - // struct mallinfo isn't defined on these platforms +// struct mallinfo isn't defined on these platforms struct mallinfo TCMallocInternalMallocInfo(void) __THROW ABSL_ATTRIBUTE_SECTION(google_malloc); #endif diff --git a/tcmalloc/tcmalloc_large_test.cc b/tcmalloc/tcmalloc_large_test.cc index 752f32539..3dc42f9a2 100644 --- a/tcmalloc/tcmalloc_large_test.cc +++ b/tcmalloc/tcmalloc_large_test.cc @@ -23,9 +23,9 @@ #include +#include "absl/container/node_hash_set.h" #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "absl/container/node_hash_set.h" #include "tcmalloc/common.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/malloc_extension.h" @@ -56,15 +56,15 @@ void TryAllocMightFail(size_t size) { unsigned char volatile* vp = p; // prevent optimizations static const size_t kPoints = 1024; - for ( size_t i = 0; i < kPoints; ++i ) { + for (size_t i = 0; i < kPoints; ++i) { vp[i * (size / kPoints)] = static_cast(i); } - for ( size_t i = 0; i < kPoints; ++i ) { + for (size_t i = 0; i < kPoints; ++i) { ASSERT_EQ(vp[i * (size / kPoints)], static_cast(i)); } - vp[size-1] = 'M'; + vp[size - 1] = 'M'; ASSERT_EQ(vp[size - 1], 'M'); } else { ASSERT_EQ(errno, ENOMEM); diff --git a/tcmalloc/testing/aligned_new_test.cc b/tcmalloc/testing/aligned_new_test.cc index c4962ad5e..fd31324d2 100644 --- a/tcmalloc/testing/aligned_new_test.cc +++ b/tcmalloc/testing/aligned_new_test.cc @@ -21,11 +21,11 @@ #include #include +#include "absl/base/attributes.h" +#include "absl/container/flat_hash_map.h" #include "benchmark/benchmark.h" #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "absl/base/attributes.h" -#include "absl/container/flat_hash_map.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/malloc_extension.h" diff --git a/tcmalloc/testing/current_allocated_bytes_test.cc b/tcmalloc/testing/current_allocated_bytes_test.cc index 9a3ce475f..95cfdf818 100644 --- a/tcmalloc/testing/current_allocated_bytes_test.cc +++ b/tcmalloc/testing/current_allocated_bytes_test.cc @@ -48,13 +48,13 @@ int main() { // Do a lot of different allocs in a lot of different size classes, // then free them all, to make sure that the logic is correct. - void* ptrs[1000]; // how many pointers to allocate in one run + void* ptrs[1000]; // how many pointers to allocate in one run for (int size = 1; size < 1000000; size = max(size + 1, size * 2 - 100)) { for (int cycles = 0; cycles < 2; ++cycles) { - for (int repeat = 0; repeat < sizeof(ptrs)/sizeof(*ptrs); ++repeat) { + for (int repeat = 0; repeat < sizeof(ptrs) / sizeof(*ptrs); ++repeat) { ptrs[repeat] = malloc(size); } - for (int repeat = 0; repeat < sizeof(ptrs)/sizeof(*ptrs); ++repeat) { + for (int repeat = 0; repeat < sizeof(ptrs) / sizeof(*ptrs); ++repeat) { free(ptrs[repeat]); } } diff --git a/tcmalloc/testing/default_parameters_test.cc b/tcmalloc/testing/default_parameters_test.cc index 90365fa18..e5a10b89e 100644 --- a/tcmalloc/testing/default_parameters_test.cc +++ b/tcmalloc/testing/default_parameters_test.cc @@ -30,12 +30,9 @@ constexpr int64_t kDefaultProfileSamplingRate = constexpr int64_t kDefaultGuardedSamplingRate = 50 * kDefaultProfileSamplingRate; constexpr int64_t kDefaultGuardedSampleParameter = 50; -constexpr MallocExtension::BytesPerSecond kDefaultBackgroundReleaseRate{ - 0 -}; +constexpr MallocExtension::BytesPerSecond kDefaultBackgroundReleaseRate{0}; bool TestProfileSamplingRate() { - auto extension_value = MallocExtension::GetProfileSamplingRate(); if (extension_value != kDefaultProfileSamplingRate) { absl::FPrintF(stderr, "ProfileSamplingRate: got %d, want %d\n", @@ -47,7 +44,6 @@ bool TestProfileSamplingRate() { } bool TestGuardedSamplingRate() { - auto extension_value = MallocExtension::GetGuardedSamplingRate(); if (extension_value != kDefaultGuardedSamplingRate) { absl::FPrintF(stderr, "GuardedSamplingRate: got %d, want %d\n", @@ -59,7 +55,6 @@ bool TestGuardedSamplingRate() { } bool TestBackgroundReleaseRate() { - auto extension_value = MallocExtension::GetBackgroundReleaseRate(); if (extension_value != kDefaultBackgroundReleaseRate) { absl::FPrintF(stderr, "BackgroundReleaseRate: got %d, want %d\n", diff --git a/tcmalloc/testing/empirical_distributions_test.cc b/tcmalloc/testing/empirical_distributions_test.cc index 7c2935eba..b715b8cca 100644 --- a/tcmalloc/testing/empirical_distributions_test.cc +++ b/tcmalloc/testing/empirical_distributions_test.cc @@ -14,11 +14,11 @@ #include "tcmalloc/testing/empirical_distributions.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/random/random.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" namespace tcmalloc { namespace { diff --git a/tcmalloc/testing/empirical_driver.cc b/tcmalloc/testing/empirical_driver.cc index 01f07f300..373f265a5 100644 --- a/tcmalloc/testing/empirical_driver.cc +++ b/tcmalloc/testing/empirical_driver.cc @@ -455,7 +455,6 @@ class SimThread { }; void SetContents(std::string filename, std::string contents) { - int fd = tcmalloc_internal::signal_safe_open(filename.c_str(), O_WRONLY); CHECK_CONDITION(fd >= 0); CHECK_CONDITION(tcmalloc_internal::signal_safe_write( diff --git a/tcmalloc/testing/empirical_test.cc b/tcmalloc/testing/empirical_test.cc index c4915ebe6..3ab533cdf 100644 --- a/tcmalloc/testing/empirical_test.cc +++ b/tcmalloc/testing/empirical_test.cc @@ -19,10 +19,10 @@ #include #include -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/random/random.h" #include "absl/strings/str_cat.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "tcmalloc/testing/testutil.h" // Koenig lookup diff --git a/tcmalloc/testing/largesmall_frag_test.cc b/tcmalloc/testing/largesmall_frag_test.cc index 788f3b4fe..cebb9a58e 100644 --- a/tcmalloc/testing/largesmall_frag_test.cc +++ b/tcmalloc/testing/largesmall_frag_test.cc @@ -15,8 +15,8 @@ #include #include -#include "gtest/gtest.h" #include "absl/strings/str_format.h" +#include "gtest/gtest.h" #include "tcmalloc/internal/linked_list.h" #include "tcmalloc/internal/memory_stats.h" #include "tcmalloc/malloc_extension.h" @@ -93,7 +93,7 @@ TEST(LargeSmallFrag, Test) { sized_delete(objects[i], kSmall); } } - allowed += 2*kSmall; + allowed += 2 * kSmall; MallocExtension::ReleaseMemoryToSystem( std::numeric_limits::max()); // Simulate scavenging diff --git a/tcmalloc/testing/limit_test.cc b/tcmalloc/testing/limit_test.cc index 9b0705b98..46d09978c 100644 --- a/tcmalloc/testing/limit_test.cc +++ b/tcmalloc/testing/limit_test.cc @@ -22,11 +22,11 @@ #include #include -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/strings/match.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "tcmalloc/common.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/internal/parameter_accessors.h" diff --git a/tcmalloc/testing/markidle_test.cc b/tcmalloc/testing/markidle_test.cc index 9e0df86aa..58639a903 100644 --- a/tcmalloc/testing/markidle_test.cc +++ b/tcmalloc/testing/markidle_test.cc @@ -19,8 +19,8 @@ #include // NOLINT(build/c++11) -#include "gtest/gtest.h" #include "absl/flags/flag.h" +#include "gtest/gtest.h" #include "tcmalloc/malloc_extension.h" namespace tcmalloc { @@ -30,7 +30,7 @@ namespace { static void TestAllocation() { static const int kNum = 1000; void* ptr[kNum]; - for (int size = 8; size <= 65536; size*=2) { + for (int size = 8; size <= 65536; size *= 2) { for (int i = 0; i < kNum; i++) { ptr[i] = malloc(size); } diff --git a/tcmalloc/testing/memalign_test.cc b/tcmalloc/testing/memalign_test.cc index 6eff7ff71..fab97de25 100644 --- a/tcmalloc/testing/memalign_test.cc +++ b/tcmalloc/testing/memalign_test.cc @@ -31,9 +31,9 @@ #include #include +#include "absl/random/random.h" #include "benchmark/benchmark.h" #include "gtest/gtest.h" -#include "absl/random/random.h" #include "tcmalloc/testing/testutil.h" namespace tcmalloc { @@ -42,7 +42,7 @@ namespace { // Return the next interesting size/delta to check. Returns -1 if no more. int NextSize(int size) { if (size < 100) { - return size+1; + return size + 1; } else if (size < 1048576) { // Find next power of two int power = 1; @@ -51,13 +51,13 @@ int NextSize(int size) { } // Yield (power-1, power, power+1) - if (size < power-1) { - return power-1; - } else if (size == power-1) { + if (size < power - 1) { + return power - 1; + } else if (size == power - 1) { return power; } else { assert(size == power); - return power+1; + return power + 1; } } else { return -1; @@ -202,15 +202,15 @@ TEST(MemalignTest, Memalign) { { // Check various corner cases - void* p1 = memalign(1<<20, 1<<19); - void* p2 = memalign(1<<19, 1<<19); - void* p3 = memalign(1<<21, 1<<19); - CheckAlignment(p1, 1<<20); - CheckAlignment(p2, 1<<19); - CheckAlignment(p3, 1<<21); - Fill(p1, 1<<19, 'a'); - Fill(p2, 1<<19, 'b'); - Fill(p3, 1<<19, 'c'); + void* p1 = memalign(1 << 20, 1 << 19); + void* p2 = memalign(1 << 19, 1 << 19); + void* p3 = memalign(1 << 21, 1 << 19); + CheckAlignment(p1, 1 << 20); + CheckAlignment(p2, 1 << 19); + CheckAlignment(p3, 1 << 21); + Fill(p1, 1 << 19, 'a'); + Fill(p2, 1 << 19, 'b'); + Fill(p3, 1 << 19, 'c'); ASSERT_TRUE(Valid(p1, 1 << 19, 'a')); ASSERT_TRUE(Valid(p2, 1 << 19, 'b')); ASSERT_TRUE(Valid(p3, 1 << 19, 'c')); diff --git a/tcmalloc/testing/memory_errors_test.cc b/tcmalloc/testing/memory_errors_test.cc index b17d7cdb6..bb46c1230 100644 --- a/tcmalloc/testing/memory_errors_test.cc +++ b/tcmalloc/testing/memory_errors_test.cc @@ -21,10 +21,10 @@ #include #include -#include "benchmark/benchmark.h" -#include "gtest/gtest.h" #include "absl/base/attributes.h" #include "absl/memory/memory.h" +#include "benchmark/benchmark.h" +#include "gtest/gtest.h" #include "tcmalloc/common.h" #include "tcmalloc/guarded_page_allocator.h" #include "tcmalloc/internal/bits.h" @@ -40,8 +40,8 @@ class GuardedAllocAlignmentTest : public testing::Test { GuardedAllocAlignmentTest() { profile_sampling_rate_ = MallocExtension::GetProfileSamplingRate(); guarded_sample_rate_ = MallocExtension::GetGuardedSamplingRate(); - MallocExtension::SetProfileSamplingRate(1); // Always do heapz samples. - MallocExtension::SetGuardedSamplingRate(0); // Guard every heapz sample. + MallocExtension::SetProfileSamplingRate(1); // Always do heapz samples. + MallocExtension::SetGuardedSamplingRate(0); // Guard every heapz sample. MallocExtension::ActivateGuardedSampling(); // Eat up unsampled bytes remaining to flush the new sample rates. diff --git a/tcmalloc/testing/releasing_test.cc b/tcmalloc/testing/releasing_test.cc index 5e579bee9..071926ac5 100644 --- a/tcmalloc/testing/releasing_test.cc +++ b/tcmalloc/testing/releasing_test.cc @@ -27,10 +27,10 @@ #include #include -#include "benchmark/benchmark.h" #include "absl/random/random.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" +#include "benchmark/benchmark.h" #include "tcmalloc/common.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/internal/memory_stats.h" diff --git a/tcmalloc/testing/sample_size_class_test.cc b/tcmalloc/testing/sample_size_class_test.cc index 941fc3bdb..e8df8abbc 100644 --- a/tcmalloc/testing/sample_size_class_test.cc +++ b/tcmalloc/testing/sample_size_class_test.cc @@ -69,7 +69,7 @@ TEST(SampleSizeClassTest, Main) { // Pick kRequestSize so that it changes significantly when it is // rounded up by tcmalloc. If this changes, you may want to pick a // new kRequestSize. - const size_t kRequestSize = 17; + const size_t kRequestSize = 17; const size_t kActualSize = 32; void* p = malloc(kRequestSize); EXPECT_EQ(kActualSize, MallocExtension::GetAllocatedSize(p)); @@ -82,7 +82,7 @@ TEST(SampleSizeClassTest, Main) { size_t allocated = 0; LinkedList objs; objs.Init(); - while (allocated < 128*1024*1024) { + while (allocated < 128 * 1024 * 1024) { // We must use the return value from malloc, otherwise the compiler may // optimize out the call altogether! void* ptr = malloc(kRequestSize); diff --git a/tcmalloc/testing/sampler_test.cc b/tcmalloc/testing/sampler_test.cc old mode 100755 new mode 100644 index ea9557cfb..7fbfa64fa --- a/tcmalloc/testing/sampler_test.cc +++ b/tcmalloc/testing/sampler_test.cc @@ -27,8 +27,8 @@ #include #include -#include "gtest/gtest.h" #include "absl/strings/str_cat.h" +#include "gtest/gtest.h" #include "tcmalloc/malloc_extension.h" #include "tcmalloc/testing/testutil.h" @@ -73,12 +73,18 @@ TEST(Sampler, TestGetSamplePeriod) { // the limit as n-> infinity. For finite n, apply the error fix below. double AndersonDarlingInf(double z) { if (z < 2) { - return exp(-1.2337141 / z) / sqrt(z) * (2.00012 + (0.247105 - - (0.0649821 - (0.0347962 - (0.011672 - 0.00168691 - * z) * z) * z) * z) * z); + return exp(-1.2337141 / z) / sqrt(z) * + (2.00012 + + (0.247105 - + (0.0649821 - (0.0347962 - (0.011672 - 0.00168691 * z) * z) * z) * + z) * + z); } - return exp( - exp(1.0776 - (2.30695 - (0.43424 - (0.082433 - - (0.008056 - 0.0003146 * z) * z) * z) * z) * z)); + return exp( + -exp(1.0776 - + (2.30695 - + (0.43424 - (0.082433 - (0.008056 - 0.0003146 * z) * z) * z) * z) * + z)); } // Corrects the approximation error in AndersonDarlingInf for small values of n @@ -86,8 +92,11 @@ double AndersonDarlingInf(double z) { // (from Marsaglia) double AndersonDarlingErrFix(int n, double x) { if (x > 0.8) { - return (-130.2137 + (745.2337 - (1705.091 - (1950.646 - - (1116.360 - 255.7844 * x) * x) * x) * x) * x) / n; + return (-130.2137 + + (745.2337 - + (1705.091 - (1950.646 - (1116.360 - 255.7844 * x) * x) * x) * x) * + x) / + n; } double cutoff = 0.01265 + 0.1757 / n; double t; @@ -97,8 +106,9 @@ double AndersonDarlingErrFix(int n, double x) { return t * (0.0037 / (n * n) + 0.00078 / n + 0.00006) / n; } else { t = (x - cutoff) / (0.8 - cutoff); - t = -0.00022633 + (6.54034 - (14.6538 - (14.458 - (8.259 - 1.91864 - * t) * t) * t) * t) * t; + t = -0.00022633 + + (6.54034 - (14.6538 - (14.458 - (8.259 - 1.91864 * t) * t) * t) * t) * + t; return t * (0.04213 + 0.01365 / n) / n; } } @@ -117,7 +127,7 @@ double AndersonDarlingStatistic(const std::vector& random_sample) { ad_sum += (2 * i + 1) * std::log(random_sample[i] * (1 - random_sample[n - 1 - i])); } - double ad_statistic = - n - 1/static_cast(n) * ad_sum; + double ad_statistic = -n - 1 / static_cast(n) * ad_sum; return ad_statistic; } @@ -140,7 +150,7 @@ void TestNextRandom(int n) { SamplerTest::Init(&sampler, 1); uint64_t x = 1; // This assumes that the prng returns 48 bit numbers - uint64_t max_prng_value = static_cast(1)<<48; + uint64_t max_prng_value = static_cast(1) << 48; // Initialize for (int i = 1; i <= 20; i++) { // 20 mimics sampler.Init() x = sampler.NextRandom(x); @@ -156,7 +166,8 @@ void TestNextRandom(int n) { std::vector random_sample(n); // Convert them to uniform randoms (in the range [0,1]) for (int i = 0; i < n; i++) { - random_sample[i] = static_cast(int_random_sample[i])/max_prng_value; + random_sample[i] = + static_cast(int_random_sample[i]) / max_prng_value; } // Now compute the Anderson-Darling statistic double ad_pvalue = AndersonDarlingTest(random_sample); @@ -243,13 +254,12 @@ TEST(Sampler, TestPickNextGuardedSample_MultipleValues) { // Further tests -double StandardDeviationsErrorInSample( - int total_samples, int picked_samples, - int alloc_size, int sampling_interval) { +double StandardDeviationsErrorInSample(int total_samples, int picked_samples, + int alloc_size, int sampling_interval) { double p = 1 - exp(-(static_cast(alloc_size) / sampling_interval)); double expected_samples = total_samples * p; - double sd = pow(p*(1-p)*total_samples, 0.5); - return((picked_samples - expected_samples) / sd); + double sd = pow(p * (1 - p) * total_samples, 0.5); + return ((picked_samples - expected_samples) / sd); } TEST(Sampler, LargeAndSmallAllocs_CombinedTest) { @@ -257,9 +267,9 @@ TEST(Sampler, LargeAndSmallAllocs_CombinedTest) { SamplerTest::Init(&sampler, 1); int counter_big = 0; int counter_small = 0; - int size_big = 129*8*1024+1; - int size_small = 1024*8; - int num_iters = 128*4*8; + int size_big = 129 * 8 * 1024 + 1; + int size_small = 1024 * 8; + int num_iters = 128 * 4 * 8; // Allocate in mixed chunks for (int i = 0; i < num_iters; i++) { if (sampler.RecordAllocation(size_big)) { @@ -272,12 +282,10 @@ TEST(Sampler, LargeAndSmallAllocs_CombinedTest) { } } // Now test that there are the right number of each - double large_allocs_sds = - StandardDeviationsErrorInSample(num_iters, counter_big, - size_big, kSamplingInterval); - double small_allocs_sds = - StandardDeviationsErrorInSample(num_iters*129, counter_small, - size_small, kSamplingInterval); + double large_allocs_sds = StandardDeviationsErrorInSample( + num_iters, counter_big, size_big, kSamplingInterval); + double small_allocs_sds = StandardDeviationsErrorInSample( + num_iters * 129, counter_small, size_small, kSamplingInterval); ASSERT_LE(fabs(large_allocs_sds), kSigmas) << large_allocs_sds; ASSERT_LE(fabs(small_allocs_sds), kSigmas) << small_allocs_sds; } @@ -351,7 +359,7 @@ TEST(Sampler, bytes_until_sample_Overflow_Underflow) { const uint64_t prng_mod_power = 48; // Number of bits in prng // First, check the largest_prng value - uint64_t largest_prng_value = (static_cast(1)<<48) - 1; + uint64_t largest_prng_value = (static_cast(1) << 48) - 1; double q = (largest_prng_value >> (prng_mod_power - 26)) + 1.0; uint64_t smallest_sample_step = 1 + static_cast((std::log2(q) - 26) * sample_scaling); @@ -370,7 +378,6 @@ TEST(Sampler, bytes_until_sample_Overflow_Underflow) { } } - // Test that NextRand is in the right range. Unfortunately, this is a // stochastic test which could miss problems. TEST(Sampler, NextRand_range) { @@ -380,8 +387,8 @@ TEST(Sampler, NextRand_range) { // The next number should be (one << 48) - 1 uint64_t max_value = (one << 48) - 1; uint64_t x = (one << 55); - int n = 22; // 27; - for (int i = 1; i <= (1< #include -#include "benchmark/benchmark.h" -#include "gtest/gtest.h" #include "absl/base/internal/sysinfo.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" +#include "benchmark/benchmark.h" +#include "gtest/gtest.h" #include "tcmalloc/common.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/internal/util.h" diff --git a/tcmalloc/testing/sampling_test.cc b/tcmalloc/testing/sampling_test.cc index 7c53c5700..075788dc4 100644 --- a/tcmalloc/testing/sampling_test.cc +++ b/tcmalloc/testing/sampling_test.cc @@ -27,13 +27,13 @@ #include #include -#include "benchmark/benchmark.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/base/attributes.h" #include "absl/debugging/symbolize.h" #include "absl/strings/str_cat.h" #include "absl/types/optional.h" +#include "benchmark/benchmark.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/malloc_extension.h" #include "tcmalloc/testing/testutil.h" @@ -67,7 +67,7 @@ size_t CountMatchingBytes(const char *target, Profile profile) { } ABSL_ATTRIBUTE_NOINLINE static void *AllocateAllocate(bool align) { - void* p; + void *p; if (align) { // A 10000 byte allocation aligned to 2K will use a 10K size class // and get 'charged' identically to malloc(10000). diff --git a/tcmalloc/testing/startup_size_test.cc b/tcmalloc/testing/startup_size_test.cc index 120b86a76..efbf1ad39 100644 --- a/tcmalloc/testing/startup_size_test.cc +++ b/tcmalloc/testing/startup_size_test.cc @@ -29,8 +29,8 @@ #include #include -#include "gtest/gtest.h" #include "absl/base/internal/sysinfo.h" +#include "gtest/gtest.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/malloc_extension.h" @@ -49,7 +49,6 @@ static size_t Property(const PropertyMap& map, const char* name) { } TEST(StartupSizeTest, Basic) { - static const size_t MiB = 1024 * 1024; PropertyMap map = MallocExtension::GetProperties(); ASSERT_NE(map.count("tcmalloc.metadata_bytes"), 0) diff --git a/tcmalloc/testing/tcmalloc_benchmark.cc b/tcmalloc/testing/tcmalloc_benchmark.cc index 0e5682cdc..4e2bbb1e6 100644 --- a/tcmalloc/testing/tcmalloc_benchmark.cc +++ b/tcmalloc/testing/tcmalloc_benchmark.cc @@ -156,7 +156,7 @@ static void BM_random_new_delete(benchmark::State& state) { random_request_size[i] = absl::Uniform(rand, 0, kMaxRequestSize) + 1; } - void *v[kMaxOnHeap]; + void* v[kMaxOnHeap]; memset(v, 0, sizeof(v)); int r = 0; diff --git a/tcmalloc/testing/tcmalloc_test.cc b/tcmalloc/testing/tcmalloc_test.cc index 916292e43..838a109b7 100644 --- a/tcmalloc/testing/tcmalloc_test.cc +++ b/tcmalloc/testing/tcmalloc_test.cc @@ -58,9 +58,6 @@ #include #include -#include "benchmark/benchmark.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/base/casts.h" #include "absl/base/internal/sysinfo.h" #include "absl/base/macros.h" @@ -70,6 +67,9 @@ #include "absl/strings/str_format.h" #include "absl/synchronization/mutex.h" #include "absl/utility/utility.h" +#include "benchmark/benchmark.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "tcmalloc/internal/declarations.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/internal/parameter_accessors.h" @@ -80,9 +80,9 @@ // Windows doesn't define pvalloc and a few other obsolete unix // functions; nor does it define posix_memalign (which is not obsolete). #if defined(_WIN32) -# define cfree free -# define valloc malloc -# define pvalloc malloc +#define cfree free +#define valloc malloc +#define pvalloc malloc static inline int PosixMemalign(void** ptr, size_t align, size_t size) { tcmalloc::Crash(tcmalloc::kCrash, __FILE__, __LINE__, "posix_memalign not supported on windows"); @@ -112,7 +112,7 @@ const int kLogMaxMemalign = 18; static const int kSizeBits = 8 * sizeof(size_t); static const size_t kMaxSize = ~static_cast(0); -static const size_t kMaxSignedSize = ((size_t(1) << (kSizeBits-1)) - 1); +static const size_t kMaxSignedSize = ((size_t(1) << (kSizeBits - 1)) - 1); namespace tcmalloc { extern bool want_hpaa(); @@ -570,15 +570,15 @@ TEST(TCMallocTest, ReleaseMemoryToSystem) { // Use up the extra MB/4 bytes from 'a' and also release 'b'. MallocExtension::ReleaseMemoryToSystem(MB / 2); - EXPECT_EQ(starting_bytes + 2*MB, GetUnmappedBytes()); + EXPECT_EQ(starting_bytes + 2 * MB, GetUnmappedBytes()); // Should do nothing since the previous call released too much. MallocExtension::ReleaseMemoryToSystem(MB / 2); - EXPECT_EQ(starting_bytes + 2*MB, GetUnmappedBytes()); + EXPECT_EQ(starting_bytes + 2 * MB, GetUnmappedBytes()); // Nothing else to release. MallocExtension::ReleaseMemoryToSystem(std::numeric_limits::max()); - EXPECT_EQ(starting_bytes + 2*MB, GetUnmappedBytes()); + EXPECT_EQ(starting_bytes + 2 * MB, GetUnmappedBytes()); a = ::operator new(MB); ::operator delete(a); @@ -586,7 +586,7 @@ TEST(TCMallocTest, ReleaseMemoryToSystem) { // Releasing less than a page should still trigger a release. MallocExtension::ReleaseMemoryToSystem(1); - EXPECT_EQ(starting_bytes + 2*MB, GetUnmappedBytes()); + EXPECT_EQ(starting_bytes + 2 * MB, GetUnmappedBytes()); } TEST(TCMallocTest, NothrowSizedDelete) { @@ -843,7 +843,7 @@ TEST(TCMallocTest, NothrowAlignedNewArray) { void CheckSizedDelete() { absl::BitGen rand; - std::vector > allocated; + std::vector> allocated; for (int i = 1; i < 100; ++i) { size_t alloc_size = absl::LogUniform(rand, 0, (1 << 20) - 1); void* p1 = ::operator new(alloc_size); @@ -857,9 +857,7 @@ void CheckSizedDelete() { } } -TEST(TCMallocTest, SizedDelete) { - CheckSizedDelete(); -} +TEST(TCMallocTest, SizedDelete) { CheckSizedDelete(); } TEST(TCMallocTest, SizedDeleteSampled) { ScopedProfileSamplingRate s(1); // Try to sample more. @@ -872,7 +870,7 @@ TEST(TCMallocTest, SampleAllocatedSize) { // Do 64 megabytes of allocation; this should (nearly) guarantee we // get a sample. - for (int i = 0; i < 1024*1024; ++i) { + for (int i = 0; i < 1024 * 1024; ++i) { void* ptr = malloc(64); ASSERT_EQ(64, MallocExtension::GetAllocatedSize(ptr)); free(ptr); diff --git a/tcmalloc/testing/testutil.cc b/tcmalloc/testing/testutil.cc index ae3538354..96655d9a8 100644 --- a/tcmalloc/testing/testutil.cc +++ b/tcmalloc/testing/testutil.cc @@ -28,7 +28,6 @@ // limiting the address-space size we get sufficient coverage without blowing // out job limits. void SetTestResourceLimit() { - // The actual resource we need to set varies depending on which flavour of // unix. On Linux we need RLIMIT_AS because that covers the use of mmap. // Otherwise hopefully RLIMIT_RSS is good enough. (Unfortunately 64-bit @@ -50,7 +49,7 @@ void SetTestResourceLimit() { if (getrlimit(USE_RESOURCE, &rlim) == 0) { if (rlim.rlim_cur == RLIM_INFINITY || rlim.rlim_cur > kMaxMem) { rlim.rlim_cur = kMaxMem; - setrlimit(USE_RESOURCE, &rlim); // ignore result + setrlimit(USE_RESOURCE, &rlim); // ignore result } } } diff --git a/tcmalloc/testing/testutil.h b/tcmalloc/testing/testutil.h index 7b966c750..30b54c2c1 100644 --- a/tcmalloc/testing/testutil.h +++ b/tcmalloc/testing/testutil.h @@ -37,7 +37,7 @@ inline void sized_delete(void* ptr, size_t size) { // Get the TCMalloc stats in textproto format. std::string GetStatsInPbTxt(); extern "C" ABSL_ATTRIBUTE_WEAK int MallocExtension_Internal_GetStatsInPbtxt( - char *buffer, int buffer_length); + char* buffer, int buffer_length); class ScopedProfileSamplingRate { public: diff --git a/tcmalloc/testing/thread_ctor_test.cc b/tcmalloc/testing/thread_ctor_test.cc index 9914cad50..5a8344e91 100644 --- a/tcmalloc/testing/thread_ctor_test.cc +++ b/tcmalloc/testing/thread_ctor_test.cc @@ -19,6 +19,4 @@ extern pthread_t *Func(); -int main() { - Func(); -} +int main() { Func(); } diff --git a/tcmalloc/testing/thread_ctor_test_lib.cc b/tcmalloc/testing/thread_ctor_test_lib.cc index da454ab8f..69834f3dd 100644 --- a/tcmalloc/testing/thread_ctor_test_lib.cc +++ b/tcmalloc/testing/thread_ctor_test_lib.cc @@ -18,19 +18,19 @@ #include #include #include + #include namespace { struct Foo { int x; - Foo() : x(42) { } + Foo() : x(42) {} }; -static void *fn(void *) -{ +static void *fn(void *) { while (true) { - std::vector v; + std::vector v; v.reserve(1000); for (int i = 0; i < 1000; ++i) { v.push_back(new Foo); diff --git a/tcmalloc/testing/thread_manager.h b/tcmalloc/testing/thread_manager.h index 396bb486f..e13a827b4 100644 --- a/tcmalloc/testing/thread_manager.h +++ b/tcmalloc/testing/thread_manager.h @@ -19,8 +19,8 @@ #include #include -#include "gtest/gtest.h" #include "absl/synchronization/blocking_counter.h" +#include "gtest/gtest.h" namespace tcmalloc { diff --git a/tcmalloc/testing/threadcachesize_test.cc b/tcmalloc/testing/threadcachesize_test.cc index f01f790b5..8d3408740 100644 --- a/tcmalloc/testing/threadcachesize_test.cc +++ b/tcmalloc/testing/threadcachesize_test.cc @@ -21,11 +21,11 @@ #include // NOLINT(build/c++11) #include -#include "gtest/gtest.h" #include "absl/base/attributes.h" #include "absl/base/const_init.h" #include "absl/synchronization/barrier.h" #include "absl/synchronization/mutex.h" +#include "gtest/gtest.h" #include "tcmalloc/malloc_extension.h" #include "tcmalloc/testing/testutil.h" diff --git a/tcmalloc/thread_cache.cc b/tcmalloc/thread_cache.cc index 2ace4af54..2241c06fd 100644 --- a/tcmalloc/thread_cache.cc +++ b/tcmalloc/thread_cache.cc @@ -169,7 +169,7 @@ void ThreadCache::Scavenge() { FreeList* list = &list_[cl]; const int lowmark = list->lowwatermark(); if (lowmark > 0) { - const int drop = (lowmark > 1) ? lowmark/2 : 1; + const int drop = (lowmark > 1) ? lowmark / 2 : 1; ReleaseToCentralCache(list, cl, drop); // Shrink the max length if it isn't used. Only shrink down to @@ -219,8 +219,7 @@ void ThreadCache::IncreaseCacheLimitLocked() { // threads before giving up. The i < 10 condition also prevents an // infinite loop in case none of the existing thread heaps are // suitable places to steal from. - for (int i = 0; i < 10; - ++i, next_memory_steal_ = next_memory_steal_->next_) { + for (int i = 0; i < 10; ++i, next_memory_steal_ = next_memory_steal_->next_) { // Reached the end of the linked list. Start at the beginning. if (next_memory_steal_ == nullptr) { ASSERT(thread_heaps_ != nullptr); diff --git a/tcmalloc/thread_cache.h b/tcmalloc/thread_cache.h index a6d955f0b..63d6bff6e 100644 --- a/tcmalloc/thread_cache.h +++ b/tcmalloc/thread_cache.h @@ -70,7 +70,7 @@ class ThreadCache { static ThreadCache* GetCache(); static ThreadCache* GetCacheIfPresent(); static ThreadCache* CreateCacheIfNecessary(); - static void BecomeIdle(); + static void BecomeIdle(); // returns stats on total thread caches created/used static inline AllocatorStats HeapStats() @@ -131,24 +131,16 @@ class ThreadCache { } // Return the maximum length of the list. - size_t max_length() const { - return max_length_; - } + size_t max_length() const { return max_length_; } // Set the maximum length of the list. If 'new_max' > length(), the // client is responsible for removing objects from the list. - void set_max_length(size_t new_max) { - max_length_ = new_max; - } + void set_max_length(size_t new_max) { max_length_ = new_max; } // Return the number of times that length() has gone over max_length(). - size_t length_overages() const { - return length_overages_; - } + size_t length_overages() const { return length_overages_; } - void set_length_overages(size_t new_count) { - length_overages_ = new_count; - } + void set_length_overages(size_t new_count) { length_overages_ = new_count; } // Low-water mark management int lowwatermark() const { return lowater_; } @@ -247,8 +239,8 @@ class ThreadCache { FreeList list_[kNumClasses]; // Array indexed by size-class - size_t size_; // Combined size of data - size_t max_size_; // size_ > max_size_ --> Scavenge() + size_t size_; // Combined size of data + size_t max_size_; // size_ > max_size_ --> Scavenge() #ifndef ABSL_HAVE_TLS // We sample allocations, biased by the size of the allocation. diff --git a/tcmalloc/thread_cache_test.cc b/tcmalloc/thread_cache_test.cc index 474f4f999..b5833f2de 100644 --- a/tcmalloc/thread_cache_test.cc +++ b/tcmalloc/thread_cache_test.cc @@ -23,9 +23,9 @@ #include #include // NOLINT(build/c++11) +#include "absl/strings/str_cat.h" #include "benchmark/benchmark.h" #include "gtest/gtest.h" -#include "absl/strings/str_cat.h" #include "tcmalloc/internal/logging.h" #include "tcmalloc/internal/memory_stats.h" #include "tcmalloc/internal/parameter_accessors.h" diff --git a/tcmalloc/tracking.h b/tcmalloc/tracking.h index 465920e39..6c6136466 100644 --- a/tcmalloc/tracking.h +++ b/tcmalloc/tracking.h @@ -64,8 +64,8 @@ enum TrackingStat { kMallocMiss = 1, // malloc that didn't kFreeHit = 2, // ibid. for free kFreeMiss = 3, - kFreeScavenges = 4, // # of frees that leads to scavenge - kFreeTruncations = 5, // # of frees that leads to list truncation + kFreeScavenges = 4, // # of frees that leads to scavenge + kFreeTruncations = 5, // # of frees that leads to list truncation kTCInsertHit = 6, // # of times the returned object list hits transfer cache. kTCInsertMiss = 7, // # of times the object list misses the transfer cache. kTCRemoveHit = 8, // # of times object list fetching hits transfer cache. @@ -80,7 +80,7 @@ void Report(TrackingStat stat, size_t cl, ssize_t count); // Dump all tracking data to . We could support various other // mechanisms for data delivery without too much trouble... -void Print(TCMalloc_Printer *out); +void Print(TCMalloc_Printer* out); // Call before a thread will die (ideally after its last malloc call!) // so we don't lose its statistics. @@ -97,7 +97,7 @@ void GetProperties(std::map* result); // no tracking, these are all no-ops inline void Report(TrackingStat stat, size_t cl, ssize_t count) {} inline void RegisterNewThreadIfNecessary() {} -inline void Print(TCMalloc_Printer *out) {} +inline void Print(TCMalloc_Printer* out) {} inline void ReportThreadDeath() {} inline void Init() {} inline void GetProperties( diff --git a/tcmalloc/transfer_cache_test.cc b/tcmalloc/transfer_cache_test.cc index fce2f2ec8..61b8fe3d7 100644 --- a/tcmalloc/transfer_cache_test.cc +++ b/tcmalloc/transfer_cache_test.cc @@ -19,13 +19,13 @@ #include #include -#include "gmock/gmock.h" -#include "gtest/gtest.h" #include "absl/base/internal/spinlock.h" #include "absl/random/distributions.h" #include "absl/random/random.h" #include "absl/time/clock.h" #include "absl/types/span.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "tcmalloc/central_freelist.h" #include "tcmalloc/common.h" #include "tcmalloc/mock_central_freelist.h"