Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Help me understand the memory usage - Page 2
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Help me understand the memory usage

2»

Comments

  • vanarpvanarp Member

    @yomero said: Linode uses 3.4 btw o_O

    Interesting....

  • tommytommy Member
    edited June 2012

    give ps_mem try

  • vanarpvanarp Member

    @tommy said: give ps_mem try

    Hmmm... it also does not solve the memory calculation issue. as can be seen below the actual memory in use and the script's result are greatly apart.

    On OpenVZ :

    root@vps:/home/bobo# ./ps_mem.py
     Private  +   Shared  =  RAM used       Program
    
    132.0 KiB +  61.5 KiB = 193.5 KiB       syslogd
    276.0 KiB +  63.0 KiB = 339.0 KiB       cron
    240.0 KiB + 198.5 KiB = 438.5 KiB       pickup
    312.0 KiB + 156.0 KiB = 468.0 KiB       su
    276.0 KiB + 198.5 KiB = 474.5 KiB       qmgr
    284.0 KiB + 205.0 KiB = 489.0 KiB       master
    732.0 KiB +  91.0 KiB = 823.0 KiB       init
    824.0 KiB + 827.0 KiB =   1.6 MiB       bash (2)
      1.0 MiB +   1.6 MiB =   2.6 MiB       sshd (3)
      1.7 MiB +   1.6 MiB =   3.3 MiB       nginx (2)
     19.8 MiB +   3.9 MiB =  23.7 MiB       php5-fpm (3)
     27.1 MiB + 137.5 KiB =  27.3 MiB       mysqld
    ---------------------------------
                             61.6 MiB
    =================================
    root@vps:/home/bobo# free -m
                 total       used       free     shared    buffers     cached
    Mem:           512        149        362          0          0          0
    -/+ buffers/cache:        149        362
    Swap:            0          0          0
    

    On KVM :

    bobo@jupiter:~$ sudo ./ps_mem.py
    [sudo] password for bobo:
     Private  +   Shared  =  RAM used       Program
    
     32.0 KiB +  28.0 KiB =  60.0 KiB       atd
      8.0 KiB +  54.0 KiB =  62.0 KiB       acpid
     64.0 KiB +  13.5 KiB =  77.5 KiB       dhclient3
      8.0 KiB + 102.5 KiB = 110.5 KiB       udevd (3)
    100.0 KiB +  42.0 KiB = 142.0 KiB       irqbalance
    104.0 KiB +  76.5 KiB = 180.5 KiB       cron
     96.0 KiB +  94.0 KiB = 190.0 KiB       upstart-socket-bridge [updated]
     96.0 KiB + 101.5 KiB = 197.5 KiB       upstart-udev-bridge [updated]
     24.0 KiB + 276.0 KiB = 300.0 KiB       getty (6)
    120.0 KiB + 180.0 KiB = 300.0 KiB       qmgr
    148.0 KiB + 184.5 KiB = 332.5 KiB       master
    232.0 KiB + 180.0 KiB = 412.0 KiB       pickup
    204.0 KiB + 261.5 KiB = 465.5 KiB       whoopsie
    508.0 KiB +  74.5 KiB = 582.5 KiB       rsyslogd
    600.0 KiB +  46.5 KiB = 646.5 KiB       dbus-daemon
    500.0 KiB + 158.0 KiB = 658.0 KiB       sudo
    644.0 KiB + 145.5 KiB = 789.5 KiB       init [updated]
      1.3 MiB + 955.5 KiB =   2.3 MiB       nginx (2)
    716.0 KiB +   1.6 MiB =   2.3 MiB       sshd (3)
      5.0 MiB +  80.5 KiB =   5.1 MiB       bash
      9.1 MiB + 110.5 KiB =   9.2 MiB       mysqld
     17.8 MiB +   5.7 MiB =  23.5 MiB       php5-fpm (4)
    ---------------------------------
                             47.8 MiB
    =================================
    bobo@jupiter:~$ free -m
                 total       used       free     shared    buffers     cached
    Mem:          1001        816        184          0         57        671
    -/+ buffers/cache:         86        914
    Swap:         1021          6       1015
    

    It makes me believe that there is no perfect program/script that can measure the exact memory in use by process on Linux.

    Only below script (ps command) takes us closer to reality but only on KVM.

    while read command percent rss; do if [[ "${command}" != "COMMAND" ]]; then rss="$(bc <<< "scale=2;${rss}/1024")"; fi; printf "%-26s%-8s%s\n" "${command}" "${percent}" "${rss}"; done < <(ps -A --sort -rss -o comm,pmem,rss | head -n 51)
    
    
    
    COMMAND                   %MEM    RSS
    php5-fpm                  2.1     21.25
    mysqld                    0.9     9.76
    php5-fpm                  0.5     5.82
    bash                      0.5     5.80
    php5-fpm                  0.4     4.78
    php5-fpm                  0.3     3.75
    sshd                      0.2     2.97
    nginx                     0.2     2.35
    sshd                      0.1     1.84
    nginx                     0.1     1.67
    init                      0.1     1.61
    sshd                      0.1     1.52
    master                    0.1     1.29
    pickup                    0.1     1.26
    qmgr                      0.1     1.14
    dbus-daemon               0.1     1.07
    whoopsie                  0.1     1.06
    bash                      0.1     1.05
    rsyslogd                  0.0     .88
    cron                      0.0     .76
    ps                        0.0     .68
    getty                     0.0     .66
    getty                     0.0     .66
    getty                     0.0     .66
    getty                     0.0     .66
    getty                     0.0     .66
    getty                     0.0     .66
    udevd                     0.0     .61
    bash                      0.0     .55
    irqbalance                0.0     .50
    acpid                     0.0     .47
    upstart-udev-br           0.0     .38
    upstart-socket-           0.0     .37
    atd                       0.0     .21
    bash                      0.0     .16
    dhclient3                 0.0     .08
    udevd                     0.0     .01
    udevd                     0.0     .01
    kthreadd                  0.0     0
    ksoftirqd/0               0.0     0
    kworker/u:0               0.0     0
    migration/0               0.0     0
    watchdog/0                0.0     0
    migration/1               0.0     0
    kworker/1:0               0.0     0
    ksoftirqd/1               0.0     0
    kworker/0:1               0.0     0
    watchdog/1                0.0     0
    cpuset                    0.0     0
    khelper                   0.0     0
    

    According to above output total memory in use is 79.62 MB which is closer to 86 MB reported by the free command.

  • yomeroyomero Member

    Nah, ps_mem.py does real memory accounting. Again, useless in these VPSs

  • DerekDerek Member

    You shouldn't run Apache and PHP FPM As Root.

    That's a problem..

  • yomeroyomero Member

    @Derek said: You shouldn't run Apache and PHP FPM As Root.

    Where is running as root?
    You mean the master processes? That's a common configuration.

  • qjqqjq Member

    ps_mem won't total up to free -m 's value cuz of stuff like disk cache

Sign In or Register to comment.