Handle cgroup file containing MAX_INT on ubuntu-20.04

This commit is contained in:
Henry Mercer 2023-09-18 13:41:50 +01:00
parent 379f89dc53
commit 0e74cd1660
3 changed files with 39 additions and 10 deletions

20
lib/util.js generated
View file

@ -153,6 +153,7 @@ exports.getMemoryFlagValueForPlatform = getMemoryFlagValueForPlatform;
* by cgroups on Linux.
*/
function getTotalMemoryAvailable(logger) {
const osTotalMemory = os.totalmem();
if (os.platform() === "linux") {
// Respect constraints imposed by Linux cgroups v1 and v2
for (const limitFile of [
@ -162,13 +163,26 @@ function getTotalMemoryAvailable(logger) {
if (fs.existsSync(limitFile)) {
const limit = Number(fs.readFileSync(limitFile, "utf8"));
if (Number.isInteger(limit)) {
logger.info(`While resolving RAM, found cgroup limit of ${limit / (1024 * 1024)} MiB in ${limitFile}.`);
return limit;
const displayLimit = `${Math.floor(limit / (1024 * 1024))} MiB`;
if (limit < osTotalMemory) {
logger.info(`While resolving RAM, found cgroup limit of ${displayLimit} in ${limitFile}.`);
return limit;
}
else {
logger.debug(`While resolving RAM, ignoring cgroup file ${limitFile} since the limit (${displayLimit}) ` +
"is greater than the total RAM reported by the operating system.");
}
}
else {
logger.debug(`While resolving RAM, ignoring cgroup file ${limitFile} as it does not contain an integer.`);
}
}
else {
logger.debug(`While resolving RAM, did not find cgroup constraints at ${limitFile}.`);
}
}
}
return os.totalmem();
return osTotalMemory;
}
/**
* Get the value of the codeql `--ram` flag as configured by the `ram` input.