Respect RAM constraints imposed by Linux cgroups
This commit is contained in:
parent
c459726691
commit
d6f9faae0d
3 changed files with 30 additions and 3 deletions
14
lib/util.js
generated
14
lib/util.js
generated
|
|
@ -148,6 +148,18 @@ function getMemoryFlagValueForPlatform(userInput, totalMemoryBytes, platform) {
|
||||||
return Math.floor(memoryToUseMegaBytes);
|
return Math.floor(memoryToUseMegaBytes);
|
||||||
}
|
}
|
||||||
exports.getMemoryFlagValueForPlatform = getMemoryFlagValueForPlatform;
|
exports.getMemoryFlagValueForPlatform = getMemoryFlagValueForPlatform;
|
||||||
|
/**
|
||||||
|
* Get the total amount of memory available to the Action.
|
||||||
|
*/
|
||||||
|
function getTotalMemoryAvailable() {
|
||||||
|
if (fs.existsSync("/sys/fs/cgroup/memory/memory.limit_in_bytes")) {
|
||||||
|
return Number(fs.readFileSync("/sys/fs/cgroup/memory/memory.limit_in_bytes", "utf8"));
|
||||||
|
}
|
||||||
|
if (fs.existsSync("/sys/fs/cgroup/memory.max")) {
|
||||||
|
return Number(fs.readFileSync("/sys/fs/cgroup/memory.max", "utf8"));
|
||||||
|
}
|
||||||
|
return os.totalmem();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Get the value of the codeql `--ram` flag as configured by the `ram` input.
|
* Get the value of the codeql `--ram` flag as configured by the `ram` input.
|
||||||
* If no value was specified, the total available memory will be used minus a
|
* If no value was specified, the total available memory will be used minus a
|
||||||
|
|
@ -156,7 +168,7 @@ exports.getMemoryFlagValueForPlatform = getMemoryFlagValueForPlatform;
|
||||||
* @returns {number} the amount of RAM to use, in megabytes
|
* @returns {number} the amount of RAM to use, in megabytes
|
||||||
*/
|
*/
|
||||||
function getMemoryFlagValue(userInput) {
|
function getMemoryFlagValue(userInput) {
|
||||||
return getMemoryFlagValueForPlatform(userInput, os.totalmem(), process.platform);
|
return getMemoryFlagValueForPlatform(userInput, getTotalMemoryAvailable(), process.platform);
|
||||||
}
|
}
|
||||||
exports.getMemoryFlagValue = getMemoryFlagValue;
|
exports.getMemoryFlagValue = getMemoryFlagValue;
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
17
src/util.ts
17
src/util.ts
|
|
@ -211,6 +211,21 @@ export function getMemoryFlagValueForPlatform(
|
||||||
return Math.floor(memoryToUseMegaBytes);
|
return Math.floor(memoryToUseMegaBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the total amount of memory available to the Action.
|
||||||
|
*/
|
||||||
|
function getTotalMemoryAvailable(): number {
|
||||||
|
if (fs.existsSync("/sys/fs/cgroup/memory/memory.limit_in_bytes")) {
|
||||||
|
return Number(
|
||||||
|
fs.readFileSync("/sys/fs/cgroup/memory/memory.limit_in_bytes", "utf8"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (fs.existsSync("/sys/fs/cgroup/memory.max")) {
|
||||||
|
return Number(fs.readFileSync("/sys/fs/cgroup/memory.max", "utf8"));
|
||||||
|
}
|
||||||
|
return os.totalmem();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of the codeql `--ram` flag as configured by the `ram` input.
|
* Get the value of the codeql `--ram` flag as configured by the `ram` input.
|
||||||
* If no value was specified, the total available memory will be used minus a
|
* If no value was specified, the total available memory will be used minus a
|
||||||
|
|
@ -221,7 +236,7 @@ export function getMemoryFlagValueForPlatform(
|
||||||
export function getMemoryFlagValue(userInput: string | undefined): number {
|
export function getMemoryFlagValue(userInput: string | undefined): number {
|
||||||
return getMemoryFlagValueForPlatform(
|
return getMemoryFlagValueForPlatform(
|
||||||
userInput,
|
userInput,
|
||||||
os.totalmem(),
|
getTotalMemoryAvailable(),
|
||||||
process.platform,
|
process.platform,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue