Skip to content

Instantly share code, notes, and snippets.

@sameo
Created February 7, 2017 13:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sameo/d49c50772d616ae00e96c9967e676976 to your computer and use it in GitHub Desktop.
Save sameo/d49c50772d616ae00e96c9967e676976 to your computer and use it in GitHub Desktop.
RSS and PSS, Clean vs Dirty, Private vs Shared
From http://unix.stackexchange.com/questions/33381/getting-information-about-a-process-memory-usage-from-proc-pid-smaps
For a given process in /proc/<pid>/smaps, for a given mapping entry what are:
Shared_Clean
Shared_Dirty
Private_Clean
Private_Dirty
Clean pages are pages that have not been modified since they were mapped (typically, text sections from shared libraries are only read from disk (when necessary), never modified, so they'll be in shared, clean pages).
Dirty pages are pages that are not clean (i.e. have been modified).
Private pages are available only to that process, shared pages are mapped by other processes*.
RSS is the total number of pages, shared or not, currently mapped into the process. So Shared_Clean + Shared_Dirty would be the shared part of the RSS (i.e. the part of RSS that is also mapped into other processes), and Private_Clean + Private_Dirty the private part of RSS (i.e. only mapped in this process).
PSS (proportional share size) is as you describe. Private pages are summed up as is, and each shared mapping's size is divided by the number of processes that share it.
So if a process had 100k private pages, 500k pages shared with one other process, and 500k shared with four other processes, the PSS would be:
100k + (500k / 2) + (500k / 5) = 450k
Further readings:
ELC: How much memory are applications really using?
Documentation/filesystems/proc.txt in the kernel source
man proc(5)
Linux Memory Management Overview
Memory Management at TLDP.org
LinuxMM
Regarding process-wide sums:
RSS can be (approximately+) obtained by summing the Rss: entries in smaps (you don't need to add up the shared/private shared/dirty entries).
awk '/Rss:/{ sum += $2 } END { print sum }' /proc/$$/smaps
You can sum up Pss: values the same way, to get process-global PSS.
USS isn't reported in smaps, but indeed, it is the sum of private mappings, so you can obtain it the same way too
*Note that a "share-able" page is counted as a private mapping until it is actually shared. i.e. if there is only one process currently using libfoo, that library's text section will appear in the process's private mappings. It will be accounted in the shared mappings (and removed from the private ones) only if/when another process starts using that library.
+The values don't add up exactly for all processes. Not exactly sure why... sorry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment