Skip to content

Commit 4a73d89

Browse files
asurdej-comcastmagomez
authored andcommitted
MemoryPressure: substract 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 0b081ab commit 4a73d89

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
@@ -58,6 +58,7 @@ static std::atomic<bool> s_hasCreatedMemoryPressureHandler;
5858
// platform component. It's a text file containing an unsigned integer value.
5959
static String s_GPUMemoryFile;
6060
static ssize_t s_envBaseThresholdVideo = 0;
61+
static bool s_videoMemoryInFootprint = false;
6162

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

247251
MemoryUsagePolicy 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+
258273
MemoryUsagePolicy 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;

Source/WTF/wtf/MemoryPressureHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class MemoryPressureHandler {
228228
std::optional<size_t> thresholdForMemoryKill(MemoryType);
229229
size_t thresholdForPolicy(MemoryUsagePolicy, MemoryType);
230230
MemoryUsagePolicy policyForFootprints(size_t, size_t);
231+
size_t calculateFootprintForPolicyDecision(size_t footprint, size_t footprintVideo);
231232

232233
void memoryPressureStatusChanged();
233234

0 commit comments

Comments
 (0)