Bug 1864828 - pt 2. Add a pref for PHC's minimum RAM size r=glandium

Differential Revision: https://phabricator.services.mozilla.com/D194363
This commit is contained in:
Paul Bone 2023-12-11 11:01:33 +00:00
parent 4f15ab146d
commit ae1c0eff5f
3 changed files with 32 additions and 16 deletions

View File

@ -11126,6 +11126,11 @@
value: @IS_EARLY_BETA_OR_EARLIER@
mirror: always
- name: memory.phc.min_ram_mb
type: uint32_t
value: 8000
mirror: always
#---------------------------------------------------------------------------
# Prefs starting with "midi."
#---------------------------------------------------------------------------

View File

@ -2015,6 +2015,10 @@ phc:
description: Whether to enable PHC
type: boolean
setPref: memory.phc.enabled
phcMinRamMB:
description: The minimum amount of RAM required to enable PHC
type: int
setPref: memory.phc.min_ram_mb
mailto:
description: Prefs to control aspects of the mailto handler

View File

@ -7,6 +7,7 @@
#include "PHCManager.h"
#include "PHC.h"
#include "mozilla/Literals.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs_memory.h"
#include "mozilla/Telemetry.h"
@ -16,31 +17,37 @@ namespace mozilla {
using namespace phc;
static const char kPHCPref[] = "memory.phc.enabled";
static const char kPHCEnabledPref[] = "memory.phc.enabled";
static const char kPHCMinRamMBPref[] = "memory.phc.min_ram_mb";
static PHCState GetPHCStateFromPref() {
return StaticPrefs::memory_phc_enabled() ? Enabled : OnlyFree;
}
static void UpdatePHCState() {
size_t mem_size = PR_GetPhysicalMemorySize() / (1_MiB);
size_t min_mem_size = StaticPrefs::memory_phc_min_ram_mb();
static void PrefChangeCallback(const char* aPrefName, void* aNull) {
MOZ_ASSERT(0 == strcmp(aPrefName, kPHCPref));
SetPHCState(GetPHCStateFromPref());
}
void InitPHCState() {
size_t memSize = PR_GetPhysicalMemorySize();
// Only enable PHC if there are at least 8GB of ram. Note that we use
// 1000 bytes per kilobyte rather than 1024. Some 8GB machines will have
// slightly lower actual RAM available after some hardware devices
// reserve some.
if (memSize >= size_t(8'000'000'000llu)) {
SetPHCState(GetPHCStateFromPref());
Preferences::RegisterCallback(PrefChangeCallback, kPHCPref);
if (StaticPrefs::memory_phc_enabled() && mem_size >= min_mem_size) {
SetPHCState(Enabled);
} else {
SetPHCState(OnlyFree);
}
}
static void PrefChangeCallback(const char* aPrefName, void* aNull) {
MOZ_ASSERT((0 == strcmp(aPrefName, kPHCEnabledPref)) ||
(0 == strcmp(aPrefName, kPHCMinRamMBPref)));
UpdatePHCState();
}
void InitPHCState() {
Preferences::RegisterCallback(PrefChangeCallback, kPHCEnabledPref);
Preferences::RegisterCallback(PrefChangeCallback, kPHCMinRamMBPref);
UpdatePHCState();
}
void ReportPHCTelemetry() {
MemoryUsage usage;
PHCMemoryUsage(usage);