diff --git a/tcmalloc/page_allocator.cc b/tcmalloc/page_allocator.cc index 500b78c3a..b1a1b451b 100644 --- a/tcmalloc/page_allocator.cc +++ b/tcmalloc/page_allocator.cc @@ -76,7 +76,21 @@ PageAllocator::PageAllocator() { TC_CHECK_LE(part, std::size(choices_)); } -void PageAllocator::ShrinkToUsageLimitSlow(Length n) { +void PageAllocator::ShrinkToUsageLimit(Length n, bool may_have_grown) { +#ifdef TCMALLOC_INTERNAL_LEGACY_LOCKING + const bool check_stats = true; +#else +#ifndef NDEBUG + const bool check_stats = true; +#else + const bool check_stats = may_have_grown; +#endif // NDEBUG +#endif // TCMALLOC_INTERNAL_LEGACY_LOCKING + + if (!check_stats) { + return; + } + BackingStats s = stats(); const size_t backed = s.system_bytes - s.unmapped_bytes + tc_globals.metadata_bytes(); diff --git a/tcmalloc/page_allocator.h b/tcmalloc/page_allocator.h index 3e06fb1a6..41aa46982 100644 --- a/tcmalloc/page_allocator.h +++ b/tcmalloc/page_allocator.h @@ -141,19 +141,7 @@ class PageAllocator { // If we have a usage limit set, ensure we're not violating it from our latest // allocation. void ShrinkToUsageLimit(Length n, bool may_have_grown) - ABSL_EXCLUSIVE_LOCKS_REQUIRED(pageheap_lock) { -#if defined(TCMALLOC_INTERNAL_LEGACY_LOCKING) || !defined(NDEBUG) - const bool check_stats = true; -#else - const bool check_stats = may_have_grown; -#endif - - if (!check_stats) { - return; - } - - ShrinkToUsageLimitSlow(n); - } + ABSL_EXCLUSIVE_LOCKS_REQUIRED(pageheap_lock); void TreatHugepageTrackers(EnableCollapse enable_collapse) ABSL_LOCKS_EXCLUDED(pageheap_lock); @@ -207,8 +195,6 @@ class PageAllocator { MemoryTag tag); static void InvokeReleaseHookSlow(Length num_pages, Length released, PageReleaseReason reason); - ABSL_ATTRIBUTE_NOINLINE void ShrinkToUsageLimitSlow(Length n) - ABSL_EXCLUSIVE_LOCKS_REQUIRED(pageheap_lock); bool ShrinkHardBy(Length page, LimitKind limit_kind) ABSL_EXCLUSIVE_LOCKS_REQUIRED(pageheap_lock);