Skip to content

Commit c9e2f0d

Browse files
committed
[MemoryPressure] Add back the WPE_POLL_MAX_MEMORY_GPU env var that overwrites the limit set by the API
1 parent fe83369 commit c9e2f0d

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

Source/WTF/wtf/MemoryPressureHandler.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <wtf/MemoryFootprint.h>
3535
#include <wtf/NeverDestroyed.h>
3636
#include <wtf/RAMSize.h>
37+
#include <wtf/text/StringToIntegerConversion.h>
3738

3839
namespace WTF {
3940

@@ -120,9 +121,23 @@ MemoryPressureHandler::MemoryPressureHandler()
120121
#endif
121122

122123
// If this is the WebProcess, Check whether the env var WPE_POLL_MAX_MEMORY_GPU_FILE exists, containing the file
123-
// that we need to poll to get the video memory used.
124-
if (isWebProcess())
124+
// that we need to poll to get the video memory used, and whether WPE_POLL_MAX_MEMORY_GPU exists, overriding the
125+
// limit for video memory set by the API.
126+
if (isWebProcess()) {
125127
s_GPUMemoryFile = String::fromLatin1(getenv("WPE_POLL_MAX_MEMORY_GPU_FILE"));
128+
String s = String::fromLatin1(getenv("WPE_POLL_MAX_MEMORY_GPU"));
129+
if (!s.isEmpty()) {
130+
String value = s.stripWhiteSpace().convertToLowercaseWithoutLocale();
131+
size_t units = 1;
132+
if (value.endsWith('k'))
133+
units = KB;
134+
else if (value.endsWith('m'))
135+
units = MB;
136+
if (units != 1)
137+
value = value.substring(0, value.length() - 1);
138+
m_configuration.baseThresholdVideo = parseInteger<size_t>(value).value_or(0) * units;
139+
}
140+
}
126141
}
127142

128143
void MemoryPressureHandler::setShouldUsePeriodicMemoryMonitor(bool use)

0 commit comments

Comments
 (0)