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

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

Comments

Projects
None yet
2 participants
@dmedri

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

This comment has been minimized.

Show comment
Hide comment
@giampaolo

giampaolo Jul 17, 2016

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.

Owner

giampaolo commented Jul 17, 2016

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

This comment has been minimized.

Show comment
Hide comment
@dmedri

dmedri 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.

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

This comment has been minimized.

Show comment
Hide comment
@giampaolo

giampaolo Sep 10, 2016

Owner

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.

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

This comment has been minimized.

Show comment
Hide comment
@giampaolo

giampaolo Sep 18, 2016

Owner

Fixed in #887

Owner

giampaolo commented Sep 18, 2016

Fixed in #887

@giampaolo giampaolo closed this Sep 18, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment