kvm available memory calculation optimization (#5540)

* Update LibvirtComputingResource.java

* Update LibvirtComputingResource.java

* Update LibvirtComputingResource.java

re

* Update MemStat.java

* Update MemStat.java

* Update MemStatTest.java
This commit is contained in:
div8cn 2021-10-05 23:34:28 +08:00 committed by GitHub
parent cd4e7e031a
commit 52a9dbdcd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -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;
@ -55,7 +56,7 @@ public class MemStat {
}
public long getAvailable() {
return getFree() + getCache();
return getFree() + getCache() + getBuffer();
}
public long getFree() {
@ -66,6 +67,10 @@ public class MemStat {
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")) {

View File

@ -48,7 +48,7 @@ public class MemStatTest {
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);
}