[psutil] Memory naming confusing

37 views
Skip to first unread message

NoxDaFox

unread,
Mar 4, 2012, 2:50:04 PM3/4/12
to psu...@googlegroups.com
Greetings,

I used this library in a project and I found it really useful.
I found only a misinterpretation that led to a bug in my project: the virtual memory getter.
psutil.virtmem_usage()
In Linux it reports the swap space as said in the documentation.

The Virtual Memory usually refers to the memory management mechanism that allows a single process running in a multitasking OS  to see more memory than the one really available, it uses disk cache to help itself in this process.
So assigning such a name leads to misunderstandings as a developer assumes that virtmem means all the addresses space and not only the swap space.

May I suggest you something more clear?

psutil.totmem_usage() - physical + swap
psutil.phymem_usage() - physical
psutil.virtmem_usage() - swap or disk paging

Or even better:

psutil.mem_usage() - physical + swap
psutil.physical_usage() - physical
psutil.diskcache_usage() - swap or disk paging


Just a hint, good job anyway ;)

nox

Giampaolo Rodolà

unread,
Mar 5, 2012, 6:51:02 PM3/5/12
to psu...@googlegroups.com

When we first thought about how to deal with such kind of
memory-related questions (in details: what to provide and under what
names) I remember we had a pretty hard time.
Since the memory management is so different across platforms we
decided that the best thing to do was to use "free" cmdline utility as
a reference and try to adjust the other platforms in accordance with
it as best as possible.

That being so, I do agree "virtmem_usage" is probably a poor name and
we should have used "swapmem_usage" instead.
We might think about renaming it.

I'm not sure about providing a brand new totmem_usage() though.
That would merely be a function which makes a simple addition of both
physical and swap memory functions, adding further confusion to a
subject which is already controversial and twisted.
Also, it is not clear whether the sum should include
psutil.cached_phymem() and psutil.phymem_buffers() on Linux (that's
one of the reasons of this being controversial).


--- Giampaolo

Jay Loden

unread,
Mar 5, 2012, 7:00:21 PM3/5/12
to psu...@googlegroups.com
I don't recall why we originally did it as virtmem, though I recall thinking about it at the time. We could change it to swapmem_usage I guess, if it makes it clearer. 

I tend to agree though about not adding another function for total. This is sort of like the Linux memory usage confusion where many people want to know "real" memory usage (subtracting cache and buffer), and to me it's clearer and more consistent across all supported platforms by having just the basic methods and letting folks do any needed calculation in their code based on their intended usage and platform. 

-Jay

Giampaolo Rodolà

unread,
Mar 5, 2012, 7:38:33 PM3/5/12
to psu...@googlegroups.com

This is now being tracked here:
http://code.google.com/p/psutil/issues/detail?id=256

G.

Reply all
Reply to author
Forward
0 new messages