@@ -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
@@ -167,6 +171,7 @@ static const char* toString(MemoryUsagePolicy policy)
167171 case MemoryUsagePolicy::Unrestricted: return " Unrestricted" ;
168172 case MemoryUsagePolicy::Conservative: return " Conservative" ;
169173 case MemoryUsagePolicy::Strict: return " Strict" ;
174+ case MemoryUsagePolicy::StrictSynchronous: return " StrictSynchronous" ;
170175 }
171176 ASSERT_NOT_REACHED ();
172177 return " " ;
@@ -228,6 +233,8 @@ size_t MemoryPressureHandler::thresholdForPolicy(MemoryUsagePolicy policy, Memor
228233 return m_configuration.conservativeThresholdFraction * (type == MemoryType::Normal ? m_configuration.baseThreshold : m_configuration.baseThresholdVideo );
229234 case MemoryUsagePolicy::Strict:
230235 return m_configuration.strictThresholdFraction * (type == MemoryType::Normal ? m_configuration.baseThreshold : m_configuration.baseThresholdVideo );
236+ case MemoryUsagePolicy::StrictSynchronous:
237+ return type == MemoryType::Normal ? m_configuration.baseThreshold : m_configuration.baseThresholdVideo ;
231238 default :
232239 ASSERT_NOT_REACHED ();
233240 return 0 ;
@@ -236,13 +243,26 @@ size_t MemoryPressureHandler::thresholdForPolicy(MemoryUsagePolicy policy, Memor
236243
237244MemoryUsagePolicy MemoryPressureHandler::policyForFootprints (size_t footprint, size_t footprintVideo)
238245{
246+ footprint = calculateFootprintForPolicyDecision (footprint, footprintVideo);
247+ if (footprint >= thresholdForPolicy (MemoryUsagePolicy::StrictSynchronous, MemoryType::Normal) || footprintVideo >= thresholdForPolicy (MemoryUsagePolicy::StrictSynchronous, MemoryType::Video))
248+ return MemoryUsagePolicy::StrictSynchronous;
239249 if (footprint >= thresholdForPolicy (MemoryUsagePolicy::Strict, MemoryType::Normal) || footprintVideo >= thresholdForPolicy (MemoryUsagePolicy::Strict, MemoryType::Video))
240250 return MemoryUsagePolicy::Strict;
241251 if (footprint >= thresholdForPolicy (MemoryUsagePolicy::Conservative, MemoryType::Normal) || footprintVideo >= thresholdForPolicy (MemoryUsagePolicy::Conservative, MemoryType::Video))
242252 return MemoryUsagePolicy::Conservative;
243253 return MemoryUsagePolicy::Unrestricted;
244254}
245255
256+ size_t MemoryPressureHandler::calculateFootprintForPolicyDecision (size_t footprint, size_t footprintVideo)
257+ {
258+ // Some devices accounts video memory into the process memory footprint (as file mappings - RSSFile).
259+ // In such cases, we need to subtract the video memory from the process memory footprint
260+ // to make the memory pressure policy decision based on the process memory footprint only.
261+ if (s_videoMemoryInFootprint)
262+ footprint -= footprintVideo;
263+ return footprint;
264+ }
265+
246266MemoryUsagePolicy MemoryPressureHandler::currentMemoryUsagePolicy ()
247267{
248268 return policyForFootprints (memoryFootprint (), memoryFootprintVideo ());
@@ -305,15 +325,15 @@ void MemoryPressureHandler::measurementTimerFired()
305325 releaseMemory (Critical::No, Synchronous::No);
306326 break ;
307327 case MemoryUsagePolicy::Strict:
308- if (footprint > m_configuration.baseThreshold || footprintVideo > m_configuration.baseThresholdVideo ) {
309- WTFLogAlways (" MemoryPressure: Critical memory usage (PID=%d) [MB]: %zu (of %zu), video: %zu (of %zu)\n " ,
310- getpid (), footprint / MB, m_configuration.baseThreshold / MB,
311- footprintVideo / MB, m_configuration.baseThresholdVideo / MB);
312- releaseMemory (Critical::Yes, Synchronous::Yes);
313- break ;
314- }
315328 releaseMemory (Critical::Yes, Synchronous::No);
316329 break ;
330+ case MemoryUsagePolicy::StrictSynchronous:
331+ WTFLogAlways (" MemoryPressure: Critical memory usage (PID=%d) [MB]: %zu%s/%zu, video: %zu/%zu\n " ,
332+ getpid (),
333+ footprint / MB, s_videoMemoryInFootprint ? " (including video)" : " " , m_configuration.baseThreshold / MB,
334+ footprintVideo / MB, m_configuration.baseThresholdVideo / MB);
335+ releaseMemory (Critical::Yes, Synchronous::Yes);
336+ break ;
317337 }
318338
319339 if (processState () == WebsamProcessState::Active && footprint > thresholdForMemoryKillOfInactiveProcess (m_pageCount))
0 commit comments