Skip to content

Commit 6db4c0c

Browse files
tomasz-karczewski-redmagomez
authored andcommitted
bmalloc: check WPE_RAM_SIZE
WPE_RAM_SIZE env can be used to control the reported available total ram (WTF/wtf/RAMSize.cpp). Bmalloc is unaware of this setting, leading to discrepancy between the current memory pressure status as seen by bmalloc & reset of wpe, which makes bmalloc uneager to scavenge & return memory to the system on time.
1 parent c18bb63 commit 6db4c0c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Source/bmalloc/bmalloc/AvailableMemory.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,29 @@ struct LinuxMemory {
149149
};
150150
#endif
151151

152+
static size_t customRAMSize()
153+
{
154+
// Syntax: Case insensitive, unit multipliers (M=Mb, K=Kb, <empty>=bytes).
155+
// Example: WPE_RAM_SIZE='500M'
156+
157+
size_t customSize = 0;
158+
159+
const char *s = getenv("WPE_RAM_SIZE");
160+
if (s) {
161+
size_t len = strlen(s);
162+
size_t val = atoi(s);
163+
size_t units = 1;
164+
if (s[len-1] == 'k' || s[len-1] == 'K')
165+
units = 1024;
166+
else if (s[len-1] == 'm' || s[len-1] == 'M')
167+
units = 1024*1024;
168+
return units * val;
169+
}
170+
171+
return customSize;
172+
}
173+
174+
152175
static size_t computeAvailableMemory()
153176
{
154177
#if BOS(DARWIN)
@@ -162,6 +185,10 @@ static size_t computeAvailableMemory()
162185
// (for example) and we have code that depends on those boundaries.
163186
return ((sizeAccordingToKernel + multiple - 1) / multiple) * multiple;
164187
#elif BOS(FREEBSD) || BOS(LINUX)
188+
size_t customRamSize = customRAMSize();
189+
if (customRamSize) {
190+
return customRamSize;
191+
}
165192
struct sysinfo info;
166193
if (!sysinfo(&info))
167194
return info.totalram * info.mem_unit;

0 commit comments

Comments
 (0)