Skip to content

Commit 1ac4442

Browse files
ckennellycopybara-github
authored andcommitted
Revert: Add a malloc extension to get estimated allocated size for cold allocations
PiperOrigin-RevId: 818709718 Change-Id: Ibb36f3a38df7d828a98ed62f4c8c9e3514728794
1 parent 31f6792 commit 1ac4442

File tree

5 files changed

+3
-45
lines changed

5 files changed

+3
-45
lines changed

tcmalloc/internal_malloc_extension.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ MallocExtension_Internal_ReleaseMemoryToSystem(size_t bytes);
128128
ABSL_ATTRIBUTE_WEAK void MallocExtension_Internal_SetMemoryLimit(
129129
size_t limit, tcmalloc::MallocExtension::LimitKind limit_kind);
130130

131-
ABSL_ATTRIBUTE_WEAK size_t MallocExtension_Internal_GetEstimatedAllocatedSize(
132-
size_t bytes, tcmalloc::hot_cold_t hot_cold);
133131
ABSL_ATTRIBUTE_WEAK size_t
134132
MallocExtension_Internal_GetAllocatedSize(const void* ptr);
135133
ABSL_ATTRIBUTE_WEAK void MallocExtension_Internal_MarkThreadBusy();

tcmalloc/malloc_extension.cc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -662,17 +662,6 @@ std::optional<size_t> MallocExtension::GetNumericProperty(
662662
return std::nullopt;
663663
}
664664

665-
size_t MallocExtension::GetEstimatedAllocatedSize(size_t size,
666-
hot_cold_t hot_cold) {
667-
#if ABSL_INTERNAL_HAVE_WEAK_MALLOCEXTENSION_STUBS
668-
if (MallocExtension_Internal_GetEstimatedAllocatedSize != nullptr) {
669-
return MallocExtension_Internal_GetEstimatedAllocatedSize(size, hot_cold);
670-
}
671-
#endif
672-
// Fall-through to assuming that the hot/cold hint doesn't affect the
673-
return nallocx(size, 0);
674-
}
675-
676665
size_t MallocExtension::GetEstimatedAllocatedSize(size_t size) {
677666
return nallocx(size, 0);
678667
}

tcmalloc/malloc_extension.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,6 @@ class MallocExtension final {
578578
// reserve more bytes, but will never reserve fewer.
579579
[[nodiscard]] static size_t GetEstimatedAllocatedSize(size_t size);
580580

581-
// Returns the estimated number of bytes that will be allocated for a request
582-
// of "size" bytes. This is an estimate: an allocation of "size" bytes may
583-
// reserve more bytes, but will never reserve fewer.
584-
static size_t GetEstimatedAllocatedSize(size_t size,
585-
tcmalloc::hot_cold_t hot_cold);
586-
587581
// Returns the actual number N of bytes reserved by tcmalloc for the pointer
588582
// p. This number may be equal to or greater than the number of bytes
589583
// requested when p was allocated.

tcmalloc/tcmalloc.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,12 @@ extern "C" size_t MallocExtension_Internal_ReleaseMemoryToSystem(
352352
// stack spills. ABSL_ATTRIBUTE_ALWAYS_INLINE does not work on
353353
// size_class_with_alignment, compiler barks that it can't inline the function
354354
// somewhere.
355-
static ABSL_ATTRIBUTE_NOINLINE size_t nallocx_slow(size_t size, int flags,
356-
hot_cold_t hot_cold) {
355+
static ABSL_ATTRIBUTE_NOINLINE size_t nallocx_slow(size_t size, int flags) {
357356
tc_globals.InitIfNecessary();
358357
size_t align = static_cast<size_t>(1ull << (flags & 0x3f));
359358
size_t size_class;
360359
if (ABSL_PREDICT_TRUE(tc_globals.sizemap().GetSizeClass(
361-
CppPolicy().AlignAs(align).AccessAs(hot_cold), size, &size_class))) {
360+
CppPolicy().AlignAs(align), size, &size_class))) {
362361
TC_ASSERT_NE(size_class, 0);
363362
return tc_globals.sizemap().class_to_size(size_class);
364363
} else {
@@ -373,7 +372,7 @@ static ABSL_ATTRIBUTE_NOINLINE size_t nallocx_slow(size_t size, int flags,
373372
// http://www.unix.com/man-page/freebsd/3/nallocx/
374373
extern "C" size_t nallocx(size_t size, int flags) noexcept {
375374
if (ABSL_PREDICT_FALSE(!tc_globals.IsInited() || flags != 0)) {
376-
return nallocx_slow(size, flags, hot_cold_t{255});
375+
return nallocx_slow(size, flags);
377376
}
378377
size_t size_class;
379378
if (ABSL_PREDICT_TRUE(
@@ -385,11 +384,6 @@ extern "C" size_t nallocx(size_t size, int flags) noexcept {
385384
}
386385
}
387386

388-
extern "C" size_t MallocExtension_Internal_GetEstimatedAllocatedSize(
389-
size_t bytes, tcmalloc::hot_cold_t hot_cold) {
390-
return nallocx_slow(bytes, 0, hot_cold);
391-
}
392-
393387
extern "C" MallocExtension::Ownership MallocExtension_Internal_GetOwnership(
394388
const void* ptr) {
395389
return GetOwnership(ptr);

tcmalloc/testing/tcmalloc_test.cc

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -799,23 +799,6 @@ TEST(TCMallocTest, nallocx_alignment) {
799799
}
800800
}
801801

802-
TEST(TCMallocTest, GetEstimatedAllocatedSizeHotCold) {
803-
// Guarded allocations may have a smaller allocated size than nallocx
804-
// predicts. So we disable guarded allocations.
805-
ScopedGuardedSamplingInterval gs(-1);
806-
for (size_t size = 0; size <= kMaxTestAllocSize; size += 17) {
807-
for (hot_cold_t hot_cold : {hot_cold_t{0}, hot_cold_t{255}}) {
808-
size_t rounded =
809-
MallocExtension::GetEstimatedAllocatedSize(size, hot_cold);
810-
ASSERT_GE(rounded, size);
811-
auto [ptr, allocated_size] =
812-
__size_returning_new_hot_cold(size, hot_cold);
813-
ASSERT_EQ(rounded, allocated_size);
814-
sized_delete(ptr, size);
815-
}
816-
}
817-
}
818-
819802
TEST(TCMallocTest, sdallocx) {
820803
for (size_t size = 0; size <= 4096; size += 7) {
821804
void* ptr = malloc(size);

0 commit comments

Comments
 (0)