Handle files that exist but whose contents are not integers
This commit is contained in:
parent
d4c26876d3
commit
9bfb9ba527
3 changed files with 23 additions and 17 deletions
18
lib/util.js
generated
18
lib/util.js
generated
|
|
@ -154,13 +154,17 @@ exports.getMemoryFlagValueForPlatform = getMemoryFlagValueForPlatform;
|
|||
*/
|
||||
function getTotalMemoryAvailable() {
|
||||
if (os.platform() === "linux") {
|
||||
// Respect constraints imposed by Linux cgroups v1
|
||||
if (fs.existsSync("/sys/fs/cgroup/memory/memory.limit_in_bytes")) {
|
||||
return Number(fs.readFileSync("/sys/fs/cgroup/memory/memory.limit_in_bytes", "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"));
|
||||
// Respect constraints imposed by Linux cgroups v1 and v2
|
||||
for (const limitFile of [
|
||||
"/sys/fs/cgroup/memory/memory.limit_in_bytes",
|
||||
"/sys/fs/cgroup/memory.max",
|
||||
]) {
|
||||
if (fs.existsSync(limitFile)) {
|
||||
const limit = Number(fs.readFileSync(limitFile, "utf8"));
|
||||
if (Number.isInteger(limit)) {
|
||||
return limit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return os.totalmem();
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
20
src/util.ts
20
src/util.ts
|
|
@ -217,15 +217,17 @@ export function getMemoryFlagValueForPlatform(
|
|||
*/
|
||||
function getTotalMemoryAvailable(): number {
|
||||
if (os.platform() === "linux") {
|
||||
// Respect constraints imposed by Linux cgroups v1
|
||||
if (fs.existsSync("/sys/fs/cgroup/memory/memory.limit_in_bytes")) {
|
||||
return Number(
|
||||
fs.readFileSync("/sys/fs/cgroup/memory/memory.limit_in_bytes", "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"));
|
||||
// Respect constraints imposed by Linux cgroups v1 and v2
|
||||
for (const limitFile of [
|
||||
"/sys/fs/cgroup/memory/memory.limit_in_bytes",
|
||||
"/sys/fs/cgroup/memory.max",
|
||||
]) {
|
||||
if (fs.existsSync(limitFile)) {
|
||||
const limit = Number(fs.readFileSync(limitFile, "utf8"));
|
||||
if (Number.isInteger(limit)) {
|
||||
return limit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return os.totalmem();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue