Find the answer to your Linux question:
Results 1 to 5 of 5
Directly from the man page of ps: vsz VSZ virtual memory size of the process in KiB (1024-byte units). Device mappings are currently excluded; this is subject to change. (alias ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2012
    Posts
    5

    Issue with the man page for ps (specifically concerning vsz)


    Directly from the man page of ps:
    vsz VSZ virtual memory size of the process in KiB (1024-byte units). Device mappings are currently excluded; this is subject to change. (alias vsize).
    ps -eo vsz,comm reports that nautilus is using a whopping 645.22 MB of memory, which is absolutely not true

    System Monitor reports nautilus is using 37.8MB of memory (a reasonable number, so I'm assuming this is accurate)

    Either vsz has been documented wrong in the man page of ps, or I'm confused. What units are vsz actually using? If I wanted to see memory usage in bytes or kilobytes, what would be a better option to send to ps -eo ? If it's a simple math conversion, I can deal with it, but I need to know what the conversion is.

    Here's a short script to demonstrate:
    Code:
    ps -eo vsz,comm | awk '/nautilus/ {print $1}' | awk '{ sum=$1 ;
                hum[1024^2]="GB"; hum[1024]="MB"; hum[1]="KB";
                for (x=1024^2; x>=1; x/=1024){
                    if (sum>=x) {
                        printf "%.2f %s\n",sum/x,hum[x];break
                    }
                }
            }'

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Hi,

    I like to use pmap in circumstances such as this. Here's an example:

    Code:
    #!/bin/bash
    proc=$1 # command line arg; or just say proc=nautilus
    pids=$(pidof $proc)
    for pid in $pids; do
      echo -n "$proc (pid $pid) "
      pmap -d $pid|awk '/^mapped/{print $3,$4}'
    done

  3. #3
    Just Joined!
    Join Date
    Jun 2012
    Posts
    5
    column one of pmap's output (sum of shared and private) is showing the same number as vsz. Interesting. Now the question is why these don't match gnome-system-monitor, and why one of them is so inaccurate.

  4. $spacer_open
    $spacer_close
  5. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    When you say System Monitor, do you mean GNOME's default one (launched via "gnome-system-monitor" on the command line)?

    On my Fedora 17 box, my system monitor (3.4.1) seems to work right. At least looking at the mem usage of one bash process in the Processes tab of system monitor matches the output of pmap's writable/private column and ps -o vsz.

    maybe you should check for updates to that package on your distro?

  6. #5
    Just Joined!
    Join Date
    Jun 2012
    Posts
    5
    It was gnome-system-monitor. Updates didn't do it (I had the issue on CentOS, Fedora, Mint, Ubuntu, and Arch). I figured it out though; the issue was me just not understanding how the kernel segregates memory.

    There are different ways to measure the amount of memory a process is consuming. If you turn on all columns in gnome-system-monitor, you'll see it.

    If I understand each right:
    virtual memory: this is the output of ps -eo vsz OR pmap -d `pidof $PROGRAM` | awk '/^mapped/ {print $2}'. It's the sum of shared memory, resident memory, and a couple other things
    resident memory: this is the output of pmap -d `pidof $PROGRAM` | awk '/^mapped/ {print $4}' . This is the best measurement of how much memory an app is consuming in my opinion, so this one right here resolves my issue
    writable memory: the default memory size displayed by gnome-system-monitor. Not directly accessible with ps or pmap. It is typically only a few KB or a few MB smaller than resident memory and can sometimes be identical
    shared memory: this is the output of pmap -d `pidof $PROGRAM` | awk '/^mapped/ {print $6}'. I think it has to do with the memory space of the shared libraries of an application
    X server memory: how much graphical memory a process is taking to render in X server. Not directly accessible with ps or pmap

    pmap's output is good enough for my script, so marking this as resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •