From ea95ed509039752e11748da1143175054cad0627 Mon Sep 17 00:00:00 2001 From: Andrew Sutherland Date: Tue, 4 Jun 2024 14:43:51 +0000 Subject: [PATCH] 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 --- dom/serviceworkers/test/browser_head.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/dom/serviceworkers/test/browser_head.js b/dom/serviceworkers/test/browser_head.js index 78e4d327ec5f..1f76bd7b406f 100644 --- a/dom/serviceworkers/test/browser_head.js +++ b/dom/serviceworkers/test/browser_head.js @@ -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); + }); }); }