Skip to content

Commit 31f6792

Browse files
ckennellycopybara-github
authored andcommitted
Turn down SelSan implementation.
PiperOrigin-RevId: 817685013 Change-Id: I42561354407f69846a19dfb5b08eba8fbcb86ab5
1 parent 9edc369 commit 31f6792

24 files changed

+8
-1030
lines changed

tcmalloc/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ tcmalloc_deps = [
7676
"@com_google_absl//absl/base:dynamic_annotations",
7777
"@com_google_absl//absl/debugging:stacktrace",
7878
"@com_google_absl//absl/debugging:symbolize",
79-
"//tcmalloc/selsan",
8079
"@com_google_absl//absl/memory",
8180
"@com_google_absl//absl/status",
8281
"@com_google_absl//absl/status:statusor",
@@ -330,7 +329,6 @@ create_tcmalloc_libraries(
330329
"//tcmalloc/internal:system_allocator",
331330
"//tcmalloc/internal:timeseries_tracker",
332331
"//tcmalloc/internal:util",
333-
"//tcmalloc/selsan",
334332
"@com_google_absl//absl/algorithm:container",
335333
"@com_google_absl//absl/base",
336334
"@com_google_absl//absl/base:core_headers",

tcmalloc/central_freelist.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "tcmalloc/page_allocator_interface.h"
3333
#include "tcmalloc/pagemap.h"
3434
#include "tcmalloc/pages.h"
35-
#include "tcmalloc/selsan/selsan.h"
3635
#include "tcmalloc/span.h"
3736
#include "tcmalloc/static_vars.h"
3837

@@ -45,9 +44,6 @@ static MemoryTag MemoryTagFromSizeClass(size_t size_class) {
4544
if (IsExpandedSizeClass(size_class)) {
4645
return MemoryTag::kCold;
4746
}
48-
if (selsan::IsEnabled()) {
49-
return MemoryTag::kSelSan;
50-
}
5147
if (!tc_globals.numa_topology().numa_aware()) {
5248
return MemoryTag::kNormal;
5349
}

tcmalloc/central_freelist.h

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include "tcmalloc/internal/logging.h"
3838
#include "tcmalloc/internal/optimization.h"
3939
#include "tcmalloc/pages.h"
40-
#include "tcmalloc/selsan/selsan.h"
4140
#include "tcmalloc/span.h"
4241
#include "tcmalloc/span_stats.h"
4342

@@ -322,9 +321,6 @@ inline void CentralFreeList<Forwarder>::Init(
322321
if (object_size_ == 0) {
323322
return;
324323
}
325-
if (selsan::IsEnabled()) {
326-
object_size_ = selsan::RoundUpObjectSize(object_size_);
327-
}
328324
pages_per_span_ = forwarder_.class_to_pages(size_class);
329325
objects_per_span_ =
330326
pages_per_span_.in_bytes() / (object_size_ ? object_size_ : 1);
@@ -462,12 +458,6 @@ inline void CentralFreeList<Forwarder>::InsertRange(absl::Span<void*> batch) {
462458
TC_CHECK(!batch.empty());
463459
TC_CHECK_LE(batch.size(), kMaxObjectsToMove);
464460

465-
if (selsan::IsEnabled()) {
466-
for (auto& ptr : batch) {
467-
ptr = selsan::ResetTag(ptr, object_size_);
468-
}
469-
}
470-
471461
Span* spans[kMaxObjectsToMove];
472462
// First, map objects to spans and prefetch spans outside of our mutex
473463
// (to reduce critical section size and cache misses).
@@ -522,26 +512,7 @@ void CentralFreeList<Forwarder>::DeallocateSpans(absl::Span<Span*> spans) {
522512
completed_spans_[LifetimeBucketNum(lifetime)].LossyAdd(1);
523513
}
524514
}
525-
if (ABSL_PREDICT_TRUE(!selsan::IsEnabled())) {
526-
return forwarder_.DeallocateSpans(objects_per_span_, spans);
527-
}
528-
Span* selsan_spans[kMaxObjectsToMove];
529-
size_t selsan_count = 0;
530-
size_t normal_count = 0;
531-
for (Span* span : spans) {
532-
if (IsSelSanMemory(span->start_address())) {
533-
selsan_spans[selsan_count++] = span;
534-
} else {
535-
spans[normal_count++] = span;
536-
}
537-
}
538-
539-
if (normal_count) {
540-
forwarder_.DeallocateSpans(objects_per_span_, {spans.data(), normal_count});
541-
}
542-
if (selsan_count) {
543-
forwarder_.DeallocateSpans(objects_per_span_, {selsan_spans, selsan_count});
544-
}
515+
return forwarder_.DeallocateSpans(objects_per_span_, spans);
545516
}
546517

547518
template <class Forwarder>

tcmalloc/global_stats.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
#include "tcmalloc/pagemap.h"
4747
#include "tcmalloc/pages.h"
4848
#include "tcmalloc/parameters.h"
49-
#include "tcmalloc/selsan/selsan.h"
5049
#include "tcmalloc/span.h"
5150
#include "tcmalloc/span_stats.h"
5251
#include "tcmalloc/stack_trace_table.h"
@@ -500,11 +499,7 @@ void DumpStats(Printer& out, int level) {
500499
}
501500
tc_globals.page_allocator().Print(out, MemoryTag::kSampled, pageflags);
502501
tc_globals.page_allocator().Print(out, MemoryTag::kCold, pageflags);
503-
if (selsan::IsEnabled()) {
504-
tc_globals.page_allocator().Print(out, MemoryTag::kSelSan, pageflags);
505-
}
506502
tc_globals.guardedpage_allocator().Print(out);
507-
selsan::PrintTextStats(out);
508503

509504
out.printf("------------------------------------------------\n");
510505
out.printf("Configured limits and related statistics\n");
@@ -729,10 +724,6 @@ void DumpStatsInPbtxt(Printer& out, int level) {
729724
tc_globals.page_allocator().PrintInPbtxt(region, MemoryTag::kSampled,
730725
pageflags);
731726
tc_globals.page_allocator().PrintInPbtxt(region, MemoryTag::kCold, pageflags);
732-
if (selsan::IsEnabled()) {
733-
tc_globals.page_allocator().PrintInPbtxt(region, MemoryTag::kSelSan,
734-
pageflags);
735-
}
736727
// We do not collect tracking information in pbtxt.
737728

738729
size_t soft_limit_bytes =
@@ -772,7 +763,6 @@ void DumpStatsInPbtxt(Printer& out, int level) {
772763
auto gwp_asan = region.CreateSubRegion("gwp_asan");
773764
tc_globals.guardedpage_allocator().PrintInPbtxt(gwp_asan);
774765
}
775-
selsan::PrintPbtxtStats(region);
776766

777767
region.PrintI64("memory_release_failures",
778768
tc_globals.system_allocator().release_errors());

tcmalloc/internal/config.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,6 @@ inline constexpr int kAddressBits = 48;
133133
inline constexpr int kAddressBits = 8 * sizeof(void*);
134134
#endif
135135

136-
#ifdef TCMALLOC_INTERNAL_SELSAN
137-
// TODO(b/404529382): add tcmalloc test suite and remove maybe_unused annotation
138-
[[maybe_unused]] inline constexpr bool kSelSanPresent = true;
139-
#else
140-
inline constexpr bool kSelSanPresent = false;
141-
#endif
142-
143136
#if defined(ABSL_HAVE_ADDRESS_SANITIZER) || \
144137
defined(ABSL_HAVE_MEMORY_SANITIZER) || defined(ABSL_HAVE_THREAD_SANITIZER)
145138
inline constexpr bool kSanitizerPresent = true;
@@ -148,9 +141,8 @@ inline constexpr bool kSanitizerPresent = false;
148141
#endif
149142

150143
// Sanitizers constrain the memory layout which causes problems with the
151-
// enlarged tags required to represent NUMA partitions and for SelSan.
144+
// enlarged tags required to represent NUMA partitions.
152145
#if defined(ABSL_HAVE_MEMORY_SANITIZER) || defined(ABSL_HAVE_THREAD_SANITIZER)
153-
static_assert(!kSelSanPresent, "MSan/TSan are incompatible with SelSan.");
154146
inline constexpr bool kSanitizerAddressSpace = true;
155147
#else
156148
inline constexpr bool kSanitizerAddressSpace = false;

tcmalloc/internal/memory_tag.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ absl::string_view MemoryTagToLabel(MemoryTag tag) {
2929
return "NORMAL_P1";
3030
case MemoryTag::kSampled:
3131
return "SAMPLED";
32-
case MemoryTag::kSelSan:
33-
return "SELSAN";
3432
case MemoryTag::kCold:
3533
return "COLD";
3634
case MemoryTag::kMetadata:

tcmalloc/internal/memory_tag.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ enum class MemoryTag : uint8_t {
3838
kCold = 0x2,
3939
// Metadata
4040
kMetadata = 0x3,
41-
// SelSan sampled spans, kept separately because we need to quickly
42-
// distinguish them from the rest during delete and they also consume
43-
// shadow memory. 0xfe is an arbitrary value that shouldn't be used.
44-
kSelSan = kSelSanPresent ? 0x1 : 0xfe,
4541
};
4642

4743
inline constexpr uintptr_t kTagShift = std::min(kAddressBits - 4, 42);
@@ -67,20 +63,6 @@ inline bool IsNormalMemory(const void* ptr) {
6763
return res;
6864
}
6965

70-
inline bool IsSelSanMemory(const void* ptr) {
71-
// This is a faster way to check for SelSan memory provided we already know
72-
// it's not a normal memory, and assuming it's not kMetadata (both assumptions
73-
// are checked by the assert below). A straightforward comparison with kSelSan
74-
// leads to extraction/check of 2 bits (these use 2 8-byte immediates);
75-
// this check can be done with a single BT instruction.
76-
// kSelSanPresent part allows to optimize away branches in non SelSan build.
77-
bool res =
78-
kSelSanPresent && (static_cast<uintptr_t>(GetMemoryTag(ptr)) &
79-
static_cast<uintptr_t>(MemoryTag::kSelSan)) != 0;
80-
TC_ASSERT_EQ(res, GetMemoryTag(ptr) == MemoryTag::kSelSan);
81-
return res;
82-
}
83-
8466
absl::string_view MemoryTagToLabel(MemoryTag tag);
8567

8668
} // namespace tcmalloc::tcmalloc_internal

tcmalloc/internal/parameter_accessors.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ ABSL_ATTRIBUTE_WEAK size_t TCMalloc_Internal_GetStats(char* buffer,
5353
size_t buffer_length);
5454
ABSL_ATTRIBUTE_WEAK void TCMalloc_Internal_SetGuardedSamplingInterval(
5555
int64_t v);
56-
ABSL_ATTRIBUTE_WEAK int TCMalloc_Internal_GetSelSanPercent();
57-
ABSL_ATTRIBUTE_WEAK void TCMalloc_Internal_SetSelSanPercent(int v);
5856
ABSL_ATTRIBUTE_WEAK void TCMalloc_Internal_SetHeapSizeHardLimit(uint64_t v);
5957
ABSL_ATTRIBUTE_WEAK void TCMalloc_Internal_SetHPAASubrelease(bool v);
6058
ABSL_ATTRIBUTE_WEAK void TCMalloc_Internal_SetReleasePartialAllocPagesEnabled(

tcmalloc/internal/system_allocator.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ class SystemAllocator {
185185
absl::once_flag rnd_flag_;
186186

187187
uintptr_t next_sampled_addr_ ABSL_GUARDED_BY(spinlock_) = 0;
188-
uintptr_t next_selsan_addr_ ABSL_GUARDED_BY(spinlock_) = 0;
189188
std::array<uintptr_t, kNumaPartitions> next_normal_addr_
190189
ABSL_GUARDED_BY(spinlock_) = {0};
191190
uintptr_t next_cold_addr_ ABSL_GUARDED_BY(spinlock_) = 0;
@@ -206,7 +205,6 @@ class SystemAllocator {
206205
std::array<AddressRegion*, kNumaPartitions> normal_region_
207206
ABSL_GUARDED_BY(spinlock_){{nullptr}};
208207
AddressRegion* sampled_region_ ABSL_GUARDED_BY(spinlock_){nullptr};
209-
AddressRegion* selsan_region_ ABSL_GUARDED_BY(spinlock_){nullptr};
210208
AddressRegion* cold_region_ ABSL_GUARDED_BY(spinlock_){nullptr};
211209
AddressRegion* metadata_region_ ABSL_GUARDED_BY(spinlock_){nullptr};
212210

@@ -330,7 +328,6 @@ template <typename Topology>
330328
void SystemAllocator<Topology>::DiscardMappedRegions() {
331329
std::fill(normal_region_.begin(), normal_region_.end(), nullptr);
332330
sampled_region_ = nullptr;
333-
selsan_region_ = nullptr;
334331
cold_region_ = nullptr;
335332
metadata_region_ = nullptr;
336333
}
@@ -458,8 +455,6 @@ std::pair<void*, size_t> SystemAllocator<Topology>::AllocateFromRegion(
458455
return &normal_region_[1];
459456
case MemoryTag::kSampled:
460457
return &sampled_region_;
461-
case MemoryTag::kSelSan:
462-
return &selsan_region_;
463458
case MemoryTag::kCold:
464459
return &cold_region_;
465460
case MemoryTag::kMetadata:
@@ -512,8 +507,6 @@ void* SystemAllocator<Topology>::MmapAlignedLocked(size_t size,
512507
switch (tag) {
513508
case MemoryTag::kSampled:
514509
return &next_sampled_addr_;
515-
case MemoryTag::kSelSan:
516-
return &next_selsan_addr_;
517510
case MemoryTag::kNormalP0:
518511
numa_partition = 0;
519512
return &next_normal_addr_[0];
@@ -736,11 +729,6 @@ AddressRegionFactory::UsageHint SystemAllocator<Topology>::TagToHint(
736729
return UsageHint::kNormalNumaAwareS1;
737730
}
738731
return UsageHint::kNormal;
739-
case MemoryTag::kSelSan:
740-
if (topology_.numa_aware()) {
741-
return UsageHint::kNormalNumaAwareS0;
742-
}
743-
return UsageHint::kNormal;
744732
case MemoryTag::kSampled:
745733
return UsageHint::kInfrequentAllocation;
746734
case MemoryTag::kCold:

tcmalloc/malloc_extension.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
defined(ABSL_HAVE_THREAD_SANITIZER) || \
4444
defined(ABSL_HAVE_HWADDRESS_SANITIZER) || \
4545
defined(ABSL_HAVE_DATAFLOW_SANITIZER) || \
46-
defined(ABSL_HAVE_LEAK_SANITIZER)) && \
47-
!defined(TCMALLOC_INTERNAL_SELSAN)
46+
defined(ABSL_HAVE_LEAK_SANITIZER))
4847
#define TCMALLOC_UNDER_SANITIZERS 1
4948
static constexpr size_t kTerabyte = (size_t)(1ULL << 40);
5049

0 commit comments

Comments
 (0)