[compiler-rt] r364345 - [scudo] Correct a behavior on the shared TSD registry
Kostya Kortchinsky via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 25 12:58:12 PDT 2019
Author: cryptoad
Date: Tue Jun 25 12:58:11 2019
New Revision: 364345
URL: http://llvm.org/viewvc/llvm-project?rev=364345&view=rev
Log:
[scudo] Correct a behavior on the shared TSD registry
Summary:
There is an error in the shared TSD registry logic when looking for a
TSD in the slow path. There is an unlikely event when a TSD's precedence
was 0 after attempting a `tryLock` which indicated that it was grabbed
by another thread in between. We dealt with that case by continuing to
the next iteration, but that meant that the `Index` was not increased
and we ended up trying to lock the same TSD.
This would manifest in heavy contention, and in the end we would still
lock a TSD, but that was a wasted iteration.
So, do not `continue`, just skip the TSD as a potential candidate.
This is in both the standalone & non-standalone versions.
Reviewers: morehouse, eugenis, vitalybuka, hctim
Reviewed By: morehouse
Subscribers: delcypher, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D63783
Modified:
compiler-rt/trunk/lib/scudo/scudo_tsd_shared.cpp
compiler-rt/trunk/lib/scudo/standalone/tsd_shared.h
Modified: compiler-rt/trunk/lib/scudo/scudo_tsd_shared.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_tsd_shared.cpp?rev=364345&r1=364344&r2=364345&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_tsd_shared.cpp (original)
+++ compiler-rt/trunk/lib/scudo/scudo_tsd_shared.cpp Tue Jun 25 12:58:11 2019
@@ -83,9 +83,7 @@ ScudoTSD *getTSDAndLockSlow(ScudoTSD *TS
}
const uptr Precedence = TSDs[Index].getPrecedence();
// A 0 precedence here means another thread just locked this TSD.
- if (UNLIKELY(Precedence == 0))
- continue;
- if (Precedence < LowestPrecedence) {
+ if (Precedence && Precedence < LowestPrecedence) {
CandidateTSD = &TSDs[Index];
LowestPrecedence = Precedence;
}
Modified: compiler-rt/trunk/lib/scudo/standalone/tsd_shared.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tsd_shared.h?rev=364345&r1=364344&r2=364345&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tsd_shared.h (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tsd_shared.h Tue Jun 25 12:58:11 2019
@@ -126,9 +126,7 @@ private:
}
const uptr Precedence = TSDs[Index].getPrecedence();
// A 0 precedence here means another thread just locked this TSD.
- if (UNLIKELY(Precedence == 0))
- continue;
- if (Precedence < LowestPrecedence) {
+ if (Precedence && Precedence < LowestPrecedence) {
CandidateTSD = &TSDs[Index];
LowestPrecedence = Precedence;
}
More information about the llvm-commits
mailing list