Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] psutil.swap_memory() shows committed memory instead of swap #1921

Closed
TishSerg opened this issue Feb 23, 2021 · 1 comment · Fixed by #1927
Closed

[Windows] psutil.swap_memory() shows committed memory instead of swap #1921

TishSerg opened this issue Feb 23, 2021 · 1 comment · Fixed by #1927

Comments

@TishSerg
Copy link

Summary

  • OS: Microsoft Windows [Version 10.0.18363.1379]
  • Architecture: AMD64
  • Psutil version: 5.8.0
  • Python version: 3.8.6
  • Type: core

Description

python3.8 -c "import psutil; print(psutil.swap_memory())" shows committed memory (physical memory + pagefile/swap). On FreeBSD, it shows swap only as it should be. I believe on Windows it should show swap-only numbers too (psutil is portable, right?).

@dbwiddis
Copy link
Contributor

On Windows, psutil uses the fields ullTotalPageFile and ullAvailPageFile from MEMORYSTATUSEX but the docs imply those values are associated with the commit limit. To correct using the existing structure, the ullTotalPhys and ullAvailPhys values, respectively, should be subtracted to get swap file usage.

However, MEMORYSTATUSEX only gives a process-level view of memory:

The current committed memory limit for the system or the current process, whichever is smaller, in bytes. To get the system-wide committed memory limit, call GetPerformanceInfo.

This will return a PERFORMANCE_INFORMATION structure. CommitLimit - PhysicalTotal is swap total, and (CommitLimit - CommitTotal) - PhysicalAvailable is swap available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants