Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c59db84c authored by Shai Barack's avatar Shai Barack
Browse files

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
parent ba67aa70
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment