diff options
author | Googler <noreply@google.com> | 2017-10-16 20:59:27 +0200 |
---|---|---|
committer | Jakob Buchgraber <buchgr@google.com> | 2017-10-18 10:27:51 +0200 |
commit | 0faf1710a4bb12e748e70d4bf445bdf16dfc9a7d (patch) | |
tree | 2af30d1f5fea2505aeddddb34ae08a260b422cbb /src/main/java/com/google/devtools/build/lib/unix | |
parent | 1f61472985203b63d1ef2368c33a107a4497c677 (diff) |
Fall back to guessing available memory on Linux machines running kernels older than 3.14-rc1 (2014-02-02).
RELNOTES: N/A
PiperOrigin-RevId: 172356826
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/unix')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/unix/ProcMeminfoParser.java | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/unix/ProcMeminfoParser.java b/src/main/java/com/google/devtools/build/lib/unix/ProcMeminfoParser.java index 3c8baab489..a022fe8997 100644 --- a/src/main/java/com/google/devtools/build/lib/unix/ProcMeminfoParser.java +++ b/src/main/java/com/google/devtools/build/lib/unix/ProcMeminfoParser.java @@ -89,7 +89,17 @@ public class ProcMeminfoParser { * line in /proc/meminfo. */ public long getFreeRamKb() throws KeywordNotFoundException { - return getRamKb("MemAvailable"); + if (memInfo.containsKey("MemAvailable")) { + return getRamKb("MemAvailable"); + } + // We have no MemAvailable in /proc/meminfo; fall back to the previous estimation. + return getRamKb("MemTotal") + - getRamKb("Active") + // Blaze doesn't want to use more than a third of inactive ram... + - (long) (getRamKb("Inactive") * 0.3) + // ...and doesn't want to assume more than 80% of the slab memory can be reallocated. + - (long) (getRamKb("Slab") * 0.8); + // That said, this estimate will be more inaccurate as it diverges from kernel internals. } /** Exception thrown when /proc/meminfo does not have a requested key. Should be tolerated. */ |