[aclug-L] Re: Determining memory usage by a user
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Tue, Jun 08, 2004 at 10:42:35AM -0500, Jonathan Hall wrote:
> If it is at all possible (I'm beginning to think it's not), I need to find a
> way to determine how much memory a specific user is using.
It is, but the trick is to first define what you mean by how much memory
a specific user is using.
The place to start is /proc. (See proc(5)). The statm file will be
most useful. From the manpage:
/proc/[number]/statm
Provides information about memory status in pages. The columns
are:
size total program size
resident resident set size
share shared pages
trs text (code)
drs data/stack
lrs library
dt dirty pages
I'm not sure exactly how those numbers tally with ps/top fields.
You can probably use a formula such as (size - share) to obtain what you
are after. Note that units may differ; you'll have to check on that. A
page is 4K on i386 systems. The /proc/[number]/stat file also has
fields that will probably interest you.
If you are interested in this for enforcement purposes, the ulimit /
setrlimit() features are probably what you want. They let the kernel do
the calculating for you.
-- John
>
> My first thought was to add the values of the VSZ or RSS fields from ps's
> output. This, however, is worthless:
>
> VSZ tells the entire 'virtual memory' usage by each process, which includes
> shared memory. This means that a memory segment used by multiple processes
> is counted multiple times. As an example of how worthless this is, if I add
> the VSZ values for every process on my router machine, the result is 712mb
> of used memory. That machine has only 32mb of physical RAM and 32mb of
> swap, so it is physically impossible for the used memory to ever exceed
> 64mb.
>
> The RSS value is also nearly-worthless, as it only reports 'resident' memory
> (i.e. memory not in swap space). I have been unable to determine how the
> RSS value treats shared memory, but if I add all values in the RSS field on
> all processes, it always seems to roughly equal the amount of used memory
> reported by 'free', so I think this value is close to accurate.
>
> If I can find some way to determine how much swap space is used by a process
> (or all processes owned by a user), then I could possibly use the sum of
> that value and the values of RSS from ps to come up with a reasonable
> estimate for the total memory used by the user.
>
> Can anyone think of a way to accomplish this?
>
> -- Jonathan
>
> -- This is the discussion@xxxxxxxxx list. To unsubscribe,
> visit http://www.complete.org/cgi-bin/listargate-aclug.cgi
>
-- This is the discussion@xxxxxxxxx list. To unsubscribe,
visit http://www.complete.org/cgi-bin/listargate-aclug.cgi
|
|