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

Checks on virtual_memory() and swap_memory() values #862

Closed
dmedri opened this issue Jul 17, 2016 · 4 comments
Closed

Checks on virtual_memory() and swap_memory() values #862

dmedri opened this issue Jul 17, 2016 · 4 comments

Comments

@dmedri
Copy link

dmedri commented Jul 17, 2016

On Linux (fedora23, i686), running psutil.cpu_memory() and free (on Py3), the results are wrong:

>>> psutil.virtual_memory()
svmem(total=2103410688, available=1315647488, percent=37.5, used=2044448768,
free=58961920, active=958812160, inactive=962322432, buffers=77824, cached=1256607744)

>>> psutil.swap_memory()
sswap(total=2148528128, used=48975872, free=2099552256, percent=2.3, sin=49152,
sout=48984064)

in console, results are differents:

> free
              total        used        free      shared  buff/cache   available
Mem:        2054112      682720       55752      190224     1315640     1132484
Swap:       2098172       47828     2050344

Let me know how can I run some tests to help you.

@giampaolo
Copy link
Owner

Some values of free and psutil.virtual_memory() refer to different things and cannot be compared.
E.g. used and available are calculated differently.
Secondly, psutil returns results in bytes. In order for free to do the same you should do free -b.

@dmedri
Copy link
Author

dmedri commented Jul 18, 2016

Ok, second try:

>>> psutil.virtual_memory()
svmem(total=2103410688, available=1310154752, percent=37.7, used=2012487680,
free=90923008, active=908922880, inactive=971247616, buffers=28672, cached=1219203072)

>>> psutil.swap_memory()
sswap(total=2148528128, used=38989824, free=2109538304, percent=1.8, sin=217088,
sout=39026688)

and free -b results:

$ free -b
              total        used        free      shared  buff/cache   available
Mem:     2103410688   703737856    76132352   182116352  1323540480  1166770176
Swap:    2148528128    38989824  2109538304

Please, sync your method with the 'free' developers for a final resolution.

@giampaolo
Copy link
Owner

giampaolo commented Sep 10, 2016

Update about this: I updated Linux tests and with Ubuntu 16.04 free column of "free" cmdline utility matches psutil. I suspect there are "free" versions where this is different, see:
#685 (comment)
Anyway, I checked the output of vmstat -s and the two values (vmstat and psutil) matches so I think "free" value is fine.

What is not fine is "used" value.
Both vmstat and free CLI tools report different numbers but I'm not sure how they calculate that. I'll have to take a peek at the source code.

@giampaolo
Copy link
Owner

Fixed in #887

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

No branches or pull requests

2 participants