Respect scaling_reserved_ram feature flag
The amount of RAM given to the CodeQL evaluator is the machine's total memory size, minus a reserved amount. Currently, the reserved amount is fixed at 1 GB (or 1.5 GB on Windows). When the scaling_reserved_ram feature flag is enabled, we also add 2% of the total memory size to the reserved amount. This allows for the fact that the kernel will consume more RAM (e.g. for page tables) on machines with more physical RAM.
This commit is contained in:
parent
85c77f1dfc
commit
f232722edf
15 changed files with 116 additions and 45 deletions
22
lib/util.js
generated
22
lib/util.js
generated
|
|
@ -108,9 +108,18 @@ exports.withTmpDir = withTmpDir;
|
|||
* from committing too much of the available memory to CodeQL.
|
||||
* @returns number
|
||||
*/
|
||||
function getSystemReservedMemoryMegaBytes() {
|
||||
async function getSystemReservedMemoryMegaBytes(totalMemoryMegaBytes, features) {
|
||||
// Windows needs more memory for OS processes.
|
||||
return 1024 * (process.platform === "win32" ? 1.5 : 1);
|
||||
const fixedAmount = 1024 * (process.platform === "win32" ? 1.5 : 1);
|
||||
if (await features.getValue(feature_flags_1.Feature.ScalingReservedRam)) {
|
||||
// Reserve an additional 2% of the total memory, since the amount used by
|
||||
// the kernel for page tables scales with the size of physical memory.
|
||||
const scaledAmount = 0.02 * totalMemoryMegaBytes;
|
||||
return fixedAmount + scaledAmount;
|
||||
}
|
||||
else {
|
||||
return fixedAmount;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the value of the codeql `--ram` flag as configured by the `ram` input.
|
||||
|
|
@ -119,7 +128,7 @@ function getSystemReservedMemoryMegaBytes() {
|
|||
*
|
||||
* @returns {number} the amount of RAM to use, in megabytes
|
||||
*/
|
||||
function getMemoryFlagValue(userInput) {
|
||||
async function getMemoryFlagValue(userInput, features) {
|
||||
let memoryToUseMegaBytes;
|
||||
if (userInput) {
|
||||
memoryToUseMegaBytes = Number(userInput);
|
||||
|
|
@ -130,7 +139,7 @@ function getMemoryFlagValue(userInput) {
|
|||
else {
|
||||
const totalMemoryBytes = os.totalmem();
|
||||
const totalMemoryMegaBytes = totalMemoryBytes / (1024 * 1024);
|
||||
const reservedMemoryMegaBytes = getSystemReservedMemoryMegaBytes();
|
||||
const reservedMemoryMegaBytes = await getSystemReservedMemoryMegaBytes(totalMemoryMegaBytes, features);
|
||||
memoryToUseMegaBytes = totalMemoryMegaBytes - reservedMemoryMegaBytes;
|
||||
}
|
||||
return Math.floor(memoryToUseMegaBytes);
|
||||
|
|
@ -143,8 +152,9 @@ exports.getMemoryFlagValue = getMemoryFlagValue;
|
|||
*
|
||||
* @returns string
|
||||
*/
|
||||
function getMemoryFlag(userInput) {
|
||||
return `--ram=${getMemoryFlagValue(userInput)}`;
|
||||
async function getMemoryFlag(userInput, features) {
|
||||
const megabytes = await getMemoryFlagValue(userInput, features);
|
||||
return `--ram=${megabytes}`;
|
||||
}
|
||||
exports.getMemoryFlag = getMemoryFlag;
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue