summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Knaack <davidkna@users.noreply.github.com>2021-04-08 11:30:33 +0200
committerGitHub <noreply@github.com>2021-04-08 11:30:33 +0200
commit93e1c468ab4ac7922472114b3aeeacda2c8676a1 (patch)
treec3edc87e37995caba523ce3de6f9caf687d7ba7d
parentb035d1f8f3bd4cea7a0a7817c21ef161f2bb2fd7 (diff)
downloadpsutil-93e1c468ab4ac7922472114b3aeeacda2c8676a1.tar.gz
[Windows] psutil.swap_memory() show swap instead of committed memory (#1927)
Signed-off-by: David Knaack <davidkna@users.noreply.github.com>
-rw-r--r--CREDITS4
-rw-r--r--HISTORY.rst1
-rw-r--r--psutil/_pswindows.py12
3 files changed, 15 insertions, 2 deletions
diff --git a/CREDITS b/CREDITS
index 360688bd..3f388854 100644
--- a/CREDITS
+++ b/CREDITS
@@ -740,3 +740,7 @@ I: 1851
N: guille
W: https://github.com/guille
I: 1913
+
+N: David Knaack
+W: https://github.com/davidkna
+I: 1921
diff --git a/HISTORY.rst b/HISTORY.rst
index b42261ab..c826f47b 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -22,6 +22,7 @@ XXXX-XX-XX
called after sprintf(). (patch by alxchk)
- 1874_: [Solaris] swap output error due to incorrect range.
- 1913_: [Linux] wait_procs seemingly ignoring timeout, TimeoutExpired thrown
+- 1921_: [Windows] psutil.swap_memory() shows committed memory instead of swap
5.8.0
=====
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py
index 0ad60c4a..6b1a34de 100644
--- a/psutil/_pswindows.py
+++ b/psutil/_pswindows.py
@@ -241,8 +241,16 @@ def virtual_memory():
def swap_memory():
"""Swap system memory as a (total, used, free, sin, sout) tuple."""
mem = cext.virtual_mem()
- total = mem[2]
- free = mem[3]
+
+ total_phys = mem[0]
+ free_phys = mem[1]
+ 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 substracted to get swap values
+ total = total_system - total_phys
+ free = min(total, free_system - free_phys)
used = total - free
percent = usage_percent(used, total, round_=1)
return _common.sswap(total, used, free, percent, 0, 0)