Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Source/bmalloc/bmalloc/AvailableMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,29 @@ struct LinuxMemory {
};
#endif

static size_t customRAMSize()
{
// Syntax: Case insensitive, unit multipliers (M=Mb, K=Kb, <empty>=bytes).
// Example: WPE_RAM_SIZE='500M'

size_t customSize = 0;

const char *s = getenv("WPE_RAM_SIZE");
if (s) {
size_t len = strlen(s);
size_t val = atoi(s);
size_t units = 1;
if (s[len-1] == 'k' || s[len-1] == 'K')
units = 1024;
else if (s[len-1] == 'm' || s[len-1] == 'M')
units = 1024*1024;
return units * val;
}

return customSize;
}


static size_t computeAvailableMemory()
{
#if BOS(DARWIN)
Expand All @@ -162,6 +185,10 @@ static size_t computeAvailableMemory()
// (for example) and we have code that depends on those boundaries.
return ((sizeAccordingToKernel + multiple - 1) / multiple) * multiple;
#elif BOS(FREEBSD) || BOS(LINUX)
size_t customRamSize = customRAMSize();
if (customRamSize) {
return customRamSize;
}
struct sysinfo info;
if (!sysinfo(&info))
return info.totalram * info.mem_unit;
Expand Down