From 1e1744fe51116d86accc74db21e6ceda46b62959 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Thu, 25 Jan 2024 19:45:42 +0000 Subject: [PATCH] Bug 1867190 - Add prefs for PHC probablities r=glandium Differential Revision: https://phabricator.services.mozilla.com/D198652 UltraBlame original commit: ce5606473bf95f0899f69034525766ca9d0ed749 --- memory/build/PHC.cpp | 160 ++++++++++++++++++ memory/build/PHC.h | 12 ++ modules/libpref/init/StaticPrefList.yaml | 57 +++++++ .../components/nimbus/FeatureManifest.yaml | 82 +++++++++ xpcom/base/PHCManager.cpp | 155 +++++++++++++++++ 5 files changed, 466 insertions(+) diff --git a/memory/build/PHC.cpp b/memory/build/PHC.cpp index 41df1965224ef..1fcd23af04248 100644 --- a/memory/build/PHC.cpp +++ b/memory/build/PHC.cpp @@ -3678,7 +3678,10 @@ return aRnd & ( +uint64_t +( aAvgDelay +) * 2 - @@ -3689,6 +3692,88 @@ aAvgDelay 1 ; } +constexpr +Delay +CheckProbability +( +int64_t +aProb +) +{ +/ +/ +Limit +delays +calculated +from +prefs +to +0x80000000 +this +is +the +largest +/ +/ +power +- +of +- +two +that +fits +in +a +Delay +since +it +is +a +uint32_t +. +/ +/ +The +minimum +is +2 +that +way +not +every +allocation +goes +straight +to +PHC +. +return +RoundUpPow2 +( +std +: +: +min +( +std +: +: +max +( +aProb +int64_t +( +2 +) +) +int64_t +( +0x80000000 +) +) +) +; +} / / Maps @@ -7234,6 +7319,48 @@ mPhcState aState ; } +void +SetProbabilities +( +int64_t +aAvgDelayFirst +int64_t +aAvgDelayNormal +int64_t +aAvgDelayPageReuse +) +{ +MutexAutoLock +lock +( +GMut +: +: +sMutex +) +; +mAvgFirstAllocDelay += +CheckProbability +( +aAvgDelayFirst +) +; +mAvgAllocDelay += +CheckProbability +( +aAvgDelayNormal +) +; +mAvgPageReuseDelay += +CheckProbability +( +aAvgDelayPageReuse +) +; +} private : template @@ -14770,6 +14897,39 @@ aState ) ; } +void +SetPHCProbabilities +( +int64_t +aAvgDelayFirst +int64_t +aAvgDelayNormal +int64_t +aAvgDelayPageReuse +) +{ +if +( +! +maybe_init +( +) +) +{ +return +; +} +gMut +- +> +SetProbabilities +( +aAvgDelayFirst +aAvgDelayNormal +aAvgDelayPageReuse +) +; +} } / / diff --git a/memory/build/PHC.h b/memory/build/PHC.h index e25fb9044f380..386f5acee2daa 100644 --- a/memory/build/PHC.h +++ b/memory/build/PHC.h @@ -979,6 +979,18 @@ PHCState aState ) ; +MOZ_JEMALLOC_API +void +SetPHCProbabilities +( +int64_t +aAvgDelayFirst +int64_t +aAvgDelayNormal +int64_t +aAvgDelayPageReuse +) +; struct MemoryUsage { diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 75fba8fa6445e..e50b696252323 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -66759,6 +66759,63 @@ value mirror : always +- +name +: +memory +. +phc +. +avg_delay +. +first +type +: +uint32_t +value +: +65536 +mirror +: +always +- +name +: +memory +. +phc +. +avg_delay +. +normal +type +: +uint32_t +value +: +16384 +mirror +: +always +- +name +: +memory +. +phc +. +avg_delay +. +page_reuse +type +: +uint32_t +value +: +262144 +mirror +: +always # - - diff --git a/toolkit/components/nimbus/FeatureManifest.yaml b/toolkit/components/nimbus/FeatureManifest.yaml index 1c86db2b5e8b8..4c58f175fd9db 100644 --- a/toolkit/components/nimbus/FeatureManifest.yaml +++ b/toolkit/components/nimbus/FeatureManifest.yaml @@ -14349,6 +14349,88 @@ memory phc . min_ram_mb +phcAvgDelayFirst +: +description +: +The +delay +before +the +first +PHC +allocation +type +: +int +setPref +: +branch +: +user +pref +: +memory +. +phc +. +avg_delay +. +first +phcAvgDelayNormal +: +description +: +The +delay +between +PHC +allocations +type +: +int +setPref +: +branch +: +user +pref +: +memory +. +phc +. +avg_delay +. +normal +phcAvgDelayPageReuse +: +description +: +The +delay +before +reusing +a +PHC +page +type +: +int +setPref +: +branch +: +user +pref +: +memory +. +phc +. +avg_delay +. +page_reuse mailto : description diff --git a/xpcom/base/PHCManager.cpp b/xpcom/base/PHCManager.cpp index 2a07219a22212..9f861b53016a4 100644 --- a/xpcom/base/PHCManager.cpp +++ b/xpcom/base/PHCManager.cpp @@ -206,6 +206,57 @@ phc min_ram_mb " ; +static +const +char +kPHCAvgDelayFirst +[ +] += +" +memory +. +phc +. +avg_delay +. +first +" +; +static +const +char +kPHCAvgDelayNormal +[ +] += +" +memory +. +phc +. +avg_delay +. +normal +" +; +static +const +char +kPHCAvgDelayPageRuse +[ +] += +" +memory +. +phc +. +avg_delay +. +page_reuse +" +; / / True @@ -317,6 +368,47 @@ mem_size min_mem_size ) { +/ +/ +Set +PHC +probablities +before +enabling +PHC +so +that +the +first +allocation +/ +/ +delay +gets +used +. +SetPHCProbabilities +( +StaticPrefs +: +: +memory_phc_avg_delay_first +( +) +StaticPrefs +: +: +memory_phc_avg_delay_normal +( +) +StaticPrefs +: +: +memory_phc_avg_delay_page_reuse +( +) +) +; SetPHCState ( Enabled @@ -373,6 +465,42 @@ aPrefName kPHCMinRamMBPref ) ) +| +| +( +0 += += +strcmp +( +aPrefName +kPHCAvgDelayFirst +) +) +| +| +( +0 += += +strcmp +( +aPrefName +kPHCAvgDelayNormal +) +) +| +| +( +0 += += +strcmp +( +aPrefName +kPHCAvgDelayPageRuse +) +) ) ; UpdatePHCState @@ -403,6 +531,33 @@ PrefChangeCallback kPHCMinRamMBPref ) ; +Preferences +: +: +RegisterCallback +( +PrefChangeCallback +kPHCAvgDelayFirst +) +; +Preferences +: +: +RegisterCallback +( +PrefChangeCallback +kPHCAvgDelayNormal +) +; +Preferences +: +: +RegisterCallback +( +PrefChangeCallback +kPHCAvgDelayPageRuse +) +; UpdatePHCState ( )