Find it

Thursday, April 22, 2010

Interpreting the output of free command - RHEL

Hi there!

Long time. Okay so today we will look into how to Interpret "free" command output. Actually this understanding helps when we analyze the systems which going through bad phase of perfromance.


# free
     total         used    free  shared buffers cached
Mem: 4147720       3974664 173056  0    358608 3285520
-/+ buffers/cache: 330536  3817184
Swap: 6289436          36  6289400

  • All the numbers are reported in 1024-byte blocks.
  • Here, we see a system with 4147720 blocks (about ~4G) of physical RAM, with 3974664 (about ~3.7 GB) currently in use.
  • The "shared" column lists the amount of physical memory shared between multiple processes. Here, we see that about 0 MB of pages are being shared (I suspect it is not a good sign; memory is not being utilized well however on maximum number of servers I've observed the same thing).
  • The "buffers" column shows the amount of memory being used by the kernel buffer cache. The buffer cache is used to speed up disk operations, by allowing disk reads and writes to be serviced directly from memory. The buffer cache size will increase or decrease as memory usage on the system changes; this memory is reclaimed if it is needed by applications. Therefore, although we see that ~3.7 GB of system memory is in use, not all (but most) of it is being used by application programs.
  • The "cache" column indicates how many memory pages the kernel has cached for faster access later. Since the memory used for buffers and cache can easily be reclaimed for use by applications, the second line (-/+ buffers/cache) provides an indication of the memory actually used by applications (the "used" column) or available to applications (the "free" column). The sum of the memory used by buffers and cache reported in the first line is subtracted from the total used memory and added to the total free memory to give the two figures on the second line.
  • In the third line, we see the total amount of swap, 6289436 blocks (about 6 GB). In this case, only very little of the swap is being used; there is plenty of physical RAM available. If additional applications were started, larger parts of the buffer cache memory would be used to host them. Swap space is generally used as a last resort when the system can't reclaim physical memory in other ways. Note that the amount of swap reported by free is somewhat less than the total size of your swap partitions and files. This is because several blocks of each swap area must be used to store a map of how each page in the swap area is being utilized. This overhead should be rather small; only a few kilobytes per swap area.
HTH

12 comments:

  1. Hi,

    This was a good post. Gave a precise description on the output. Keep up the good work.

    I was searching more on such posts and came across this one:

    http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in-memory

    There are other posts too which describe the internals in a great illustrated manner.

    ReplyDelete
  2. plz help me with this ,i am lloking for a command to show memory usage on aix ,solaris and linux .so tht i can write a portable script tp mem_ck .plz reply me on abhishekmca@hotmail.com

    ReplyDelete
  3. Hullo, I don't understand the last point starting "In the third line." It goes on to say swap is not being used as there is plenty of RAM available. But 'free' shows RAM as being nearly exhausted - 173056 , can you explain the reasoning?
    many thanks :-)

    ReplyDelete
  4. @Anynomous

    This is the link http://www.linuxatemyram.com/
    Hope answer your question

    ReplyDelete
  5. This article was a very useful for me) thanx

    ReplyDelete
  6. Hi Nilesh, as per above example i think their is some correction.
    Please find my analysis below
    eg: # free
    total used free shared buffers cached
    Mem: 4147720 3974664 173056 0 358608 3285520
    -/+ buffers/cache: 330536 3817184
    Swap: 6289436 36 6289400

    A per ur
    The sum of the memory used by buffers and cache reported in the first line is subtracted from the total used memory and added to the total free memory to give the two figures on the second line.

    358608 + 3285520 = 36,44,128

    3974664 - 36,44,128 = 3,30,536 (memory used in 2nd line)

    3,30,536 + 173056 = 5,03,592 (which is not correct in mem free in second line)

    If we correct this as
    The sum of the memory used by buffers and cache reported in the first line is subtracted from the total used memory and substract from total memory of first line to give the two figures on the second line.


    358608 + 3285520 = 36,44,128

    3974664 - 36,44,128 = 3,30,536 (memory used in 2nd line)

    4147720 - 3,30,536 = 38,17,184 (memory free in 2nd line)



    Correct me

    Thanks & Regards,
    Srikanth

    ReplyDelete
  7. Thank you so much..This is very good post, I was loking for this kind of stuff. Keep it up. Good wishes :)

    ReplyDelete
  8. Hi Nilesh. WRT the 0 in the shared column, you say, "I suspect it is not a good sign; memory is not being utilized well however on maximum number of servers I've observed the same thing". If you had *read the man page* for free you would have noticed in the first paragraph: "The shared memory column should be ignored; it is obsolete." Always read the manual page first ;) http://linux.die.net/man/1/free

    ReplyDelete
  9. @Nilesh This was great help! The man page for free does such a poor job of explaining this otherwise. +10 to your karma points :-)

    ReplyDelete
  10. Swap space is generally used as a last resort when the system can't reclaim physical memory in other ways. Note that the amount of swap reported by free is somewhat less than the total size of your swap partitions and files. This is because several blocks of each swap area must be used to store a map of how each page in the swap area is being utilized. This overhead should be rather small; only a few kilobytes per swap area.
    Judi Poker
    Nonton Bokep
    Cerita Dewasa
    Nonton Movie

    ReplyDelete