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
17
src/util.ts
17
src/util.ts
|
|
@ -211,6 +211,21 @@ export function getMemoryFlagValueForPlatform(
|
|||
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.
|
||||
* 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 {
|
||||
return getMemoryFlagValueForPlatform(
|
||||
userInput,
|
||||
os.totalmem(),
|
||||
getTotalMemoryAvailable(),
|
||||
process.platform,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue