Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class MemStat {
protected final static String FREE_KEY = "MemFree";
protected final static String CACHE_KEY = "Cached";
protected final static String TOTAL_KEY = "MemTotal";
protected final static String BUFFER_KEY = "Buffers";
long reservedMemory;
long overCommitMemory;

Expand All @@ -55,7 +56,7 @@ public long getTotal() {
}

public long getAvailable() {
return getFree() + getCache();
return getFree() + getCache() + getBuffer();
}

public long getFree() {
Expand All @@ -66,6 +67,10 @@ public long getCache() {
return _memStats.get(CACHE_KEY);
}

public long getBuffer() {
return _memStats.get(BUFFER_KEY);
}

public void refresh() {
File f = new File(MEMINFO_FILE);
try (Scanner scanner = new Scanner(f,"UTF-8")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void getMemInfoParseTest() {
MemStat memStat = new MemStat();

Assert.assertEquals(memStat.getTotal(), 5970161664L);
Assert.assertEquals(memStat.getAvailable(), 2829840384L);
Assert.assertEquals(memStat.getAvailable(), 3164520448L);
Assert.assertEquals(memStat.getFree(), 160514048L);
Assert.assertEquals(memStat.getCache(), 2669326336L);
}
Expand Down