Skip to content

[scudo] Add the record of number of attempted page release #120497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions compiler-rt/lib/scudo/standalone/primary32.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ template <typename Config> class SizeClassAllocator32 {

struct ReleaseToOsInfo {
uptr BytesInFreeListAtLastCheckpoint;
uptr RangesReleased;
uptr NumReleasesAttempted;
uptr LastReleasedBytes;
u64 LastReleaseAtNs;
};
Expand Down Expand Up @@ -880,14 +880,14 @@ template <typename Config> class SizeClassAllocator32 {
BytesInFreeList - Sci->ReleaseInfo.BytesInFreeListAtLastCheckpoint;
}
const uptr AvailableChunks = Sci->AllocatedUser / BlockSize;
Str->append(" %02zu (%6zu): mapped: %6zuK popped: %7zu pushed: %7zu "
"inuse: %6zu avail: %6zu releases: %6zu last released: %6zuK "
"latest pushed bytes: %6zuK\n",
ClassId, getSizeByClassId(ClassId), Sci->AllocatedUser >> 10,
Sci->FreeListInfo.PoppedBlocks, Sci->FreeListInfo.PushedBlocks,
InUse, AvailableChunks, Sci->ReleaseInfo.RangesReleased,
Sci->ReleaseInfo.LastReleasedBytes >> 10,
PushedBytesDelta >> 10);
Str->append(
" %02zu (%6zu): mapped: %6zuK popped: %7zu pushed: %7zu "
"inuse: %6zu avail: %6zu releases attempted: %6zu last released: %6zuK "
"latest pushed bytes: %6zuK\n",
ClassId, getSizeByClassId(ClassId), Sci->AllocatedUser >> 10,
Sci->FreeListInfo.PoppedBlocks, Sci->FreeListInfo.PushedBlocks, InUse,
AvailableChunks, Sci->ReleaseInfo.NumReleasesAttempted,
Sci->ReleaseInfo.LastReleasedBytes >> 10, PushedBytesDelta >> 10);
}

void getSizeClassFragmentationInfo(SizeClassInfo *Sci, uptr ClassId,
Expand Down Expand Up @@ -972,6 +972,10 @@ template <typename Config> class SizeClassAllocator32 {
const uptr Base = First * RegionSize;
const uptr NumberOfRegions = Last - First + 1U;

// The following steps contribute to the majority time spent in page
// releasing thus we increment the counter here.
++Sci->ReleaseInfo.NumReleasesAttempted;

// ==================================================================== //
// 2. Mark the free blocks and we can tell which pages are in-use by
// querying `PageReleaseContext`.
Expand All @@ -991,9 +995,8 @@ template <typename Config> class SizeClassAllocator32 {
};
releaseFreeMemoryToOS(Context, Recorder, SkipRegion);

if (Recorder.getReleasedRangesCount() > 0) {
if (Recorder.getReleasedBytes() > 0) {
Sci->ReleaseInfo.BytesInFreeListAtLastCheckpoint = BytesInFreeList;
Sci->ReleaseInfo.RangesReleased += Recorder.getReleasedRangesCount();
Sci->ReleaseInfo.LastReleasedBytes = Recorder.getReleasedBytes();
TotalReleasedBytes += Sci->ReleaseInfo.LastReleasedBytes;
}
Expand Down
10 changes: 5 additions & 5 deletions compiler-rt/lib/scudo/standalone/primary64.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ template <typename Config> class SizeClassAllocator64 {

struct ReleaseToOsInfo {
uptr BytesInFreeListAtLastCheckpoint;
uptr RangesReleased;
uptr NumReleasesAttempted;
uptr LastReleasedBytes;
// The minimum size of pushed blocks to trigger page release.
uptr TryReleaseThreshold;
Expand Down Expand Up @@ -1144,11 +1144,12 @@ template <typename Config> class SizeClassAllocator64 {
Str->append(
"%s %02zu (%6zu): mapped: %6zuK popped: %7zu pushed: %7zu "
"inuse: %6zu total: %6zu releases: %6zu last "
"released: %6zuK latest pushed bytes: %6zuK region: 0x%zx (0x%zx)\n",
"releases attempted: %6zuK latest pushed bytes: %6zuK region: 0x%zx "
"(0x%zx)\n",
Region->Exhausted ? "E" : " ", ClassId, getSizeByClassId(ClassId),
Region->MemMapInfo.MappedUser >> 10, Region->FreeListInfo.PoppedBlocks,
Region->FreeListInfo.PushedBlocks, InUseBlocks, TotalChunks,
Region->ReleaseInfo.RangesReleased,
Region->ReleaseInfo.NumReleasesAttempted,
Region->ReleaseInfo.LastReleasedBytes >> 10,
RegionPushedBytesDelta >> 10, Region->RegionBeg,
getRegionBaseByClassId(ClassId));
Expand Down Expand Up @@ -1322,7 +1323,7 @@ template <typename Config> class SizeClassAllocator64 {
Context.getReleaseOffset());
auto SkipRegion = [](UNUSED uptr RegionIndex) { return false; };
releaseFreeMemoryToOS(Context, Recorder, SkipRegion);
if (Recorder.getReleasedRangesCount() > 0) {
if (Recorder.getReleasedBytes() > 0) {
// This is the case that we didn't hit the release threshold but it has
// been past a certain period of time. Thus we try to release some pages
// and if it does release some additional pages, it's hint that we are
Expand All @@ -1342,7 +1343,6 @@ template <typename Config> class SizeClassAllocator64 {
}

Region->ReleaseInfo.BytesInFreeListAtLastCheckpoint = BytesInFreeList;
Region->ReleaseInfo.RangesReleased += Recorder.getReleasedRangesCount();
Region->ReleaseInfo.LastReleasedBytes = Recorder.getReleasedBytes();
}
Region->ReleaseInfo.LastReleaseAtNs = getMonotonicTimeFast();
Expand Down
8 changes: 0 additions & 8 deletions compiler-rt/lib/scudo/standalone/release.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ template <typename MemMapT> class RegionReleaseRecorder {
RegionReleaseRecorder(MemMapT *RegionMemMap, uptr Base, uptr Offset = 0)
: RegionMemMap(RegionMemMap), Base(Base), Offset(Offset) {}

uptr getReleasedRangesCount() const { return ReleasedRangesCount; }

uptr getReleasedBytes() const { return ReleasedBytes; }

uptr getBase() const { return Base; }
Expand All @@ -33,12 +31,10 @@ template <typename MemMapT> class RegionReleaseRecorder {
void releasePageRangeToOS(uptr From, uptr To) {
const uptr Size = To - From;
RegionMemMap->releasePagesToOS(getBase() + Offset + From, Size);
ReleasedRangesCount++;
ReleasedBytes += Size;
}

private:
uptr ReleasedRangesCount = 0;
uptr ReleasedBytes = 0;
MemMapT *RegionMemMap = nullptr;
uptr Base = 0;
Expand All @@ -52,8 +48,6 @@ class ReleaseRecorder {
ReleaseRecorder(uptr Base, uptr Offset = 0, MapPlatformData *Data = nullptr)
: Base(Base), Offset(Offset), Data(Data) {}

uptr getReleasedRangesCount() const { return ReleasedRangesCount; }

uptr getReleasedBytes() const { return ReleasedBytes; }

uptr getBase() const { return Base; }
Expand All @@ -62,12 +56,10 @@ class ReleaseRecorder {
void releasePageRangeToOS(uptr From, uptr To) {
const uptr Size = To - From;
releasePagesToOS(Base, From + Offset, Size, Data);
ReleasedRangesCount++;
ReleasedBytes += Size;
}

private:
uptr ReleasedRangesCount = 0;
uptr ReleasedBytes = 0;
// The starting address to release. Note that we may want to combine (Base +
// Offset) as a new Base. However, the Base is retrieved from
Expand Down
Loading