Log cgroup RAM limits

This commit is contained in:
Henry Mercer 2023-09-18 12:43:52 +01:00
parent 253d9cf358
commit 379f89dc53
12 changed files with 32 additions and 19 deletions

11
lib/util.js generated
View file

@ -152,7 +152,7 @@ exports.getMemoryFlagValueForPlatform = getMemoryFlagValueForPlatform;
* Get the total amount of memory available to the Action, taking into account constraints imposed
* by cgroups on Linux.
*/
function getTotalMemoryAvailable() {
function getTotalMemoryAvailable(logger) {
if (os.platform() === "linux") {
// Respect constraints imposed by Linux cgroups v1 and v2
for (const limitFile of [
@ -162,6 +162,7 @@ function getTotalMemoryAvailable() {
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;
}
}
@ -176,8 +177,8 @@ function getTotalMemoryAvailable() {
*
* @returns {number} the amount of RAM to use, in megabytes
*/
function getMemoryFlagValue(userInput) {
return getMemoryFlagValueForPlatform(userInput, getTotalMemoryAvailable(), process.platform);
function getMemoryFlagValue(userInput, logger) {
return getMemoryFlagValueForPlatform(userInput, getTotalMemoryAvailable(logger), process.platform);
}
exports.getMemoryFlagValue = getMemoryFlagValue;
/**
@ -187,8 +188,8 @@ exports.getMemoryFlagValue = getMemoryFlagValue;
*
* @returns string
*/
function getMemoryFlag(userInput) {
const megabytes = getMemoryFlagValue(userInput);
function getMemoryFlag(userInput, logger) {
const megabytes = getMemoryFlagValue(userInput, logger);
return `--ram=${megabytes}`;
}
exports.getMemoryFlag = getMemoryFlag;