Get chrome's total memory usage

Given that google killed chrome://memory in March 2016, I am now using smem:

# detailed output, in kB apparently
smem -t -P chrom
# just the total PSS, with automatic unit:
smem -t -k -c pss -P chrom | tail -n 1
  • to be more accurate replace chrom by full path e.g. /opt/google/chrome or /usr/lib64/chromium-browser
  • this works the same for multiprocess firefox (e10s) with -P firefox
  • be careful, smem reports itself in the output, an additional ~10-20M on my system.
  • unlike top it needs root access to accurately monitor root processes -- use sudo smem for that.
  • see this SO answer for more details on why smem is a good tool and how to read the output.

I'm sure that it's not the best solution, still it works for me:

ps aux | grep "[/]opt/google/chrome/chrome" | awk '{print $5}' | awk '{sum += $1 } END { print sum }' 
ps aux | grep "[/]opt/google/chrome/chrome" | awk '{print $6}' | awk '{sum += $1 } END { print sum }' 

Note: change the [/]opt/google/chrome/chrome to something appropriate for your system, e.g. if you're on Mac OS X (simply grep "chrome" will work).

Running this:

perl -e '$a="x"x1000000000;sleep(10);print"done\n"'

takes up 1.8GB RAM. So you would expect running this:

perl -e '$a="x"x1000000000;fork;fork;fork;fork;sleep(10);print"done\n"'

would take up 16 times as much. But it does not.

This is due to the Linux kernel's intelligent copy-on-write: Because the contents of '$a' does not change, then the memory of '$a' can be shared. But it will only remain shared until '$a' is changed. When that happens, the changed section will be copied and start to take up RAM.

Whether you can measure how much memory is copy-on-write over-committed I do not know. But at least this explains your over-counting.