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

swap_memory is not in bytes on FreeBSD #1255

Closed
href opened this issue Mar 27, 2018 · 8 comments · Fixed by #1260
Closed

swap_memory is not in bytes on FreeBSD #1255

href opened this issue Mar 27, 2018 · 8 comments · Fixed by #1260

Comments

@href
Copy link
Contributor

href commented Mar 27, 2018

Running psutil.swap_memory on FreeBSD 10.3 I gives me the following output:

sswap(total=2097088, used=17347, free=2079741, percent=0.8, sin=53145, sout=76176)

Running swapinfo at the same time returns with the following output:

Device          1K-blocks     Used    Avail Capacity
/dev/gpt/swap0    4194304    34308  4159996     1%
/dev/gpt/swap1    4194304    35080  4159224     1%
Total             8388608    69388  8319220     1%

In other words, psutil thinks I got 2'097'088 bytes of swap, even though I actually have 8'388'608'000 bytes. Since the answer is off by a factor of almost exactly 4000, I assume that psutil doesn't really return bytes here.

Am I missing something? These values should be in bytes, right?

@giampaolo
Copy link
Owner

giampaolo commented Mar 27, 2018

Yes all values are supposed to be expressed in bytes.
This is how it's done on FreeBSD:
https://github.com/giampaolo/psutil/blob/master/psutil/arch/freebsd/specific.c#L501
The C type is an int, which indeed makes me think we're not dealing with bytes (int is too small).
I searched a bit and in here:
https://github.com/KDE/ksysguard/blob/master/ksysguardd/FreeBSD/Memory.c#L159
...they convert it as swap_total * pagesize / 1024.
I currently don't have a FreeBSD to test against (have to reinstall it on VirtualBox) and I'll be travelling to China on Saturday. Maybe you can try doing the change yourself, re-compile and test?

@href
Copy link
Contributor Author

href commented Mar 27, 2018

Sure. Not sure if I can get to it this week, but I don't mind tackling this.

@giampaolo
Copy link
Owner

Take a look at:
https://github.com/giampaolo/psutil/blob/master/DEVGUIDE.rst
There are also a bunch unit tests for this:
https://github.com/giampaolo/psutil/blob/master/psutil/tests/test_bsd.py#L451-L463
I suppose they never failed for me 'cause I never had a swap > 0.

@giampaolo
Copy link
Owner

Forget about it, it's for NetBSD. =)

@href
Copy link
Contributor Author

href commented Mar 29, 2018

I fixed it locally, hopefully I did this the right way. My C is way rusty ;)

@href
Copy link
Contributor Author

href commented Apr 3, 2018

Within what time frame can I expect a release of psutil with this fix in it?

@giampaolo
Copy link
Owner

It's out. Enjoy!

@href
Copy link
Contributor Author

href commented Apr 13, 2018

Awesome, thank you 🎉

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

Successfully merging a pull request may close this issue.

2 participants