@@ -58,6 +58,7 @@ static std::atomic<bool> s_hasCreatedMemoryPressureHandler;
5858// platform component. It's a text file containing an unsigned integer value.
5959static String s_GPUMemoryFile;
6060static ssize_t s_envBaseThresholdVideo = 0 ;
61+ static bool s_videoMemoryInFootprint = false ;
6162
6263static bool isWebProcess ()
6364{
@@ -150,6 +151,9 @@ MemoryPressureHandler::MemoryPressureHandler()
150151 if (s_envBaseThresholdVideo)
151152 m_configuration.baseThresholdVideo = s_envBaseThresholdVideo;
152153 }
154+ String gpuInRSS = String::fromLatin1 (getenv (" WPE_POLL_GPU_IN_FOOTPRINT" ));
155+ if (gpuInRSS == String::fromLatin1 (" 1" ) || gpuInRSS.convertToASCIILowercase () == String::fromLatin1 (" true" ))
156+ s_videoMemoryInFootprint = true ;
153157 }
154158}
155159
@@ -246,6 +250,7 @@ size_t MemoryPressureHandler::thresholdForPolicy(MemoryUsagePolicy policy, Memor
246250
247251MemoryUsagePolicy MemoryPressureHandler::policyForFootprints (size_t footprint, size_t footprintVideo)
248252{
253+ footprint = calculateFootprintForPolicyDecision (footprint, footprintVideo);
249254 if (footprint >= thresholdForPolicy (MemoryUsagePolicy::StrictSynchronous, MemoryType::Normal) || footprintVideo >= thresholdForPolicy (MemoryUsagePolicy::StrictSynchronous, MemoryType::Video))
250255 return MemoryUsagePolicy::StrictSynchronous;
251256 if (footprint >= thresholdForPolicy (MemoryUsagePolicy::Strict, MemoryType::Normal) || footprintVideo >= thresholdForPolicy (MemoryUsagePolicy::Strict, MemoryType::Video))
@@ -255,6 +260,16 @@ MemoryUsagePolicy MemoryPressureHandler::policyForFootprints(size_t footprint, s
255260 return MemoryUsagePolicy::Unrestricted;
256261}
257262
263+ size_t MemoryPressureHandler::calculateFootprintForPolicyDecision (size_t footprint, size_t footprintVideo)
264+ {
265+ // Some devices accounts video memory into the process memory footprint (as file mappings - RSSFile).
266+ // In such cases, we need to subtract the video memory from the process memory footprint
267+ // to make the memory pressure policy decision based on the process memory footprint only.
268+ if (s_videoMemoryInFootprint)
269+ footprint -= footprintVideo;
270+ return footprint;
271+ }
272+
258273MemoryUsagePolicy MemoryPressureHandler::currentMemoryUsagePolicy ()
259274{
260275 if (m_isSimulatingMemoryWarning)
@@ -341,9 +356,9 @@ void MemoryPressureHandler::measurementTimerFired()
341356 releaseMemory (Critical::Yes, Synchronous::No);
342357 break ;
343358 case MemoryUsagePolicy::StrictSynchronous:
344- WTFLogAlways (" MemoryPressure: Critical memory usage (PID=%d) [MB]: %zu/%zu, video: %zu/%zu\n " ,
359+ WTFLogAlways (" MemoryPressure: Critical memory usage (PID=%d) [MB]: %zu%s /%zu, video: %zu/%zu\n " ,
345360 getpid (),
346- footprint / MB, m_configuration.baseThreshold / MB,
361+ footprint / MB, s_videoMemoryInFootprint ? " (including video) " : " " , m_configuration.baseThreshold / MB,
347362 footprintVideo / MB, m_configuration.baseThresholdVideo / MB);
348363 releaseMemory (Critical::Yes, Synchronous::Yes);
349364 break ;
0 commit comments