Skip to content
  • Jerome Marchand's avatar
    mm, procfs: breakdown RSS for anon, shmem and file in /proc/pid/status · 8cee852e
    Jerome Marchand authored
    
    
    There are several shortcomings with the accounting of shared memory
    (SysV shm, shared anonymous mapping, mapping of a tmpfs file).  The
    values in /proc/<pid>/status and <...>/statm don't allow to distinguish
    between shmem memory and a shared mapping to a regular file, even though
    theirs implication on memory usage are quite different: during reclaim,
    file mapping can be dropped or written back on disk, while shmem needs a
    place in swap.
    
    Also, to distinguish the memory occupied by anonymous and file mappings,
    one has to read the /proc/pid/statm file, which has a field for the file
    mappings (again, including shmem) and total memory occupied by these
    mappings (i.e.  equivalent to VmRSS in the <...>/status file.  Getting
    the value for anonymous mappings only is thus not exactly user-friendly
    (the statm file is intended to be rather efficiently machine-readable).
    
    To address both of these shortcomings, this patch adds a breakdown of
    VmRSS in /proc/<pid>/status via new fields RssAnon, RssFile and
    RssShmem, making use of the previous preparatory patch.  These fields
    tell the user the memory occupied by private anonymous pages, mapped
    regular files and shmem, respectively.  Other existing fields in /status
    and /statm files are left without change.  The /statm file can be
    extended in the future, if there's a need for that.
    
    Example (part of) /proc/pid/status output including the new Rss* fields:
    
    VmPeak:  2001008 kB
    VmSize:  2001004 kB
    VmLck:         0 kB
    VmPin:         0 kB
    VmHWM:      5108 kB
    VmRSS:      5108 kB
    RssAnon:              92 kB
    RssFile:            1324 kB
    RssShmem:           3692 kB
    VmData:      192 kB
    VmStk:       136 kB
    VmExe:         4 kB
    VmLib:      1784 kB
    VmPTE:      3928 kB
    VmPMD:        20 kB
    VmSwap:        0 kB
    HugetlbPages:          0 kB
    
    [vbabka@suse.cz: forward-porting, tweak changelog]
    Signed-off-by: default avatarJerome Marchand <jmarchan@redhat.com>
    Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
    Acked-by: default avatarKonstantin Khlebnikov <khlebnikov@yandex-team.ru>
    Acked-by: default avatarMichal Hocko <mhocko@suse.com>
    Acked-by: default avatarHugh Dickins <hughd@google.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    8cee852e