server: Set free memory to zero if greater than total memory (#4571)

Fixes https://github.com/apache/cloudstack/issues/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>
This commit is contained in:
davidjumani 2021-03-30 14:05:46 +05:30 committed by GitHub
parent d6a74272a4
commit 03ad702c1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -209,7 +209,7 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
private Long memoryKBs;
@SerializedName("memoryintfreekbs")
@Param(description = "the internal memory thats free in vm")
@Param(description = "the internal memory that's free in vm or zero if it can not be calculated")
private Long memoryIntFreeKBs;
@SerializedName("memorytargetkbs")

View File

@ -222,8 +222,11 @@ public class UserVmJoinDaoImpl extends GenericDaoBaseWithTagInformation<UserVmJo
userVmResponse.setDiskKbsWrite((long)vmStats.getDiskWriteKBs());
userVmResponse.setDiskIORead((long)vmStats.getDiskReadIOs());
userVmResponse.setDiskIOWrite((long)vmStats.getDiskWriteIOs());
userVmResponse.setMemoryKBs((long)vmStats.getMemoryKBs());
userVmResponse.setMemoryIntFreeKBs((long)vmStats.getIntFreeMemoryKBs());
long totalMemory = (long)vmStats.getMemoryKBs();
long freeMemory = (long)vmStats.getIntFreeMemoryKBs();
long correctedFreeMemory = freeMemory >= totalMemory ? 0 : freeMemory;
userVmResponse.setMemoryKBs(totalMemory);
userVmResponse.setMemoryIntFreeKBs(correctedFreeMemory);
userVmResponse.setMemoryTargetKBs((long)vmStats.getTargetMemoryKBs());
}