Skip to content

Commit c919109

Browse files
authored
[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.
1 parent de4fdcc commit c919109

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

compiler-rt/lib/scudo/standalone/primary32.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,6 @@ uptr SizeClassAllocator32<Config>::releaseToOSMaybe(SizeClassInfo *Sci,
10581058
uptr ClassId,
10591059
ReleaseToOS ReleaseType)
10601060
REQUIRES(Sci->Mutex) {
1061-
SCUDO_SCOPED_TRACE(GetPrimaryReleaseToOSMaybeTraceName(ReleaseType));
1062-
10631061
const uptr BlockSize = getSizeByClassId(ClassId);
10641062

10651063
DCHECK_GE(Sci->FreeListInfo.PoppedBlocks, Sci->FreeListInfo.PushedBlocks);
@@ -1096,6 +1094,12 @@ uptr SizeClassAllocator32<Config>::releaseToOSMaybe(SizeClassInfo *Sci,
10961094
// 2. Mark the free blocks and we can tell which pages are in-use by
10971095
// querying `PageReleaseContext`.
10981096
// ==================================================================== //
1097+
1098+
// Only add trace point after the quick returns have occurred to avoid
1099+
// incurring performance penalties. Most of the time in this function
1100+
// will be the mark free blocks call and the actual release to OS call.
1101+
SCUDO_SCOPED_TRACE(GetPrimaryReleaseToOSMaybeTraceName(ReleaseType));
1102+
10991103
PageReleaseContext Context = markFreeBlocks(Sci, ClassId, BlockSize, Base,
11001104
NumberOfRegions, ReleaseType);
11011105
if (!Context.hasBlockMarked())

compiler-rt/lib/scudo/standalone/primary64.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,8 +1379,6 @@ uptr SizeClassAllocator64<Config>::releaseToOSMaybe(RegionInfo *Region,
13791379
uptr ClassId,
13801380
ReleaseToOS ReleaseType)
13811381
REQUIRES(Region->MMLock) EXCLUDES(Region->FLLock) {
1382-
SCUDO_SCOPED_TRACE(GetPrimaryReleaseToOSMaybeTraceName(ReleaseType));
1383-
13841382
const uptr BlockSize = getSizeByClassId(ClassId);
13851383
uptr BytesInFreeList;
13861384
const uptr AllocatedUserEnd =
@@ -1444,6 +1442,12 @@ uptr SizeClassAllocator64<Config>::releaseToOSMaybe(RegionInfo *Region,
14441442
// Then we can tell which pages are in-use by querying
14451443
// `PageReleaseContext`.
14461444
// ==================================================================== //
1445+
1446+
// Only add trace point after the quick returns have occurred to avoid
1447+
// incurring performance penalties. Most of the time in this function
1448+
// will be the mark free blocks call and the actual release to OS call.
1449+
SCUDO_SCOPED_TRACE(GetPrimaryReleaseToOSMaybeTraceName(ReleaseType));
1450+
14471451
PageReleaseContext Context =
14481452
markFreeBlocks(Region, BlockSize, AllocatedUserEnd,
14491453
getCompactPtrBaseByClassId(ClassId), GroupsToRelease);

0 commit comments

Comments
 (0)