On 2009-Aug-24 23:26:26 +0100, "Dr. David Kirkby" <[email protected]> wrote: >Yes, I finally found it myself. I like this bit of code: [devel/sage-main/sage/misc/getusage.py extract removed]
I'm glad someone liked it - it made me feel somewhat ill :-)
>It would appear to me the code is attempting to read the 5th column of
>'top' which is marked 'SIZE'. I'm not sure if that is a very useful
>thing to get, as the number returned includes that memory that is shared
>with other processes.
It's intended to emulate the VmSize value in Linux's /proc/<pid>/status -
which is the process's virtual size.
> I would have thought the 6th column, which is the
>memory used by that process alone (i.e. resident size) was more useful.
Not really. RSS just measures the amount of physical memory currently
occupied by the process. AFAIK, it also includes shared memory. And
the main use I can see for get_memory_usage is to check for memory
leaks - which are more obvious in VSZ than RSS. Including shared memory
is irrelevant for this because it won't change. OTOH, leaked memory is
not used and therefore likely to be paged out and so not counted in RSS.
>The following bit of C code finds the memory used by process 1877 (I
>have hard-coded that for now, but I'll change it later). It reports data
>in bytes.
Using procfs is the correct solution. This code needs to be
conditionally embedded in Sage in a similar way to the Darwin code.
Having just done something similar for FreeBSD (still being tested
so no ticket yet), the approach is presumably:
Create solaris_memory_usage.c, solaris_memory_usage.h and
solaris_utilities.pyx to provide a Python solaris_virtual_size
function that calls the relevant procfs functions.
Patch sage/ext/gen_interpreters.py to include the above:
if UNAME[0] == "Solaris":
ext_modules.append(
Extension('sage.misc.solaris_utilities',
sources = ['sage/misc/solaris_memory_usage.c',
'sage/misc/solaris_utilities.pyx'],
depends = ['sage/misc/solaris_memory_usage.h']
)
--
Peter Jeremy
pgpkiYlGkZH8Z.pgp
Description: PGP signature
