This is an archive of the discontinued LLVM Phabricator instance.

[scudo] Finer lock granularity in Region of SizeClassAllocator64
ClosedPublic

Authored by Chia-hungDuan on Apr 25 2023, 2:57 AM.

Details

Summary
[scudo] Finer lock granularity in Region of SizeClassAllocator64

In this CL, we introduce two new locks, MMLock for MemMap operations and
FLLock for freelist operations.

MMLock will be used when we want to manipulate pages. For example,
mapping more pages through populateFreeList() and releaseToOSMaybe().

FLLock will be used when we want to access the freelist. For example,
pushBlocks() and popBatch().

With the new locks, they increase the parallelism of the operations
mentioned above. For example, populateFreeList() won't block the
pushBlocks() when it's still doing the system call for more pages.

We also enforce lock hierarchy to avoid deadlock, MMLock is required to
be held before FLLock if you have to lock both of them. We don't store
the lock owner, therefore, we rely static thread-safey annotation to
detect any violation.

Diff Detail

Event Timeline

Chia-hungDuan created this revision.Apr 25 2023, 2:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 2:57 AM
Chia-hungDuan requested review of this revision.Apr 25 2023, 2:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 2:57 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript

Fix the logic of pushing block of BatchClass

Add more comments

Chia-hungDuan retitled this revision from [scudo] Finer lock granularity in Region of SizeClassAllocator64 (WIP) to [scudo] Finer lock granularity in Region of SizeClassAllocator64.Apr 25 2023, 10:50 PM
Chia-hungDuan edited the summary of this revision. (Show Details)
Chia-hungDuan added a reviewer: cferris.
Chia-hungDuan added a reviewer: cryptoad.
Chia-hungDuan edited the summary of this revision. (Show Details)

Acquire FLLock before entering releaseToOSMaybe()

Fix the use of tryLock() in popBatch()

Minor refactor in populateFreeList. Which is mainly for the dependent CLs

cryptoad added inline comments.Jun 8 2023, 10:51 AM
compiler-rt/lib/scudo/standalone/primary64.h
190

nit: const

499–501

Isn't RandState getting changed with every shuffle?

Chia-hungDuan added inline comments.Jun 8 2023, 11:27 AM
compiler-rt/lib/scudo/standalone/primary64.h
499–501

You're right. I forgot it's passed by reference in shuffle(). Will fix it in later CL

Chia-hungDuan marked an inline comment as done.

Mark RandState as guarded by MMLock and other review comment

cferris requested changes to this revision.Jun 14 2023, 6:28 PM
cferris added inline comments.
compiler-rt/lib/scudo/standalone/primary64.h
168

to call

171

Use a condition

185

gets

189

Since the same locks aren't being held, I'm guessing you still want to do the stats printing after the loop to avoid holding MMLock. If so, you should probably put a comment here about that.

223

using a condition

228

Is there a reason you are using a variable here? It looks like the if statement below is the only time NeedToRefill is used.

This revision now requires changes to proceed.Jun 14 2023, 6:28 PM
Chia-hungDuan marked 6 inline comments as done.

Address review comment

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

I hope this variable will give the idea of why we check Size == 1U and that is a little bit unclear at the first glance. In the future change D152419, we add one more condition here so I think it may be better not to squeeze them in the predicate.

cferris accepted this revision.Jun 15 2023, 5:03 PM

LGTM.

This revision is now accepted and ready to land.Jun 15 2023, 5:03 PM