Skip to content

Commit b68acb2

Browse files
committed
[scudo] Move the trace point in releaseToOSMaybe
Move the trace point until after it is determined that a release to os operation is needed in the releaseToOSMaybe function. This avoids adding extra calculations on a fast path.
1 parent 4ab8dab commit b68acb2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 5 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);
@@ -1104,6 +1102,11 @@ uptr SizeClassAllocator32<Config>::releaseToOSMaybe(SizeClassInfo *Sci,
11041102
// ==================================================================== //
11051103
// 3. Release the unused physical pages back to the OS.
11061104
// ==================================================================== //
1105+
1106+
// Only add trace point after it is determined that a release will occur to
1107+
// avoid incurring performance penalties.
1108+
SCUDO_SCOPED_TRACE(GetPrimaryReleaseToOSMaybeTraceName(ReleaseType));
1109+
11071110
ReleaseRecorder Recorder(Base);
11081111
auto SkipRegion = [this, First, ClassId](uptr RegionIndex) {
11091112
ScopedLock L(ByteMapMutex);

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

Lines changed: 5 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 =
@@ -1455,6 +1453,11 @@ uptr SizeClassAllocator64<Config>::releaseToOSMaybe(RegionInfo *Region,
14551453
// ==================================================================== //
14561454
// 4. Release the unused physical pages back to the OS.
14571455
// ==================================================================== //
1456+
1457+
// Only add trace point after it is determined that a release will occur to
1458+
// avoid incurring performance penalties.
1459+
SCUDO_SCOPED_TRACE(GetPrimaryReleaseToOSMaybeTraceName(ReleaseType));
1460+
14581461
RegionReleaseRecorder<MemMapT> Recorder(&Region->MemMapInfo.MemMap,
14591462
Region->RegionBeg,
14601463
Context.getReleaseOffset());

0 commit comments

Comments
 (0)