Skip to content

Commit

Permalink
Formatting, credits, change log
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <widdis@gmail.com>
  • Loading branch information
dbwiddis committed Oct 20, 2022
1 parent 195b01d commit 066c4c1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -801,3 +801,7 @@ I: 2135

N: Daniel Li
I: 2150

N: Daniel Widdis
W: https://github.com/dbwiddis
I: 2077
10 changes: 10 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -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
=====

Expand Down
14 changes: 8 additions & 6 deletions psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,21 +612,23 @@ static PyObject *
psutil_virtual_mem(PyObject *self, PyObject *args) {
unsigned long long totalPhys, availPhys, totalSys, availSys, pageSize;
PERFORMANCE_INFORMATION perfInfo;

if (! GetPerformanceInfo(&perfInfo, sizeof(PERFORMANCE_INFORMATION))) {
PyErr_SetFromWindowsErr(0);
return NULL;
}
// values are size_t, widen to long long
// 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);
return Py_BuildValue(
"(LLLL)",
totalPhys,
availPhys,
totalSys,
availSys);
}


Expand Down
3 changes: 2 additions & 1 deletion psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ def swap_memory():
total_system = mem[2]
free_system = mem[3]

# physical memory values need to be substracted 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
Expand Down

0 comments on commit 066c4c1

Please sign in to comment.