@@ -54,6 +54,7 @@ static const Seconds s_pollInterval = 30_s;
5454// platform component. It's a text file containing an unsigned integer value.
5555static String s_GPUMemoryFile;
5656static ssize_t s_envBaseThresholdVideo = 0 ;
57+ static bool s_videoMemoryInFootprint = false ;
5758
5859static bool isWebProcess ()
5960{
@@ -140,6 +141,9 @@ MemoryPressureHandler::MemoryPressureHandler()
140141 if (s_envBaseThresholdVideo)
141142 m_configuration.baseThresholdVideo = s_envBaseThresholdVideo;
142143 }
144+ String gpuInRSS = String::fromLatin1 (getenv (" WPE_POLL_GPU_IN_FOOTPRINT" ));
145+ if (gpuInRSS == String::fromLatin1 (" 1" ) || gpuInRSS.convertToASCIILowercase () == String::fromLatin1 (" true" ))
146+ s_videoMemoryInFootprint = true ;
143147 }
144148}
145149
@@ -237,6 +241,7 @@ size_t MemoryPressureHandler::thresholdForPolicy(MemoryUsagePolicy policy, Memor
237241
238242MemoryUsagePolicy MemoryPressureHandler::policyForFootprints (size_t footprint, size_t footprintVideo)
239243{
244+ footprint = calculateFootprintForPolicyDecision (footprint, footprintVideo);
240245 if (footprint >= thresholdForPolicy (MemoryUsagePolicy::StrictSynchronous, MemoryType::Normal) || footprintVideo >= thresholdForPolicy (MemoryUsagePolicy::StrictSynchronous, MemoryType::Video))
241246 return MemoryUsagePolicy::StrictSynchronous;
242247 if (footprint >= thresholdForPolicy (MemoryUsagePolicy::Strict, MemoryType::Normal) || footprintVideo >= thresholdForPolicy (MemoryUsagePolicy::Strict, MemoryType::Video))
@@ -246,6 +251,16 @@ MemoryUsagePolicy MemoryPressureHandler::policyForFootprints(size_t footprint, s
246251 return MemoryUsagePolicy::Unrestricted;
247252}
248253
254+ size_t MemoryPressureHandler::calculateFootprintForPolicyDecision (size_t footprint, size_t footprintVideo)
255+ {
256+ // Some devices accounts video memory into the process memory footprint (as file mappings - RSSFile).
257+ // In such cases, we need to subtract the video memory from the process memory footprint
258+ // to make the memory pressure policy decision based on the process memory footprint only.
259+ if (s_videoMemoryInFootprint)
260+ footprint -= footprintVideo;
261+ return footprint;
262+ }
263+
249264MemoryUsagePolicy MemoryPressureHandler::currentMemoryUsagePolicy ()
250265{
251266 return policyForFootprints (memoryFootprint (), memoryFootprintVideo ());
@@ -311,9 +326,9 @@ void MemoryPressureHandler::measurementTimerFired()
311326 releaseMemory (Critical::Yes, Synchronous::No);
312327 break ;
313328 case MemoryUsagePolicy::StrictSynchronous:
314- WTFLogAlways (" MemoryPressure: Critical memory usage (PID=%d) [MB]: %zu/%zu, video: %zu/%zu\n " ,
329+ WTFLogAlways (" MemoryPressure: Critical memory usage (PID=%d) [MB]: %zu%s /%zu, video: %zu/%zu\n " ,
315330 getpid (),
316- footprint / MB, m_configuration.baseThreshold / MB,
331+ footprint / MB, s_videoMemoryInFootprint ? " (including video) " : " " , m_configuration.baseThreshold / MB,
317332 footprintVideo / MB, m_configuration.baseThresholdVideo / MB);
318333 releaseMemory (Critical::Yes, Synchronous::Yes);
319334 break ;
0 commit comments