[compiler-rt] c919109 - [scudo] Move the trace point in releaseToOSMaybe (#159204)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 17 08:49:23 PDT 2025
Author: Christopher Ferris
Date: 2025-09-17T08:49:18-07:00
New Revision: c919109aa96cae7b72eb9cc3f1559706e36a3c0b
URL: https://github.com/llvm/llvm-project/commit/c919109aa96cae7b72eb9cc3f1559706e36a3c0b
DIFF: https://github.com/llvm/llvm-project/commit/c919109aa96cae7b72eb9cc3f1559706e36a3c0b.diff
LOG: [scudo] Move the trace point in releaseToOSMaybe (#159204)
Move the trace point until right before the mark free blocks call for
the primary. This avoids adding extra calculations on a fast path.
Added:
Modified:
compiler-rt/lib/scudo/standalone/primary32.h
compiler-rt/lib/scudo/standalone/primary64.h
Removed:
################################################################################
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<Config>::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<Config>::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<Config>::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<Config>::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);
More information about the llvm-commits
mailing list