Python psutil memory does not match linux command
Asked Answered
T

0

7

I want to know why psutil's virtual memory used or active do not match the value I get from the linux command 'free -m' What I want to know is the physical system memory used.

virtual_memory().total / 1024 / 1024 = 29741
virtual_memory().used / 1024 / 1024 = 7967
virtual_memory().active / 1024 / 1024 = 2259

              total        used        free      shared  buff/cache   available
Mem:          29741        1148       21773          16        6819       28322
Swap:             0           0           0

I'm guessing that virtual_memory().used returns physical mem + shared mem + cached mem but still, active memory should match 1148.

Tutankhamen answered 29/5, 2015 at 18:49 Comment(3)
You are correct, that virtual_memory().used includes buffers and cache. There are actually articles on the net on how to correctly interpret the output of the free command regarding that topic in general. To get the actually used RAM (without buffers etc.), use psutil.virtual_memory().total - psutil.virtual_memory().available.Poppy
I ran it again on other machines. The used memory matched the one from linux command. There might have been an os related bug.Tutankhamen
I've just had a look at the documentation of psutil, and it's stated there, that .active is indeed OS dependent (UNIX). See pythonhosted.org/psutil/#memoryPoppy

© 2022 - 2024 — McMap. All rights reserved.