diff --git a/tcmalloc/internal/system_allocator.h b/tcmalloc/internal/system_allocator.h index a25e1f1b4..90f9bf328 100644 --- a/tcmalloc/internal/system_allocator.h +++ b/tcmalloc/internal/system_allocator.h @@ -377,6 +377,15 @@ SystemAllocator::MmapRegion::Alloc( // This is only advisory, so ignore the error. ErrnoRestorer errno_restorer; (void)madvise(result_ptr, actual_size, MADV_NOHUGEPAGE); + } else { + // Opt-in to transparent hugepages for large allocations when system is + // configured for transparent_hugepage=madvise. This can improve memory + // performance by reducing TLB pressure. + if (actual_size >= kHugePageSize) { + // This is only advisory, so ignore the error. + ErrnoRestorer errno_restorer; + (void)madvise(result_ptr, actual_size, MADV_HUGEPAGE); + } } free_size_ -= actual_size; return {result_ptr, actual_size};