From a0b096c88421548593ecebe93bbe369385087f3b Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Sat, 15 Apr 2023 13:39:02 +0200 Subject: [NetBSD] virtual_memory() metrics are completely wrong (#2235), fixes #2234 Match values shown by **htop**. This is before. In here: * available mem is almost the same as total (unrealistic) * used is higher than total; there's also a failing test: ``` MEMORY ------ Total : 972.7M Available : 959.1M Percent : 1.4 Used : 1.1G Free : 173.6M Active : 434.3M Inactive : 258.4M Buffers : 509.4M Cached : 692.9M Shared : 0.0B Wired : 280.0K ``` Now: ``` MEMORY ------ Total : 972.7M Available : 538.1M Percent : 44.7 Used : 434.5M Free : 173.6M Active : 434.2M Inactive : 258.4M Buffers : 509.4M Cached : 692.9M Shared : 0.0B Wired : 280.0K ``` --- docs/index.rst | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'docs') diff --git a/docs/index.rst b/docs/index.rst index dfca444d..2a1c5b6a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -334,18 +334,20 @@ Memory .. function:: virtual_memory() Return statistics about system memory usage as a named tuple including the - following fields, expressed in bytes. Main metrics: + following fields, expressed in bytes. + + Main metrics: - **total**: total physical memory (exclusive swap). - **available**: the memory that can be given instantly to processes without the system going into swap. - This is calculated by summing different memory values depending on the - platform and it is supposed to be used to monitor actual memory usage in a - cross platform fashion. + This is calculated by summing different memory metrics that vary depending + on the platform. It is supposed to be used to monitor actual memory usage + in a cross platform fashion. + - **percent**: the percentage usage calculated as ``(total - available) / total * 100``. Other metrics: - - **percent**: the percentage usage calculated as ``(total - available) / total * 100`` - **used**: memory used, calculated differently depending on the platform and designed for informational purposes only. **total - free** does not necessarily match **used**. @@ -370,7 +372,8 @@ Memory human readable form. .. note:: if you just want to know how much physical memory is left in a - cross platform fashion simply rely on the **available** field. + cross platform fashion simply rely on **available** and **percent** + fields. >>> import psutil >>> mem = psutil.virtual_memory() -- cgit v1.2.1