diff options
| author | 2025-02-05 07:35:05 -0800 | |
|---|---|---|
| committer | 2025-02-05 07:35:05 -0800 | |
| commit | c59db84c455570af8a314f426357355499c804d5 (patch) | |
| tree | f1849d4711626179925b43ae870917a69f2c8b2d /libs/androidfw/Util.cpp | |
| parent | ba67aa701ec4283b318b6477de2e2107dd019252 (diff) | |
Remove synchronization (and potential priority inversions) from RateLimitingCache
Noticed this issue while looking at a trace of binder spam.
Fetching the rate-limited value inside a synchronized block
exposes all call sites to priority inversions.
A priority inversion would happen for instance if an unimportant
caller manages to fetch a value, fetching the value requires for
instance a binder call, and when the calling unimportant thread
becomes runnable again because the result is available that
thread isn't scheduled for a very long time.
In the meantime, another calling thread that is more important is
blocked on entering the synchronized lock.
This change removes the lock, and the opportunity for contention
and inversion.
This slightly changes the behavior of RateLimitingCache.
Before this change, the rate limiter would strictly not permit
more instances of getting the underlying value than is set.
After this change, if there are at most N threads potentially
calling into this cache then in the extreme we would admit at
most limit + N - 1 calls to get the underlying value in a given
window.
Flag: EXEMPT bugfix
Bug: 393503787
Change-Id: I5f392d54c10348fa1dac1c82f15900118325a679
Diffstat (limited to 'libs/androidfw/Util.cpp')
0 files changed, 0 insertions, 0 deletions