Skip to content

Commit 03ad702

Browse files
server: Set free memory to zero if greater than total memory (#4571)
Fixes #4566 Sets `memoryintfreekbs` to zero if it is greater than `memorykbs`. Caused by KVM returning the RSS memory of the process running the VM rather than the free memory inside the VM. Co-authored-by: dahn <daan.hoogland@gmail.com>
1 parent d6a7427 commit 03ad702

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/response/UserVmResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
209209
private Long memoryKBs;
210210

211211
@SerializedName("memoryintfreekbs")
212-
@Param(description = "the internal memory thats free in vm")
212+
@Param(description = "the internal memory that's free in vm or zero if it can not be calculated")
213213
private Long memoryIntFreeKBs;
214214

215215
@SerializedName("memorytargetkbs")

server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,11 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
222222
userVmResponse.setDiskKbsWrite((long)vmStats.getDiskWriteKBs());
223223
userVmResponse.setDiskIORead((long)vmStats.getDiskReadIOs());
224224
userVmResponse.setDiskIOWrite((long)vmStats.getDiskWriteIOs());
225-
userVmResponse.setMemoryKBs((long)vmStats.getMemoryKBs());
226-
userVmResponse.setMemoryIntFreeKBs((long)vmStats.getIntFreeMemoryKBs());
225+
long totalMemory = (long)vmStats.getMemoryKBs();
226+
long freeMemory = (long)vmStats.getIntFreeMemoryKBs();
227+
long correctedFreeMemory = freeMemory >= totalMemory ? 0 : freeMemory;
228+
userVmResponse.setMemoryKBs(totalMemory);
229+
userVmResponse.setMemoryIntFreeKBs(correctedFreeMemory);
227230
userVmResponse.setMemoryTargetKBs((long)vmStats.getTargetMemoryKBs());
228231

229232
}

0 commit comments

Comments
 (0)