Skip to content

Commit cada9f9

Browse files
committed
MemoryPressure: Add WPE_RAM_SIZE env var to define a custom RAM size
1 parent aa7a1e0 commit cada9f9

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Source/WTF/wtf/RAMSize.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include "config.h"
2727
#include <wtf/RAMSize.h>
28+
#include <wtf/text/StringToIntegerConversion.h>
29+
#include <wtf/text/WTFString.h>
2830

2931
#include <mutex>
3032

@@ -50,8 +52,35 @@ namespace WTF {
5052
static constexpr size_t ramSizeGuess = 512 * MB;
5153
#endif
5254

55+
static size_t customRAMSize()
56+
{
57+
// Syntax: Case insensitive, unit multipliers (M=Mb, K=Kb, <empty>=bytes).
58+
// Example: WPE_RAM_SIZE='500M'
59+
60+
size_t customSize = 0;
61+
62+
String s = String::fromLatin1(getenv("WPE_RAM_SIZE"));
63+
if (!s.isEmpty()) {
64+
String value = s.convertToLowercaseWithoutLocale();
65+
size_t units = 1;
66+
if (value.endsWith('k'))
67+
units = KB;
68+
else if (value.endsWith('m'))
69+
units = MB;
70+
if (units != 1)
71+
value = value.substring(0, value.length() - 1);
72+
customSize = parseInteger<uint64_t>(value).value_or(0) * units;
73+
}
74+
75+
return customSize;
76+
}
77+
5378
static size_t computeRAMSize()
5479
{
80+
size_t custom = customRAMSize();
81+
if (custom)
82+
return custom;
83+
5584
#if OS(WINDOWS)
5685
MEMORYSTATUSEX status;
5786
status.dwLength = sizeof(status);

0 commit comments

Comments
 (0)