Skip to content

Commit 2162d24

Browse files
[MemoryPressureHandler] Subtract GPU memory from RSS when deciding memory policy
On Mali GPU drivers GPU memory is also included in process RSS mem (RSSFile) that cause pressure handler to kick in too early comparing to other devices. GPU memory doesn't increase container's total mem usage in cgroups so this change doesn't affect total memory allowance but delays pressure handler only.
1 parent 7f53149 commit 2162d24

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

Source/WTF/wtf/MemoryPressureHandler.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static const Seconds s_pollInterval = 30_s;
5454
// platform component. It's a text file containing an unsigned integer value.
5555
static String s_GPUMemoryFile;
5656
static ssize_t s_envBaseThresholdVideo = 0;
57+
static bool s_videoMemoryInFootprint = false;
5758

5859
static 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

238242
MemoryUsagePolicy 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+
249264
MemoryUsagePolicy 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;

Source/WTF/wtf/MemoryPressureHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ class MemoryPressureHandler {
244244
std::optional<size_t> thresholdForMemoryKill(MemoryType);
245245
size_t thresholdForPolicy(MemoryUsagePolicy, MemoryType);
246246
MemoryUsagePolicy policyForFootprints(size_t, size_t);
247+
size_t calculateFootprintForPolicyDecision(size_t footprint, size_t footprintVideo);
247248

248249
void memoryPressureStatusChanged();
249250

0 commit comments

Comments
 (0)