Skip to content

Commit

Permalink
Handle mismatch between committed vs. used physical memory
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Oct 21, 2022
1 parent 55b588a commit b5551e3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,12 @@ def swap_memory():
# 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)
# commit total is incremented immediately (decrementing free_system)
# while the corresponding free physical value is not decremented until
# pages are accessed, so free_phys is an overestimate of the portion
# free_system contributed to by physical memory, and in some edge cases
# can exceed free system memory.
free = max(0, free_system - free_phys)
used = total - free
percent = usage_percent(used, total, round_=1)
return _common.sswap(total, used, free, percent, 0, 0)
Expand Down

0 comments on commit b5551e3

Please sign in to comment.