Skip to content

Commit 52a9dbd

Browse files
authored
kvm available memory calculation optimization (apache#5540)
* Update LibvirtComputingResource.java * Update LibvirtComputingResource.java * Update LibvirtComputingResource.java re * Update MemStat.java * Update MemStat.java * Update MemStatTest.java
1 parent cd4e7e0 commit 52a9dbd

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

  • plugins/hypervisors/kvm/src

‎plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/MemStat.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class MemStat {
3535
protected final static String FREE_KEY = "MemFree";
3636
protected final static String CACHE_KEY = "Cached";
3737
protected final static String TOTAL_KEY = "MemTotal";
38+
protected final static String BUFFER_KEY = "Buffers";
3839
long reservedMemory;
3940
long overCommitMemory;
4041

@@ -55,7 +56,7 @@ public long getTotal() {
5556
}
5657

5758
public long getAvailable() {
58-
return getFree() + getCache();
59+
return getFree() + getCache() + getBuffer();
5960
}
6061

6162
public long getFree() {
@@ -66,6 +67,10 @@ public long getCache() {
6667
return _memStats.get(CACHE_KEY);
6768
}
6869

70+
public long getBuffer() {
71+
return _memStats.get(BUFFER_KEY);
72+
}
73+
6974
public void refresh() {
7075
File f = new File(MEMINFO_FILE);
7176
try (Scanner scanner = new Scanner(f,"UTF-8")) {

‎plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/utils/linux/MemStatTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void getMemInfoParseTest() {
4848
MemStat memStat = new MemStat();
4949

5050
Assert.assertEquals(memStat.getTotal(), 5970161664L);
51-
Assert.assertEquals(memStat.getAvailable(), 2829840384L);
51+
Assert.assertEquals(memStat.getAvailable(), 3164520448L);
5252
Assert.assertEquals(memStat.getFree(), 160514048L);
5353
Assert.assertEquals(memStat.getCache(), 2669326336L);
5454
}

0 commit comments

Comments
 (0)