45

Since google chrome/chromium spawn multiple processes it's harder to see how much total memory these processes use in total.

Is there an easy way to see how much total memory a series of connected processes is using?

1
  • If I convert the numbers that prints out from KiB to GiB then even for Res. Memory I get more than the machine's amount of RAM plus swap. So it seems like something is getting over-counted.
    – Ryan1729
    Jun 9, 2016 at 4:42

8 Answers 8

48

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.
9
  • I am not sure that this is working for me. When I run the second command, I get a returned value of 338.0M. This is too low. When I run System Monitor, I can see that there are 11 chrome processes and each is taking between 70MB and 400MB of RAM. Not sure if System Monitor is reporting incorrectly or not. Apr 5, 2017 at 15:40
  • Same problem for smem on a Kali Linux 2017.1 distribution, the output is 800Mo of ram used by chrome with 5 instances and at least 30 tabs ... And the system monitor does not agree with smem either. Has anyone found a solution to this ? (Thanks for the answer and the references)
    – matthieusb
    Jun 17, 2017 at 22:10
  • 1
    Your comments deserve a separate question (with full output of conflicting programs). Just post the link in the comment.
    – eddygeek
    Jun 18, 2017 at 22:43
  • 1
    I would use chrome instead of just chorm because if you are running both chrome and chromium, you 'd be seeing total for both.
    – R J
    Mar 3, 2018 at 12:33
  • 3
    You can exclude smem from its own output by using something like [c]hrome, e.g. smem -tkP '[c]hrome'. This works by matching the c inside the square brackets and not the brackets themselves.
    – wjandrea
    May 26, 2018 at 4:31
4

Improving solution of @eddygeek:

smem -ktP chrome

Take a look on the value of column "USS", on last line

Note: you can also create an alias for this:

alias mem='smem -ktP '

And then use:

mem chrome
3

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

#!/bin/sh
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).

9
  • 2
    This “works” in that it prints a number. However this number is not all that useful since memory that is shared between several processes is counted multiple times. Jun 9, 2016 at 22:38
  • I imagine in reality it's still good enough because Chrome is by far the biggest memory hog on typical desktops and when you kill chrome processes your system becomes blazing fast. Dec 3, 2016 at 2:48
  • Why two awk commands? That is, why not just ... | awk '{sum += $6} END {print sum}'?
    – wjandrea
    Apr 23, 2018 at 6:37
  • 2
    FWIW, here's a shorter, clearer version: ps aux | grep "/opt/google/chrome/chrome" | awk '{vsz += $5; rss += $6} END { print "vsz="vsz, "rss="rss }'
    – wjandrea
    Apr 23, 2018 at 17:24
  • 1
    @Rushi Don't bother. This solution doesn't give a meaningful number. Use smem per the top answer. Though FWIW, I would implement it as a script or function, since it's too complex for an alias.
    – wjandrea
    Aug 3, 2019 at 14:41
2

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.

1

Just quickly calculate the sum of the processes.

On Mac:

  • go to chrome://system/ and select all reported in mem_usage
  • paste in SublimeText
  • SelectAll (CMD+'A') and SelectAllLines (CMD+SHIFT+'L')
  • CMD+Right (go to eol), Backspace, Backspace, Backspace, ALT+Left, CMD+Backspace
  • Backspace, type '+', CMD+'A', CMD+'C'
  • open Terminal, run python, CMD+V, Enter

Et voila! "Easy"... 🤓😅

PS - Shortcut ninjas & 80s/90s Fighting-game players should have no problem with this solution 🤖🕹💾

0

I found a solution with vim and awk. Open chrome://system, expand mem_usage, copy to vim and execute the regexp:

:%s/\D*\(\d*\).MB.*/\1

This leaves only the numbers before MB. Save the file and execute

cat file | awk '{sum += $1} END {print sum}'

I could not convert the vim regexp code to sed.

0

There is USS which is available cross platforms

The USS (Unique Set Size) is the memory which is unique to a process and which would be freed if the process was terminated right now.

psutil>4.0 Python library can access it

Here is I would use it

sudo python3 -c "import psutil;print(sum(p.memory_full_info().uss for p in psutil.Process(pid=292).children())/1024/1024);"

where pid=292 is PID of most outer process from Activity Monitor

-1

I knew that chrome/chromium had a task manager, but it doesn't give the total memory used. It turns out that the "Stats for nerds" link in the task manager leads to chrome://memory-redirect/ which does list the total memory used. It would be nice to have external validation of these numbers, as well as a way to get the information on the command line so more could be done with it, but this seems to be the best way available.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .