Wednesday, January 10, 2018

How to find process using high memory in Linux

Learn how to find process using high memory on linux server. This
helps in tracking down issues and troubleshooting utilization problems.

Many times you came to know system memory is highly utilized using utility like sar. You want to find processes hogging on memory. To find that, we will be using sort function of process status ps
command in this article. We will be sorting ps output with RSS values.
RSS is Resident Set Size. This values shows how much memory from
physical RAM allocated to particular process. It does not include
swapped out memory numbers. Since, we troubleshooting processes using
high physical memory RSS fits for our criteria.

Lets see below example :

Shell

1

2

3

4

5

6

7

8

9

10

11

12

13

# ps aux --sort -rss |head -10

USER PID%CPU%MEM VSZ RSS TTYSTAT START TIMECOMMAND

oracle_admin144000.011.83693738431420276?Ss201686:41ora_mman_DB1

oracle_admin144050.211.33699367630023868?Ss20161676:11ora_DB3

oracle_admin144160.211.33699367630023656?Ss20161722:47ora_DB3

oracle_admin144100.211.33699367630020400?Ss20161702:09ora_DB3

oracle_admin144210.211.33699367630018272?Ss20161754:25ora_DB3

oracle_admin144400.010.53694686827887152?Ss2016130:30ora_mon_DB3

oracle_admin158550.06.91923242418298484?Ss201641:01ora_mman_DB4

oracle_admin158570.16.71928872017966276?Ss2016161:45ora_DB4

oracle_admin158640.16.71928872017964584?Ss2016173:36ora_DB4

In
above output we sorted processes with RSS and shown only top 10 one.
RSS value in output is in Kb. Lets verify this output for top most
process with pid 14400.

Shell

1

2

3

4

5

6

7

# free

total used free shared buffers cached

Mem:264611456961467281684647280104297275377436

-/+buffers/cache:19726320244885136

Swap:6710886053960066569260

On
our system we have 264611456Kb physical RAM (highlighted entry in above
output). Out of which 11.8% is used by process 14400 (from ps output
above) which comes to 31224151Kb. This value matches RSS value of
31420276Kb (in ps output above)!
So above method works good when you try to find processes using highest physical memory on system!
You can even use another methods to get high memory using processes like top, htop etc. but this article aimed at using ps.