Bug 1776004 - Intermittent fix: Report QM usage, allow for incremental vacuum. r=edenchuang

This attempts to address intermittents where the QM usage is not as low
as we expect.  The patch:
- Reports the QM usage via `info()`.
- Adjusts the minimum origin usage to allow for the Cache API storage
  to be empty by way of having had its contents cleared and the
  incremental vacuum heuristics having found that there weren't enough
  free pages to force an incremental vacuum.
  - Because we are using 15 of the 16 pages when fully vacuumed and the
    incremental vacuum heuristics only kick in when we have at least 8
    free pages, it's definitely possible for an empty Cache DB to be
    3 * 32 KiB in size.

Note that this is not guaranteed to fix the problem; it's possible
there is an actual ordering problem that is causing us to try and get
the quota usage before it has been cleared, but in that case we will
still fail because we ensure that we have multiple megabytes of storage
used.  And in that case, the QM usage being reported will let us move
to the next stage of investigation with some idea of what's going on.

Differential Revision: https://phabricator.services.mozilla.com/D211959
This commit is contained in:
Andrew Sutherland 2024-06-04 14:43:51 +00:00
parent 521ca6e5fc
commit ea95ed5090

View file

@ -26,8 +26,11 @@ const SWM = Cc["@mozilla.org/serviceworkers/manager;1"].getService(
// The expected minimum usage for an origin that has any Cache API storage in
// use. Currently, the DB uses a page size of 4k and a minimum growth size of
// 32k and has enough tables/indices for this to round up to 64k.
const kMinimumOriginUsageBytes = 65536;
// 32k and has enough tables/indices for this to use 15 pages (61440) which
// rounds up to 64k. However, we also have to allow for the incremental
// vacuum heuristic only firing if we have more than the growth increment's
// worth of free pages, so we need to set the threshold at 32k * 3.
const kMinimumOriginUsageBytes = 98304;
function getPrincipal(url, attrs) {
const uri = Services.io.newURI(url);
@ -62,9 +65,10 @@ async function get_qm_origin_usage(origin) {
return new Promise(resolve => {
const principal =
Services.scriptSecurityManager.createContentPrincipalFromOrigin(origin);
Services.qms.getUsageForPrincipal(principal, request =>
resolve(request.result.usage)
);
Services.qms.getUsageForPrincipal(principal, request => {
info(`QM says usage of ${origin} is ${request.result.usage}`);
resolve(request.result.usage);
});
});
}