[lkml]   [2005]   [Jul]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: How do you accurately determine a process' RAM usage?
    Andrew Morton wrote:
    > OK, please let us know how it goes.

    It went very well. I could find no problems at all.
    I've updated my script to use the new method, so please merge smaps :)

    Usually the shared mem reported by /proc/$$/statm
    is the same as summing all the shared values in in /proc/$$/smaps
    but there can be large discrepancies.
    In the real world you can see this with a newly started apache.
    On my system statm reported that apache was using 35MB,
    whereas smaps reported the correct amount of 11MB.
    These numbers will converge over time as the unused pages
    of the apache processes were swapped out.
    Attached is a script that triggers and reports
    the memory discrepancy on an smaps enabled system.

    As for the overhead of calling smaps, well comparing to
    /proc/$$/maps which does essentially the same thing only
    not walking mem, on my 1.6GHz P4, 384MB laptop, gives:

    time read_10K_smaps

    real 0m3.323s
    user 0m0.636s
    sys 0m2.660s

    time read_10K_maps

    real 0m1.742s
    user 0m0.300s
    sys 0m1.428s

    I've also attached a patch to make smaps output match the maps output,
    as smaps was not showing info like which map was heap and stack etc.
    The code is smaller also, as show_smap() now just calls show_map().
    Note this patch is to be applied _after_ Hugh's changes.

    Pádraig Brady -
    import os, sys, time
    PAGESIZE=os.sysconf("SC_PAGE_SIZE")/1024 #KiB

    #stat = {Shared,Rss}
    #file = {smaps,statm}
    def getMemStat(pid,stat,file):
    if file=="smaps":
    for line in open("/proc/"+str(pid)+"/smaps").readlines()
    if line.find(stat)!=-1]
    return sum([int(line.split()[1]) for line in shared_lines])
    if stat == "Shared": stat_index=2
    elif stat == "Rss": stat_index=1
    return int(open("/proc/"+str(pid)+"/statm").readline().split()[stat_index])*PAGESIZE

    a="\x00"*(32*1024*1024) #alloc 32MiB
    if(not pid):

    for file in ["statm", "smaps"]:
    print "/proc/%d/%s reports %.1f%% shared" % (pid,file,((shr/rss)*100))

    [unhandled content-type:application/x-texinfo]
     \ /
      Last update: 2005-07-12 11:50    [W:0.021 / U:4.748 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site