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
This commit is contained in:
Jan Varga 2022-01-19 21:32:15 +00:00
Родитель b4b60bf5d3
Коммит b5d63c6ae5
4 изменённых файлов: 69 добавлений и 16 удалений

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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`

Просмотреть файл

@ -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