Skip to content

Commit

Permalink
Put Most of TCMalloc in google_malloc
Browse files Browse the repository at this point in the history
We do this by providing google_malloc as the section name for .text for the tcmalloc namespace.  Some of the templated functions still end up in .text section.  We specially handle such functions in the newly added test.

PiperOrigin-RevId: 353713296
Change-Id: Id2537937d35e78a44e803303290394f685812679
  • Loading branch information
nilayvaish authored and copybara-github committed Jan 25, 2021
1 parent 0f461e6 commit b05cd9c
Show file tree
Hide file tree
Showing 106 changed files with 283 additions and 3 deletions.
6 changes: 6 additions & 0 deletions tcmalloc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ tcmalloc_deps = [
"@com_google_absl//absl/memory",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/numeric:bits",
"//tcmalloc/internal:config",
"//tcmalloc/internal:declarations",
"//tcmalloc/internal:linked_list",
"//tcmalloc/internal:logging",
Expand Down Expand Up @@ -319,6 +320,7 @@ cc_library(
copts = ["-g0"] + TCMALLOC_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
"//tcmalloc/internal:config",
"@com_google_absl//absl/base:core_headers",
],
alwayslink = 1,
Expand All @@ -333,6 +335,7 @@ cc_library(
copts = ["-g0"] + TCMALLOC_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
"//tcmalloc/internal:config",
"@com_google_absl//absl/base:core_headers",
],
alwayslink = 1,
Expand All @@ -349,6 +352,7 @@ cc_library(
"//tcmalloc/testing:__pkg__",
],
deps = [
"//tcmalloc/internal:config",
"@com_google_absl//absl/base:core_headers",
],
alwayslink = 1,
Expand All @@ -362,6 +366,7 @@ cc_library(
copts = ["-g0"] + TCMALLOC_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
"//tcmalloc/internal:config",
"@com_google_absl//absl/base:core_headers",
],
alwayslink = 1,
Expand Down Expand Up @@ -1115,6 +1120,7 @@ cc_library(
"//visibility:public",
],
deps = [
"//tcmalloc/internal:config",
"//tcmalloc/internal:parameter_accessors",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:dynamic_annotations",
Expand Down
2 changes: 2 additions & 0 deletions tcmalloc/arena.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "tcmalloc/internal/logging.h"
#include "tcmalloc/system-alloc.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -51,3 +52,4 @@ void* Arena::Alloc(size_t bytes) {

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END
2 changes: 2 additions & 0 deletions tcmalloc/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "absl/base/thread_annotations.h"
#include "tcmalloc/common.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -59,5 +60,6 @@ class Arena {

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END

#endif // TCMALLOC_ARENA_H_
2 changes: 2 additions & 0 deletions tcmalloc/background.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "tcmalloc/malloc_extension.h"
#include "tcmalloc/parameters.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {
namespace {
Expand Down Expand Up @@ -84,6 +85,7 @@ void ReleasePerCpuMemoryToOS() {
} // namespace
} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END

// Release memory to the system at a constant rate.
void MallocExtension_Internal_ProcessBackgroundActions() {
Expand Down
2 changes: 2 additions & 0 deletions tcmalloc/central_freelist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "tcmalloc/pages.h"
#include "tcmalloc/static_vars.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -195,3 +196,4 @@ SpanStats CentralFreeList::GetSpanStats() const {

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END
2 changes: 2 additions & 0 deletions tcmalloc/central_freelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "tcmalloc/span.h"
#include "tcmalloc/span_stats.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -129,5 +130,6 @@ class CentralFreeList {

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END

#endif // TCMALLOC_CENTRAL_FREELIST_H_
2 changes: 2 additions & 0 deletions tcmalloc/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "tcmalloc/runtime_size_classes.h"
#include "tcmalloc/sampler.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -180,3 +181,4 @@ void SizeMap::Init() {

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END
2 changes: 2 additions & 0 deletions tcmalloc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "tcmalloc/internal/logging.h"
#include "tcmalloc/size_class_info.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -450,5 +451,6 @@ extern absl::base_internal::SpinLock pageheap_lock;

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END

#endif // TCMALLOC_COMMON_H_
2 changes: 2 additions & 0 deletions tcmalloc/cpu_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "tcmalloc/static_vars.h"
#include "tcmalloc/transfer_cache.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -653,6 +654,7 @@ static PerCPUInitializer module_enter_exit;

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END

extern "C" bool MallocExtension_Internal_GetPerCpuCachesActive() {
return tcmalloc::tcmalloc_internal::Static::CPUCacheActive();
Expand Down
2 changes: 2 additions & 0 deletions tcmalloc/cpu_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "tcmalloc/thread_cache.h"
#include "tcmalloc/tracking.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -268,4 +269,5 @@ inline bool UsePerCpuCache() {

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END
#endif // TCMALLOC_CPU_CACHE_H_
2 changes: 2 additions & 0 deletions tcmalloc/experiment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "tcmalloc/internal/environment.h"
#include "tcmalloc/internal/logging.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {
namespace {
Expand Down Expand Up @@ -158,3 +159,4 @@ absl::optional<Experiment> FindExperimentByName(absl::string_view name) {
}

} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END
2 changes: 2 additions & 0 deletions tcmalloc/experiment.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
// BORG_DISABLE_EXPERIMENTS=all *or*
// BORG_DISABLE_EXPERIMENTS=BAD_EXPERIMENT_LABEL

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -65,5 +66,6 @@ bool IsExperimentActive(Experiment exp);
absl::optional<Experiment> FindExperimentByName(absl::string_view name);

} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END

#endif // TCMALLOC_EXPERIMENT_H_
2 changes: 2 additions & 0 deletions tcmalloc/experimental_56_size_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "tcmalloc/common.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {

namespace tcmalloc_internal {
Expand Down Expand Up @@ -707,3 +708,4 @@ const SizeClassInfo SizeMap::kExperimentalSizeClasses[SizeMap::kExperimentalSize

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END
2 changes: 2 additions & 0 deletions tcmalloc/guarded_page_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "tcmalloc/static_vars.h"
#include "tcmalloc/system-alloc.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -550,3 +551,4 @@ extern "C" void MallocExtension_Internal_ActivateGuardedSampling() {

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END
2 changes: 2 additions & 0 deletions tcmalloc/guarded_page_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "tcmalloc/common.h"
#include "tcmalloc/internal/logging.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -305,5 +306,6 @@ struct ConstexprCheck {

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END

#endif // TCMALLOC_GUARDED_PAGE_ALLOCATOR_H_
2 changes: 2 additions & 0 deletions tcmalloc/guarded_page_allocator_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "tcmalloc/guarded_page_allocator.h"
#include "tcmalloc/internal/logging.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {
namespace {
Expand Down Expand Up @@ -56,3 +57,4 @@ BENCHMARK(BM_AllocDealloc)->Arg(1)->ThreadRange(1, kMaxGpaPages);
} // namespace
} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END
2 changes: 2 additions & 0 deletions tcmalloc/huge_address_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "absl/base/internal/cycleclock.h"
#include "tcmalloc/internal/logging.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -370,3 +371,4 @@ HugeAddressMap::Node::Node(HugeRange r, int prio)

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END
2 changes: 2 additions & 0 deletions tcmalloc/huge_address_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "tcmalloc/huge_pages.h"
#include "tcmalloc/internal/logging.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -150,5 +151,6 @@ inline const HugeAddressMap::Node *HugeAddressMap::root() const {

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END

#endif // TCMALLOC_HUGE_ADDRESS_MAP_H_
2 changes: 2 additions & 0 deletions tcmalloc/huge_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "tcmalloc/huge_address_map.h"
#include "tcmalloc/internal/logging.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -171,3 +172,4 @@ void HugeAllocator::AddSpanStats(SmallSpanStats *small, LargeSpanStats *large,

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END
2 changes: 2 additions & 0 deletions tcmalloc/huge_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "tcmalloc/huge_pages.h"
#include "tcmalloc/stats.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -102,5 +103,6 @@ class HugeAllocator {

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END

#endif // TCMALLOC_HUGE_ALLOCATOR_H_
2 changes: 2 additions & 0 deletions tcmalloc/huge_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "tcmalloc/internal/logging.h"
#include "tcmalloc/stats.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -495,3 +496,4 @@ void HugeCache::PrintInPbtxt(PbtxtRegion *hpaa) {

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END
3 changes: 3 additions & 0 deletions tcmalloc/huge_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
#include "tcmalloc/experiment_config.h"
#include "tcmalloc/huge_allocator.h"
#include "tcmalloc/huge_pages.h"
#include "tcmalloc/internal/config.h"
#include "tcmalloc/internal/logging.h"
#include "tcmalloc/internal/timeseries_tracker.h"
#include "tcmalloc/stats.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -222,5 +224,6 @@ class HugeCache {

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END

#endif // TCMALLOC_HUGE_CACHE_H_
2 changes: 2 additions & 0 deletions tcmalloc/huge_page_aware_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "tcmalloc/static_vars.h"
#include "tcmalloc/stats.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand Down Expand Up @@ -665,3 +666,4 @@ void HugePageAwareAllocator::UnbackWithoutLock(void *start, size_t length) {

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END
4 changes: 4 additions & 0 deletions tcmalloc/huge_page_aware_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
#include "tcmalloc/huge_page_filler.h"
#include "tcmalloc/huge_pages.h"
#include "tcmalloc/huge_region.h"
#include "tcmalloc/internal/config.h"
#include "tcmalloc/internal/logging.h"
#include "tcmalloc/page_allocator_interface.h"
#include "tcmalloc/page_heap_allocator.h"
#include "tcmalloc/span.h"
#include "tcmalloc/stats.h"
#include "tcmalloc/system-alloc.h"

GOOGLE_MALLOC_SECTION_BEGIN
namespace tcmalloc {
namespace tcmalloc_internal {

Expand All @@ -43,6 +45,7 @@ bool decide_subrelease();
class HugePageAwareAllocator final : public PageAllocatorInterface {
public:
explicit HugePageAwareAllocator(MemoryTag tag);
~HugePageAwareAllocator() override = default;

// Allocate a run of "n" pages. Returns zero if out of memory.
// Caller should not pass "n == 0" -- instead, n should have
Expand Down Expand Up @@ -168,5 +171,6 @@ class HugePageAwareAllocator final : public PageAllocatorInterface {

} // namespace tcmalloc_internal
} // namespace tcmalloc
GOOGLE_MALLOC_SECTION_END

#endif // TCMALLOC_HUGE_PAGE_AWARE_ALLOCATOR_H_
Loading

0 comments on commit b05cd9c

Please sign in to comment.