From ae1c0eff5f7e8ec97e69d3551f0869100180dd98 Mon Sep 17 00:00:00 2001 From: Paul Bone Date: Mon, 11 Dec 2023 11:01:33 +0000 Subject: [PATCH] Bug 1864828 - pt 2. Add a pref for PHC's minimum RAM size r=glandium Differential Revision: https://phabricator.services.mozilla.com/D194363 --- modules/libpref/init/StaticPrefList.yaml | 5 +++ .../components/nimbus/FeatureManifest.yaml | 4 ++ xpcom/base/PHCManager.cpp | 39 +++++++++++-------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 9406952690fb..c53aeaf0b6de 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -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." #--------------------------------------------------------------------------- diff --git a/toolkit/components/nimbus/FeatureManifest.yaml b/toolkit/components/nimbus/FeatureManifest.yaml index c30ad0f5bb4f..c55129cc73a0 100644 --- a/toolkit/components/nimbus/FeatureManifest.yaml +++ b/toolkit/components/nimbus/FeatureManifest.yaml @@ -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 diff --git a/xpcom/base/PHCManager.cpp b/xpcom/base/PHCManager.cpp index 73ba656d7df1..d2cc2a861c97 100644 --- a/xpcom/base/PHCManager.cpp +++ b/xpcom/base/PHCManager.cpp @@ -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);