Fooling around /proc - Linux

This is a discussion on Fooling around /proc - Linux ; Hi all, I was recently fooling with /proc for a school project and found out that ps and top are not doing the same calculation about memory load. For instance : ps aux | grep X 3323 1.5 5.9 64948 ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Fooling around /proc

  1. Fooling around /proc

    Hi all,
    I was recently fooling with /proc for a school project and found out
    that ps and top are not doing the same calculation about memory load.

    For instance :

    ps aux | grep X
    3323 1.5 5.9 64948 53996

    ok, so the value for the VSS size read by ps is : 64948 and the value
    for the RSS size is 53996

    Let's look at top now :

    serty2@serty2 ~ $ top > test.top
    serty2@serty2 ~ $ more test.top
    top - 18:31:52 up 1 day, 18:44, 1 user, load average: 0.26, 0.36,
    0.31
    Tasks: 78 total, 6 running, 71 sleeping, 0 stopped, 1 zomb
    ie
    Cpu(s): 4.2%us, 0.5%sy, 0.0%ni, 94.7%id, 0.6%wa,
    0.0%hi, 0.0%si, 0.0%st
    Mem: 904952k total, 765224k used, 139728k free, 38812k
    buffers
    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

    3323 root 15 0 191m 52m 7284 S 11.9 6.0 39:05.93 X



    Ok, so for Top , the Virtual mem size is 191m.
    This is somewhat different to the 64948Kb found by Ps.

    Am I wrong by thinking that these two values should be the same ?

    I've done the same test with other programs and most of the times, the
    values are the same.
    I really don't understand it

    I digged a bit deeper to see where the difference comes from.

    There are at least two different files in /proc that gives you the mem
    load of a particular process.

    Those files are : /proc/[PID]/statm and /proc/[PID]/status

    let's look at thos files for this example

    serty2@serty2 ~ $ more /proc/3323/status
    Name: X
    State: S (sleeping)
    SleepAVG: 98%
    Tgid: 3323
    Pid: 3323
    PPid: 3320
    TracerPid: 0
    Uid: 0 0 0 0
    Gid: 0 0 0 0
    FDSize: 256
    Groups:
    VmSize: 65080 kB
    VmLck: 0 kB
    VmRSS: 54128 kB
    VmData: 46772 kB
    VmStk: 84 kB
    VmExe: 1532 kB
    VmLib: 13124 kB
    VmPTE: 224 kB
    Threads: 1
    SigPnd: 0000000000000000
    ShdPnd: 0000000000000000
    SigBlk: 0000000000000000
    SigIgn: 0000000000001000
    SigCgt: 00000001d1806ecb
    CapInh: 00000000fffffeff
    CapPrm: 00000000fffffeff
    CapEff: 00000000fffffeff

    Ok , so the VmSize is 65080 , that really looks like the value we got
    from ps
    (not the exact same because of the time delay between the two tests)

    Let's look at the other file :

    serty2@serty2 ~ $ more /proc/3323/statm
    49166 13532 1821 383 0 11714 0

    as stated in proc's man , the first value is the total program size in
    mem pages.

    then : (49166 * 4096) / (1024) =192Mb

    We're pretty close to the value given by Top .

    I don't understand why there is a difference for those values for some
    programs.
    And most important of it, I really don't know what value to use

    I think I would go for the value in /proc/[PID]/statm because the
    /proc/[PID]/status is supposed to be only a aggregate of information
    found in other files and made "human-readable".
    But then, I'm not sure.

    Does anyone know which file holds the right value ?

    Thanks for any comments

    Damien

    PS : please excuse my english mistakes


  2. Re: Fooling around /proc

    serty2@gmail.com wrote:

    >Hi all,
    >I was recently fooling with /proc for a school project and found out
    >that ps and top are not doing the same calculation about memory load.
    >
    >For instance :
    >
    >ps aux | grep X
    >3323 1.5 5.9 64948 53996
    >
    >ok, so the value for the VSS size read by ps is : 64948 and the value
    >for the RSS size is 53996
    >
    >Let's look at top now :
    >
    >serty2@serty2 ~ $ top > test.top
    >serty2@serty2 ~ $ more test.top
    >top - 18:31:52 up 1 day, 18:44, 1 user, load average: 0.26, 0.36,
    >0.31
    >Tasks: 78 total, 6 running, 71 sleeping, 0 stopped, 1 zomb
    >ie
    >Cpu(s): 4.2%us, 0.5%sy, 0.0%ni, 94.7%id, 0.6%wa,
    > 0.0%hi, 0.0%si, 0.0%st
    >Mem: 904952k total, 765224k used, 139728k free, 38812k
    >buffers
    > PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    >
    > 3323 root 15 0 191m 52m 7284 S 11.9 6.0 39:05.93 X
    >
    >Ok, so for Top , the Virtual mem size is 191m.
    >This is somewhat different to the 64948Kb found by Ps.
    >
    >Am I wrong by thinking that these two values should be the same ?


    Yes. The "top" value probably includes the size of your frame buffer,
    which has to be mapped into the virtual memory space to be used, but
    doesn't actually use any RAM. If your graphics card uses a 128MB frame
    buffer, then that is almost certainly the case.
    --
    - Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.

+ Reply to Thread