How do I find out Linux System Memory Utilization?

by Vivek Gite on November 24, 2007 · 6 comments

Q. How do I find out System / Server Memory Utilization under RHEL / CentOS / any other Linux distribution?

A. You need to use free command which, displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel.

free command example

Type the free command at shell prompt:
$ free
$ free -m

Output:

             total       used       free     shared    buffers     cached
Mem:          2010       1965         45          0        152        776
-/+ buffers/cache:       1036        974
Swap:         2047        137       1910

vmstat command

vmstat command provides more information :
$ vmstat
Output:

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0 140480  43636 158196 797692    1    0   108   220    1    4  7  5 87  1  0

Understanding vmstat memory options

  • swpd: the amount of virtual memory used.
  • free: the amount of idle memory.
  • buff: the amount of memory used as buffers.
  • cache: the amount of memory used as cache.
  • inact: the amount of inactive memory. (-a option)
  • active: the amount of active memory. (-a option)

$ vmstat -a
Output:

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa st
 0  1 140480  37376 109516 1730040    1    0   108   220    1    4  7  5 87  1  0

The following command displays one new line of utilization data every second
$ vmstat 1
The following command displays one new line per 2 second, but only for the next 10 seconds:
$ vmstat 2 10
Output:

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa st
 4  0 139216  23508 130644 1723680    1    0   108   220    1    5  7  5 87  1  0
 2  0 139216  23252 130668 1723816    0    0     0   410 3242 11472  9  7 84  0  0
 1  0 139216  23120 130656 1724012    0    0     0   750 3280 11592  3  6 90  1  0
 0  0 139216  22996 130588 1724180    0    0     0   426 3272 11052  2  5 93  0  0
 2  0 139216  20988 129932 1726980    0    0     6  1146 3353 12105 14  9 74  2  0
 1  0 139216  20244 129900 1727216    0    0     0   392 3238 11752  8  7 85  0  0
 1  0 139216  20120 129868 1727352    0    0     0   444 3197 11173  2  5 93  0  0
 1  0 139216  25964 129852 1721044    0    0     0   268 3147 9269  1  4 95  0  0
 3  0 139216  25964 129748 1721196    0    0     2   132 3199 10540  1  4 95  0  0
 1  0 139216  25964 129676 1721332    0    0     0   456 3213 10608  2  4 93  1  0

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 6 comments… read them below or add one }

1 Vijay April 2, 2009

Hi Vivek,

How can I know the memory usage for a particular process in Linux.

Thank you,
Vijay

Reply

2 shantha Kumar April 5, 2009

Thank’s a lot yar…………thank’s

Reply

3 sujith August 5, 2010

Hi Vivek

What is the difference between free memory and inactive memory
Thanks
sujith

Reply

4 sreeharsha April 14, 2011

Inactive memory is the pages that are used or allocated for some other processes earlier, but not in use now. Hence if it exhausts on free memory it will utilize form this set. The only advantage of inactive pages is, it saves time if the same page ( that is in inactive set ) is needed, it can be used without bringing in the page. If you want to reduce the inactive page, do as following:
dd if=/dev/urandom of=/tmp/test_file bs=20M

Now after writing for 1-2 GB of file, stop dd and delete it. You can see the respective amount of mem being added to free from inactive. Though this is not suggested as you might be losing the inactive pages, which can become valuable for other processes when they start.

Reply

5 rikijam November 28, 2011

wow.. thank you sreeharsha!. your trick solved my problem.

Reply

6 mrcool December 26, 2011

how to increase the file descriptor values in linux. . .

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 7 + 10 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: