From b5d63c6ae50dd23d1deb574073e486ff43cbead0 Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Wed, 19 Jan 2022 21:32:15 +0000 Subject: [PATCH] Bug 1733054 - Introduce prefs for peak usage pre-incrementation and idle timeout; r=dom-storage-reviewers,asuth Differential Revision: https://phabricator.services.mozilla.com/D135518 --- dom/localstorage/ActorsParent.cpp | 24 ++++++++++--- dom/localstorage/LSSnapshot.cpp | 10 ++---- dom/localstorage/PBackgroundLSDatabase.ipdl | 11 +++--- modules/libpref/init/StaticPrefList.yaml | 40 +++++++++++++++++++++ 4 files changed, 69 insertions(+), 16 deletions(-) diff --git a/dom/localstorage/ActorsParent.cpp b/dom/localstorage/ActorsParent.cpp index f3bd22b1e8cf..3bb18a1f4df6 100644 --- a/dom/localstorage/ActorsParent.cpp +++ b/dom/localstorage/ActorsParent.cpp @@ -2958,6 +2958,21 @@ void SnapshotGradualPrefillPrefChangedCallback(const char* aPrefName, gSnapshotGradualPrefill = snapshotGradualPrefill; } +int64_t GetSnapshotPeakUsagePreincrement(bool aInitial) { + return aInitial ? StaticPrefs:: + dom_storage_snapshot_peak_usage_initial_preincrement() + : StaticPrefs:: + dom_storage_snapshot_peak_usage_gradual_preincrement(); +} + +int64_t GetSnapshotPeakUsageReducedPreincrement(bool aInitial) { + return aInitial + ? StaticPrefs:: + dom_storage_snapshot_peak_usage_reduced_initial_preincrement() + : StaticPrefs:: + dom_storage_snapshot_peak_usage_reduced_gradual_preincrement(); +} + void ClientValidationPrefChangedCallback(const char* aPrefName, void* aClosure) { MOZ_ASSERT(NS_IsMainThread()); @@ -4961,15 +4976,16 @@ int64_t Datastore::AttemptToUpdateUsage(int64_t aMinSize, bool aInitial) { MOZ_ASSERT_IF(aInitial, aMinSize >= 0); MOZ_ASSERT_IF(!aInitial, aMinSize > 0); - const int64_t size = aMinSize + (aInitial ? 131072 : 4096); + const int64_t size = aMinSize + GetSnapshotPeakUsagePreincrement(aInitial); - if (UpdateUsage(size)) { + if (size && UpdateUsage(size)) { return size; } - const int64_t reducedSize = aMinSize + (aInitial ? 4096 : 1024); + const int64_t reducedSize = + aMinSize + GetSnapshotPeakUsageReducedPreincrement(aInitial); - if (UpdateUsage(reducedSize)) { + if (reducedSize && UpdateUsage(reducedSize)) { return reducedSize; } diff --git a/dom/localstorage/LSSnapshot.cpp b/dom/localstorage/LSSnapshot.cpp index 73d6aa61abc2..5a7594d36583 100644 --- a/dom/localstorage/LSSnapshot.cpp +++ b/dom/localstorage/LSSnapshot.cpp @@ -26,6 +26,7 @@ #include "mozilla/Preferences.h" #include "mozilla/RefPtr.h" #include "mozilla/ScopeExit.h" +#include "mozilla/StaticPrefs_dom.h" #include "mozilla/UniquePtr.h" #include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/LSValue.h" @@ -47,12 +48,6 @@ namespace mozilla::dom { -namespace { - -const uint32_t kSnapshotIdleTimeoutMs = 20000; - -} // namespace - /** * Coalescing manipulation queue used by `LSSnapshot`. Used by `LSSnapshot` to * buffer and coalesce manipulations before they are sent to the parent process, @@ -1008,7 +1003,8 @@ LSSnapshot::Run() { MOZ_ASSERT(mIdleTimer); MOZ_ALWAYS_SUCCEEDS(mIdleTimer->InitWithNamedFuncCallback( - IdleTimerCallback, this, kSnapshotIdleTimeoutMs, + IdleTimerCallback, this, + StaticPrefs::dom_storage_snapshot_idle_timeout_ms(), nsITimer::TYPE_ONE_SHOT, "LSSnapshot::IdleTimerCallback")); mHasPendingIdleTimerCallback = true; diff --git a/dom/localstorage/PBackgroundLSDatabase.ipdl b/dom/localstorage/PBackgroundLSDatabase.ipdl index 330561f40b7b..fa3871998b26 100644 --- a/dom/localstorage/PBackgroundLSDatabase.ipdl +++ b/dom/localstorage/PBackgroundLSDatabase.ipdl @@ -52,11 +52,12 @@ struct LSSnapshotInitInfo * The amount of storage allowed to be used by the Snapshot without requesting * more storage space via IncreasePeakUsage. This is the `initialUsage` plus * 0 or more bytes of space. If space was available, the increase will be the - * `minSize` from the PBackgroundLSSnapshot constructor plus peak usage - * initial pre-increment. If the LocalStorage usage was already close to the - * limit, then the fallback is either the `minSize` plus peak usage reduced - * initial pre-increment, or `minSize`, or 0 depending on remaining available - * space. + * `minSize` from the PBackgroundLSSnapshot constructor plus the configured + * pre-increment (via "dom.storage.snapshot_peak_usage.initial_preincrement"). + * If the LocalStorage total usage was already close to the limit, then the + * fallback is either the `minSize` plus the configured reduced pre-increment + * (via "dom.storage.snapshot_peak_usage.reduced_initial_preincrement"), or + * `minSize`, or 0 depending on remaining available space. */ int64_t peakUsage; // See `LSSnapshot::LoadState` in `LSSnapshot.h` diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index a470021e2912..4390d31ff41a 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -3511,6 +3511,46 @@ mirror: always do_not_use_directly: true +# The amount of snapshot peak usage which is attempted to be pre-incremented +# during snapshot creation. +- name: dom.storage.snapshot_peak_usage.initial_preincrement + type: RelaxedAtomicUint32 + value: 131072 + mirror: always + +# The amount of snapshot peak usage which is attempted to be pre-incremented +# during snapshot creation if the LocalStorage usage was already close to the +# limit (a fallback for dom.storage.snapshot_peak_usage.initial_preincrement). +- name: dom.storage.snapshot_peak_usage.reduced_initial_preincrement + type: RelaxedAtomicUint32 + value: 4096 + mirror: always + +# The amount of snapshot peak usage which is attempted to be pre-incremented +# beyond the specific values which are subsequently requested after snapshot +# creation. +- name: dom.storage.snapshot_peak_usage.gradual_preincrement + type: RelaxedAtomicUint32 + value: 4096 + mirror: always + +# The amount of snapshot peak usage which is attempted to be pre-incremented +# beyond the specific values which are subsequently requested after snapshot +# creation if the LocalStorage total usage was already close to the limit +# (a fallback for dom.storage.snapshot_peak_usage.gradual_preincrement). +- name: dom.storage.snapshot_peak_usage.reduced_gradual_preincrement + type: RelaxedAtomicUint32 + value: 1024 + mirror: always + +# How long between a snapshot becomes idle and when we actually finish the +# snapshot. This preference is only used when "dom.storage.snapshot_reusing" +# is true. +- name: dom.storage.snapshot_idle_timeout_ms + type: uint32_t + value: 20000 + mirror: always + # Is support for Storage test APIs enabled? - name: dom.storage.testing type: bool