Skip to content

System memory functions big refactoring #311

Closed
@giampaolo

Description

From g.rodola on July 24, 2012 19:14:54

As of now psutil provides 2 functions to extract system memory stats:

- phymem_usage()
- virtmem_usage()

...providing a (total, free, used, percent) namedtuple.

There are different problems with these 2 functions:

1 - first of all they are insufficient: it is necessary to provide 
platform-specific types of memory. For example, on BSD and OSX we have active, 
inactive, wired and cached memory, which are also important (note: top shows 
them). Same for Linux, where we have cached and buffers memory (free shows 
them). These stats are currently not exposed, except for "buffers" and "cached" 
on Linux, provided by two extra functions.

2 - on both UNIX and Windows there's a concept of 'free' and 'available' 
memory; as of right now we only provide 'free' but again, that's insufficient.
What really matters is the available memory: 
http://www.sevenforums.com/performance-maintenance/114504-diff-between-available-free-physical-memory.html
 ...and that's what need to be used to monitor actual memory usage in a cross 
platform fashion.

3 - virtmem_usage() is inconsistent: on Windows and BSD it returns information 
about virtual memory while on OSX and Linux return stats about the swap memory.


=== REFACTORING PROPOSAL === 
http://blog.zabbix.com/when-alexei-isnt-looking/#vm.memory.size 
http://www.zabbix.com/documentation/2.0/manual/appendix/items/vm.memory.size_params

http://www.zabbix.com/documentation/2.0/manual/appendix/items/supported_by_platform?s[]=swap
 The links above provide useful suggestions as to how we can organize memory 
functions in psutil, and that's what I've been doing in the memory branch: 
https://code.google.com/p/psutil/source/browse/#svn%2Fbranches%2Fmemory 
Basically we'd have two functions:

= psutil.virtual_memory() =

We'll have 5 fields available on all platforms:
- total
- available
- percent
- used
- free

...plus others (e.g. buffers, cached, wired, etc...) depending on what platform we're on.
Again, monitoring apps are interested in 'available' memory.

= psutil.swap_memory() =

It'll have 5 fields:

- total
- used
- free
- percent
- sin   (no. of bytes the system has swapped in from disk (cumulative))
- sout  (no. of bytes the system has swapped out from disk (cumulative))


=== FUNCTIONS NEED TO BE DEPRECATED ===

- phymem_usage()
- virtmem_usage()
- phymem_buffers()
- cached_phymem()

These can be deprecated in 0.6.0 and scheduled for removal in 1.0.0 or later.
Also we have:

- psutil.avail_phymem()
- psutil.used_phymem()
- psutil.total_virtmem()
- psutil.avail_virtmem()
- psutil.used_virtmem()

...which were were already deprecated in 0.3.0.
They also need to go away.

Original issue: http://code.google.com/p/psutil/issues/detail?id=311

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions