• Mauricio Lin's avatar
    [PATCH] add /proc/pid/smaps · e070ad49
    Mauricio Lin authored
    Add a "smaps" entry to /proc/pid: show howmuch memory is resident in each
    mapping.
    
    People that want to perform a memory consumption analysing can use it
    mainly if someone needs to figure out which libraries can be reduced for
    embedded systems.  So the new features are the physical size of shared and
    clean [or dirty]; private and clean [or dirty].
    
    Take a look the example below:
    
    # cat /proc/4576/smaps
    
    08048000-080dc000 r-xp /bin/bash
    Size:               592 KB
    Rss:                500 KB
    Shared_Clean:       500 KB
    Shared_Dirty:         0 KB
    Private_Clean:        0 KB
    Private_Dirty:        0 KB
    080dc000-080e2000 rw-p /bin/bash
    Size:                24 KB
    Rss:                 24 KB
    Shared_Clean:         0 KB
    Shared_Dirty:         0 KB
    Private_Clean:        0 KB
    Private_Dirty:       24 KB
    080e2000-08116000 rw-p
    Size:               208 KB
    Rss:                208 KB
    Shared_Clean:         0 KB
    Shared_Dirty:         0 KB
    Private_Clean:        0 KB
    Private_Dirty:      208 KB
    b7e2b000-b7e34000 r-xp /lib/tls/libnss_files-2.3.2.so
    Size:                36 KB
    Rss:                 12 KB
    Shared_Clean:        12 KB
    Shared_Dirty:         0 KB
    Private_Clean:        0 KB
    Private_Dirty:        0 KB
    ...
    
    (Includes a cleanup from "Richard Purdie" <rpurdie@rpsys.net>)
    
    From: Torsten Foertsch <torsten.foertsch@gmx.net>
    
    show_smap calls first show_map and then prints its additional information to
    the seq_file.  show_map checks if all it has to print fits into the buffer and
    if yes marks the current vma as written.  While that is correct for show_map
    it is not for show_smap.  Here the vma should be marked as written only after
    the additional information is also written.
    
    The attached patch cures the problem.  It moves the functionality of the
    show_map function to a new function show_map_internal that is called with an
    additional struct mem_size_stats* argument.  Then show_map calls
    show_map_internal with NULL as struct mem_size_stats* whereas show_smap calls
    it with a real pointer.  Now the final
    
    	if (m->count < m->size)  /* vma is copied successfully */
    		m->version = (vma != get_gate_vma(task))? vma->vm_start: 0;
    
    is done only if the whole entry fits into the buffer.
    Signed-off-by: default avatarHugh Dickins <hugh@veritas.com>
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    e070ad49
base.c 51 KB