summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CREDITS4
-rw-r--r--HISTORY.rst10
-rw-r--r--psutil/_psutil_windows.c25
-rw-r--r--psutil/_pswindows.py6
4 files changed, 32 insertions, 13 deletions
diff --git a/CREDITS b/CREDITS
index 6f1b6e5b..29298ca3 100644
--- a/CREDITS
+++ b/CREDITS
@@ -801,3 +801,7 @@ I: 2135
N: Daniel Li
I: 2150
+
+N: Daniel Widdis
+W: https://github.com/dbwiddis
+I: 2077
diff --git a/HISTORY.rst b/HISTORY.rst
index e9833990..f0d0905d 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -1,5 +1,15 @@
*Bug tracker at https://github.com/giampaolo/psutil/issues*
+5.9.4 (IN DEVELOPMENT)
+======================
+
+XXXX-XX-XX
+
+**Bug fixes**
+
+- 2077_, [Windows]: Use system-level values for `virtual_memory()`. (patch by
+ Daniel Widdis)
+
5.9.3
=====
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index 83da3a26..6e51c449 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -610,20 +610,25 @@ psutil_proc_memory_uss(PyObject *self, PyObject *args) {
*/
static PyObject *
psutil_virtual_mem(PyObject *self, PyObject *args) {
- MEMORYSTATUSEX memInfo;
- memInfo.dwLength = sizeof(MEMORYSTATUSEX);
+ unsigned long long totalPhys, availPhys, totalSys, availSys, pageSize;
+ PERFORMANCE_INFORMATION perfInfo;
- if (! GlobalMemoryStatusEx(&memInfo)) {
+ if (! GetPerformanceInfo(&perfInfo, sizeof(PERFORMANCE_INFORMATION))) {
PyErr_SetFromWindowsErr(0);
return NULL;
}
- return Py_BuildValue("(LLLLLL)",
- memInfo.ullTotalPhys, // total
- memInfo.ullAvailPhys, // avail
- memInfo.ullTotalPageFile, // total page file
- memInfo.ullAvailPageFile, // avail page file
- memInfo.ullTotalVirtual, // total virtual
- memInfo.ullAvailVirtual); // avail virtual
+ // values are size_t, widen (if needed) to long long
+ pageSize = perfInfo.PageSize;
+ totalPhys = perfInfo.PhysicalTotal * pageSize;
+ availPhys = perfInfo.PhysicalAvailable * pageSize;
+ totalSys = perfInfo.CommitLimit * pageSize;
+ availSys = totalSys - perfInfo.CommitTotal * pageSize;
+ return Py_BuildValue(
+ "(LLLL)",
+ totalPhys,
+ availPhys,
+ totalSys,
+ availSys);
}
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py
index 7d882b77..b546f15d 100644
--- a/psutil/_pswindows.py
+++ b/psutil/_pswindows.py
@@ -229,7 +229,7 @@ def getpagesize():
def virtual_memory():
"""System virtual memory as a namedtuple."""
mem = cext.virtual_mem()
- totphys, availphys, totpagef, availpagef, totvirt, freevirt = mem
+ totphys, availphys, totsys, availsys = mem
#
total = totphys
avail = availphys
@@ -248,8 +248,8 @@ def swap_memory():
total_system = mem[2]
free_system = mem[3]
- # Despite the name PageFile refers to total system memory here
- # thus physical memory values need to be subtracted to get swap values
+ # system memory (commit total/limit) is the sum of physical and swap
+ # thus physical memory values need to be substracted to get swap values
total = total_system - total_phys
free = min(total, free_system - free_phys)
used = total - free