Re: /proc/*/statm, exactly what does "shared" mean?

From: Hugh Dickins
Date: Sat Feb 12 2005 - 08:10:22 EST


On Fri, 11 Feb 2005, Richard F. Rebel wrote:
>
> I can't seem to find clear documentation about the 'share' column
> from /proc/<pid>/statm.
>
> Does this include pages that are shared with forked children marked as
> copy-on-write?
>
> Does this only reflect libraries that are dynamically loaded? What
> about shared memory segments/mmaps (ala shmat or mmmap)?
>
> If there is a place where I might find documentation that is more clear
> beyond the proc.txt in the kernel docs and then man pages for procfs,
> I'd welcome a pointer.

You may not be entirely happy with this answer.
It is a count of "pages of the process" which are "shared" in some sense.
But precisely what that means has changed from time to time: depending on
our perception of what we can safely afford the overhead of counting.

You may want to look at fs/proc proc_pid_statm() source for the release
of interest, and follow that back to see exactly what is being counted.

Throughout 2.4 (and 2.2 too I think) it was the count of those pages
instantiated in the process address space which currently have a page
count greater than 1. That would include private pages shared with
forked children, pages from the pagecache (including pages mapped
from executable or library or shared memory or file mmap), those
private pages which currently have swap allocated (so they're also
in the swapcache), and any pages which transitorily have page count
raised for whatever reason (they'd likely already be in one of the
above categories). A ragbag of meanings, but that's all you can
get from looking at page count.

Counting up that not very meaningful number, at frequent intervals
on large process address spaces, is a waste of valuable time.

>From 2.5.37 to 2.6.9, it's the total extent of file-backed areas
(file including executable or library or shared memory) in the
process address space: a total extent (in pagesize units),
not a count of instantiated pages. Much quicker to calculate.

But there were complaints about that, and a need to revert from
total extent to count of instantiated pages.

>From 2.6.10 onwards, for the foreseeable future, it is the count
of those pages instantiated in the process address space which are
shared with a file (including executable or library or shared memory)
i.e. those pages which are not anonymous, not private. That count
does not include private pages shared with forked children, nor
does it include private pages which happen to have swap allocated.

Hugh
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/