diff --git a/compiler-rt/lib/scudo/standalone/primary32.h b/compiler-rt/lib/scudo/standalone/primary32.h index 49aa74adfc10a..645c3968ce3e1 100644 --- a/compiler-rt/lib/scudo/standalone/primary32.h +++ b/compiler-rt/lib/scudo/standalone/primary32.h @@ -1058,8 +1058,6 @@ uptr SizeClassAllocator32::releaseToOSMaybe(SizeClassInfo *Sci, uptr ClassId, ReleaseToOS ReleaseType) REQUIRES(Sci->Mutex) { - SCUDO_SCOPED_TRACE(GetPrimaryReleaseToOSMaybeTraceName(ReleaseType)); - const uptr BlockSize = getSizeByClassId(ClassId); DCHECK_GE(Sci->FreeListInfo.PoppedBlocks, Sci->FreeListInfo.PushedBlocks); @@ -1096,6 +1094,12 @@ uptr SizeClassAllocator32::releaseToOSMaybe(SizeClassInfo *Sci, // 2. Mark the free blocks and we can tell which pages are in-use by // querying `PageReleaseContext`. // ==================================================================== // + + // Only add trace point after the quick returns have occurred to avoid + // incurring performance penalties. Most of the time in this function + // will be the mark free blocks call and the actual release to OS call. + SCUDO_SCOPED_TRACE(GetPrimaryReleaseToOSMaybeTraceName(ReleaseType)); + PageReleaseContext Context = markFreeBlocks(Sci, ClassId, BlockSize, Base, NumberOfRegions, ReleaseType); if (!Context.hasBlockMarked()) diff --git a/compiler-rt/lib/scudo/standalone/primary64.h b/compiler-rt/lib/scudo/standalone/primary64.h index 7727049426b47..d08103008ef7c 100644 --- a/compiler-rt/lib/scudo/standalone/primary64.h +++ b/compiler-rt/lib/scudo/standalone/primary64.h @@ -1379,8 +1379,6 @@ uptr SizeClassAllocator64::releaseToOSMaybe(RegionInfo *Region, uptr ClassId, ReleaseToOS ReleaseType) REQUIRES(Region->MMLock) EXCLUDES(Region->FLLock) { - SCUDO_SCOPED_TRACE(GetPrimaryReleaseToOSMaybeTraceName(ReleaseType)); - const uptr BlockSize = getSizeByClassId(ClassId); uptr BytesInFreeList; const uptr AllocatedUserEnd = @@ -1444,6 +1442,12 @@ uptr SizeClassAllocator64::releaseToOSMaybe(RegionInfo *Region, // Then we can tell which pages are in-use by querying // `PageReleaseContext`. // ==================================================================== // + + // Only add trace point after the quick returns have occurred to avoid + // incurring performance penalties. Most of the time in this function + // will be the mark free blocks call and the actual release to OS call. + SCUDO_SCOPED_TRACE(GetPrimaryReleaseToOSMaybeTraceName(ReleaseType)); + PageReleaseContext Context = markFreeBlocks(Region, BlockSize, AllocatedUserEnd, getCompactPtrBaseByClassId(ClassId), GroupsToRelease);