Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1875859 - Refactor MemoryPool::PurgeExpired and PurgeByFrecency t…
…o reduce overhead and protect against races while sorting. r=necko-reviewers,valentin A `CacheEntry`'s `mExpirationTime` and `mFrecency` can be updated asynchronously while sorting. This is at best undefined behavior and at worst it can derail `std::sort`'s algorithm out of bounds. Looking a bit closer it turns out that sorting for `PurgeExpired` is actually not needed and we can have just a `mManagedEntries` linked list in a memory pool instead of two arrays. This way we can also achieve constant O(1) time for unregistering entries when purging. `PurgeByFrecency` needs sorting and must ensure to not race with modifications of `mFrecency`. We ensure to make some progress on each run to compensate for the cost of sorting. We also do `PurgeExpired` always, not only if under memory pressure, as it is cheap (no sorting) and interuptable., as well as an emergency handling if `PurgeByFrecency` failed to allocate the auxiliary sort array. Differential Revision: https://phabricator.services.mozilla.com/D199955
- Loading branch information