This is an archive of the discontinued LLVM Phabricator instance.

[scudo] Deallocate the AllocatorRingBuffer too in unmapTestOnly
ClosedPublic

Authored by fabio-d on Apr 26 2023, 9:38 AM.

Details

Summary

The AllocatorRingBuffer is allocated dynamically when Allocator is
initialized. This patch adds a corresponding deinitialization call in
unmapTestOnly, to avoid running out of virtual memory if the tests are run
a large number of times on memory-constrained platforms.

Diff Detail

Event Timeline

fabio-d created this revision.Apr 26 2023, 9:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2023, 9:38 AM
Herald added subscribers: yaneury, Enna1. · View Herald Transcript
fabio-d requested review of this revision.Apr 26 2023, 9:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2023, 9:38 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
Caslyn added a subscriber: Caslyn.Apr 26 2023, 9:58 AM

Can you provide a more complete summary of the problem, and how this addresses it? If there is an tracking issue on github, it's fine to keep the summary terse if the bug covers it in more detail, but this probably needs more context for anyone coming along later to understand why this is required, and the problem you're trying to solve.

fabio-d edited the summary of this revision. (Show Details)Apr 26 2023, 1:32 PM
fabio-d added a reviewer: mcgrathr.
Chia-hungDuan added inline comments.May 1 2023, 5:52 PM
compiler-rt/lib/scudo/standalone/combined.h
1523

It looks like we already store the size, can we use this instead? Besides, we may want reset them to zero like

RawRingBuffer = nullptr;
RingBuffer->Size = 0;
1530

I may suggest some name like deallocateRingBuffer or destroyRingBuffer

fabio-d updated this revision to Diff 518766.May 2 2023, 9:16 AM
fabio-d marked 2 inline comments as done.May 2 2023, 9:19 AM
fabio-d added inline comments.
compiler-rt/lib/scudo/standalone/combined.h
1523

Done, thanks! There was no need to set the size back to 0 because RingBuffer->Size is actually stored in the memory region that is unmapped.

1530

Renamed to destroyRingBuffer, thanks!

paulkirth added inline comments.May 2 2023, 10:45 AM
compiler-rt/lib/scudo/standalone/combined.h
1530

fly-by-comment: you may want to rename the initialization function something like mapAndInitialzeRingBuffer and this to unmapRingBuffer, since 1) that more closely matches what's going on, and 2) the relationship is obvious from the naming.

alternatively using allocate/deallocate instead of map is equally good.

Chia-hungDuan accepted this revision.May 9 2023, 11:38 AM
Chia-hungDuan added inline comments.
compiler-rt/lib/scudo/standalone/combined.h
1519–1520

BTW, I think this roundUp() is something we want to fix as well. Just add a note here.

This revision is now accepted and ready to land.May 9 2023, 11:38 AM
pcc added a subscriber: pcc.May 9 2023, 1:57 PM
pcc added inline comments.
compiler-rt/lib/scudo/standalone/combined.h
1532

Why not call getRingBufferSize()?

Chia-hungDuan requested changes to this revision.May 9 2023, 5:25 PM
Chia-hungDuan added inline comments.
compiler-rt/lib/scudo/standalone/combined.h
1532

Oh I forgot we have this.
BTW, even if we use getRingBufferSize(), we still need to do the roundUp. The need of roundUp will be fixed later.

This revision now requires changes to proceed.May 9 2023, 5:25 PM
fabio-d updated this revision to Diff 521691.May 12 2023, 9:44 AM
fabio-d marked 2 inline comments as done.
fabio-d marked 3 inline comments as done.May 12 2023, 9:47 AM
fabio-d added inline comments.
compiler-rt/lib/scudo/standalone/combined.h
1530

Renamed to mapAndInitializeRingBuffer and unmapRingBuffer as you suggested.

1532

Thanks! I've updated the CL to use getRingBufferSize() while keeping the roundUp

Chia-hungDuan accepted this revision.May 12 2023, 2:20 PM
This revision is now accepted and ready to land.May 12 2023, 2:20 PM
This revision was automatically updated to reflect the committed changes.