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() {
|
function getTotalMemoryAvailable() {
|
||||||
if (os.platform() === "linux") {
|
if (os.platform() === "linux") {
|
||||||
// Respect constraints imposed by Linux cgroups v1
|
// Respect constraints imposed by Linux cgroups v1 and v2
|
||||||
if (fs.existsSync("/sys/fs/cgroup/memory/memory.limit_in_bytes")) {
|
for (const limitFile of [
|
||||||
return Number(fs.readFileSync("/sys/fs/cgroup/memory/memory.limit_in_bytes", "utf8"));
|
"/sys/fs/cgroup/memory/memory.limit_in_bytes",
|
||||||
}
|
"/sys/fs/cgroup/memory.max",
|
||||||
// Respect constraints imposed by Linux cgroups v2
|
]) {
|
||||||
if (fs.existsSync("/sys/fs/cgroup/memory.max")) {
|
if (fs.existsSync(limitFile)) {
|
||||||
return Number(fs.readFileSync("/sys/fs/cgroup/memory.max", "utf8"));
|
const limit = Number(fs.readFileSync(limitFile, "utf8"));
|
||||||
|
if (Number.isInteger(limit)) {
|
||||||
|
return limit;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return os.totalmem();
|
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 {
|
function getTotalMemoryAvailable(): number {
|
||||||
if (os.platform() === "linux") {
|
if (os.platform() === "linux") {
|
||||||
// Respect constraints imposed by Linux cgroups v1
|
// Respect constraints imposed by Linux cgroups v1 and v2
|
||||||
if (fs.existsSync("/sys/fs/cgroup/memory/memory.limit_in_bytes")) {
|
for (const limitFile of [
|
||||||
return Number(
|
"/sys/fs/cgroup/memory/memory.limit_in_bytes",
|
||||||
fs.readFileSync("/sys/fs/cgroup/memory/memory.limit_in_bytes", "utf8"),
|
"/sys/fs/cgroup/memory.max",
|
||||||
);
|
]) {
|
||||||
}
|
if (fs.existsSync(limitFile)) {
|
||||||
// Respect constraints imposed by Linux cgroups v2
|
const limit = Number(fs.readFileSync(limitFile, "utf8"));
|
||||||
if (fs.existsSync("/sys/fs/cgroup/memory.max")) {
|
if (Number.isInteger(limit)) {
|
||||||
return Number(fs.readFileSync("/sys/fs/cgroup/memory.max", "utf8"));
|
return limit;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return os.totalmem();
|
return os.totalmem();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue