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.

max
  • 9,708
  • 15
  • 89
  • 144
  • 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`. – Daniel May 29 '15 at 23:50
  • I ran it again on other machines. The used memory matched the one from linux command. There might have been an os related bug. – max May 30 '15 at 19:21
  • 1
    I've just had a look at the documentation of psutil, and it's stated there, that `.active` is indeed OS dependent (UNIX). See https://pythonhosted.org/psutil/#memory – Daniel May 30 '15 at 20:21

0 Answers0