Improve docs

This commit is contained in:
Henry Mercer 2023-09-15 18:17:13 +01:00
parent d6f9faae0d
commit d4c26876d3
3 changed files with 25 additions and 15 deletions

17
lib/util.js generated
View file

@ -149,14 +149,19 @@ function getMemoryFlagValueForPlatform(userInput, totalMemoryBytes, platform) {
} }
exports.getMemoryFlagValueForPlatform = getMemoryFlagValueForPlatform; exports.getMemoryFlagValueForPlatform = getMemoryFlagValueForPlatform;
/** /**
* Get the total amount of memory available to the Action. * Get the total amount of memory available to the Action, taking into account constraints imposed
* by cgroups on Linux.
*/ */
function getTotalMemoryAvailable() { function getTotalMemoryAvailable() {
if (fs.existsSync("/sys/fs/cgroup/memory/memory.limit_in_bytes")) { if (os.platform() === "linux") {
return Number(fs.readFileSync("/sys/fs/cgroup/memory/memory.limit_in_bytes", "utf8")); // Respect constraints imposed by Linux cgroups v1
} if (fs.existsSync("/sys/fs/cgroup/memory/memory.limit_in_bytes")) {
if (fs.existsSync("/sys/fs/cgroup/memory.max")) { return Number(fs.readFileSync("/sys/fs/cgroup/memory/memory.limit_in_bytes", "utf8"));
return Number(fs.readFileSync("/sys/fs/cgroup/memory.max", "utf8")); }
// Respect constraints imposed by Linux cgroups v2
if (fs.existsSync("/sys/fs/cgroup/memory.max")) {
return Number(fs.readFileSync("/sys/fs/cgroup/memory.max", "utf8"));
}
} }
return os.totalmem(); return os.totalmem();
} }

File diff suppressed because one or more lines are too long

View file

@ -212,16 +212,21 @@ export function getMemoryFlagValueForPlatform(
} }
/** /**
* Get the total amount of memory available to the Action. * Get the total amount of memory available to the Action, taking into account constraints imposed
* by cgroups on Linux.
*/ */
function getTotalMemoryAvailable(): number { function getTotalMemoryAvailable(): number {
if (fs.existsSync("/sys/fs/cgroup/memory/memory.limit_in_bytes")) { if (os.platform() === "linux") {
return Number( // Respect constraints imposed by Linux cgroups v1
fs.readFileSync("/sys/fs/cgroup/memory/memory.limit_in_bytes", "utf8"), 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")); }
// Respect constraints imposed by Linux cgroups v2
if (fs.existsSync("/sys/fs/cgroup/memory.max")) {
return Number(fs.readFileSync("/sys/fs/cgroup/memory.max", "utf8"));
}
} }
return os.totalmem(); return os.totalmem();
} }