jaypipes/ghw

Windows: do not print correctly the unused memory value.(about issue#176)

zzustu opened this issue · 1 comments

Wrong
OS: Windows Server 2019 Datacenter
total memory: 12GB
unused memory: 7.5GB (≈7GB)
but ghw print unused=total

memory (12GB physical, 12GB usable)

review fix issue#176 WQL

SELECT TotalVisibleMemorySize FROM Win32_OperatingSystem

You should use FreePhysicalMemory instead of TotalVisibleMemorySize,
picture from Microsoft WMI API website: https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-operatingsystem

TotalVisibleMemorySize (Units "kilobytes")
TotalVisibleMemorySize

FreePhysicalMemory (Units "kilobytes")
FreePhysicalMemory

Hi @zzustu. You have some confusion about what the MemoryInfo.TotalUsableBytes contains.

From the documentation:

ghw.MemoryInfo.TotalUsableBytes contains the amount of memory the system can actually use. Usable memory accounts for things like the kernel's resident memory size and some reserved system bits

For Windows, the amount of win32_OperatingSystem.TotalVisibleMemorySize field is equal to the total amount of memory that the system has available to it to use, which is what ghw.MemoryInfo.TotalUsableBytes represents.

The ghw.MemoryInfo.TotalPhysicalBytes amount, on the other hand, is the total amount of physical memory (in DIMMs) attached to the hardware. In Linux, this can be determined by looking at syslog startup messages. In Windows, I will need to determine this value by summing the amount of the Win32_MemoryBank WMI table records. I have this on my roadmap to tackle. Hope to get to it in the next month. You can see here for more discussion on this topic:

#171 (comment)