diff options
author | 2017-10-05 02:07:54 +0200 | |
---|---|---|
committer | 2017-10-06 19:45:55 +0200 | |
commit | e7af2092ab8f75d314e272a686e9181130f3b22f (patch) | |
tree | 0018b52b5df8f427b3e02571d3bc8fab8dff884e /src/main/java/com/google/devtools | |
parent | 93b3e75598881e92914e356ff389cedb854561fc (diff) |
Rather than logging the amount of free physical memory on Linux systems, log the amount of *available* physical memory. This includes memory used as cache or buffer that will be evicted if an application requests memory, and is a much more realistic metric of utilization than free memory, which is usually <1% of memory available to the machine.
PiperOrigin-RevId: 171087122
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/unix/ProcMeminfoParser.java | 35 |
1 files changed, 5 insertions, 30 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 b1e245df0c..e7ea1035af 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 @@ -81,43 +81,18 @@ public class ProcMeminfoParser { } /** - * Return the inactive memory. - */ - public long getInactiveKb() { - return getRamKb("Inactive"); - } - - /** - * Return the active memory. - */ - public long getActiveKb() { - return getRamKb("Active"); - } - - /** - * Return the slab memory. - */ - public long getSlabKb() { - return getRamKb("Slab"); - } - - /** * Convert KB to MB. */ public static double kbToMb(long kb) { - return kb / 1E3; + return kb >> 10; } /** - * Calculates amount of free RAM from /proc/meminfo content by using - * MemTotal - (Active + 0.3*InActive + 0.8*Slab) formula. - * Assumption here is that we allow Blaze to use all memory except when - * used by active pages, 30% of the inactive pages (since they may become - * active at any time) and 80% of memory used by kernel slab heap (since we - * want to keep most of the slab heap in the memory but do not want it to - * consume all available free memory). + * Reads the amount of *available* memory as reported by the kernel. See https://goo.gl/ABn283 for + * why this is better than trying to figure it out ourselves. This corresponds to the MemAvailable + * line in /proc/meminfo. */ public long getFreeRamKb() { - return getTotalKb() - getActiveKb() - (long)(getInactiveKb() * 0.3) - (long)(getSlabKb() * 0.8); + return getRamKb("MemAvailable"); } } |