Psutil 存储值在数学上似乎不准确

Psutil storage values appear to be mathematically inaccurate

当我运行以下代码时:

import psutil
print(psutil.virtual_memory())

并收到以下输出;没有错误: svmem(total=8589934592, available=378863616, percent=95.6, used=893149184, free=18837504, active=363634688, inactive=352071680, wired=529514496)

我的 macOS Activity 监视器给我以下结果: MacOs Activity Monitor App Screenshot

我不明白的是:

谢谢!

used: memory used, calculated differently depending on the platform and designed for informational purposes only. total - free does not necessarily match used.

Note: if you just want to know how much physical memory is left in a cross platform fashion simply rely on the available field.

  • 缓冲区、缓存和共享内存值仅在 Linux 和 BSD 上测量。
  • 你实际上不能说 total - (used + free)。再次来自 documentations:

free: memory not being used at all (zeroed) that is readily available; note that this doesn’t reflect the actual memory available (use available instead). total - used does not necessarily match free.

由于Activity监视器不显示real-time中的值,因此Activity监视器中的Memory Used与[=12=之间仍然存在一些差异] 的 psutil.