Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

[OT]What is "buffers" and "cached" memory in Linux system box?

by sunshine_august (Scribe)
on Sep 19, 2008 at 03:31 UTC ( [id://712434]=perlquestion: print w/replies, xml ) Need Help??

sunshine_august has asked for the wisdom of the Perl Monks concerning the following question:

Hi, dear all monks:

I am writting a block of code to calculate the free memory of a linux system box, but I am confused with the "buffers" and "cached" memory from the output generated by 'free' command.

[larry@localhost ~]$ free total used free shared buffers cac +hed Mem: 8164688 3135816 5028872 0 24816 108 +660 -/+ buffers/cache: 3002340 5162348 Swap: 0 0 0

What should I think of the "buffers" and "cached" memory? should I think they are part of free memory?

In my opinion, the kernel can take back the "buffers" and "cached" memory when some process require more memory but the free memory is lower than some threshhold.

If I am wrong, pls feel free to correct me, thx:)

Replies are listed 'Best First'.
Re: [OT]What is "buffers" and "cached" memory in Linux system box?
by themage (Friar) on Sep 19, 2008 at 09:51 UTC
    Hi sunshine_august,

    Buffers and Cached is memory used by the kernel to optimize access to slow access data, usually disks.

    You can think of that as free memory, but you are much better while kernel have memory to use that way.

    I wrote some software that update several thousands of files, and that was a slow process. Later, as that updates repeated, the Kernel allocated near 2GB of memory to cached, and the performance was really (I can't make enought enfase on that really) improved.

    Memory in not something you may consider as enougth. It is only enougth if you can spare some to the kernel, it won't abuse it.

Re: [OT]What is "buffers" and "cached" memory in Linux system box?
by jethro (Monsignor) on Sep 19, 2008 at 11:43 UTC
    I don't think the kernel can take back those buffers, as they are necessary for any I/O that needs to read or write arbitrary sized chunks from/to block devices (but I could be wrong about the meaning of "buffers")
Re: [OT]What is "buffers" and "cached" memory in Linux system box?
by Hue-Bond (Priest) on Sep 19, 2008 at 22:05 UTC
    What should I think of the "buffers" and "cached" memory? should I think they are part of free memory?

    This is a verbatim copy of what I wrote down when I had this same question:

    total used free shared buffers cac +hed Mem: 1034332 983572 50760 0 149028 530 +132 -/+ buffers/cache: 304412 729920 Swap: 131064 9856 121208 Mem: A B C D E + F -/+ buffers/cache: G H G+H = A E+F+G = B ## probably D+E+F+G C+E+F = H ## probably C+D+E+F

    --
    David Serrano

      I try to rearrange the expression to make it more clear:
      A = B + C = G + H G = B - E - F H = C + E + F
      It seems that:

      Mem: 1034332 983572 50760 0 149028 530132
      shows "buffers" and "cached" as part of "used" memory.

      But -/+ buffers/cache: 304412 729920
      shows "buffers" and "cached" as part of "free" memory

      The -/+ buffers/cache line shows how much memory is used and free from the perspective of the applications.
      --- from http://gentoo-wiki.com/FAQ_Linux_Memory_Management#The_difference_between_buffers_and_cache

      And I do a test on my box, it shows that when the "free" memory is going to be exhausted, the kernel will take back all the "buffers" memory, but still left some "cached"memory. Following is the output by "free -m -s 1" when I increasingly created threads to consume the memory:

      total used free shared buffers cac +hed Mem: 7973 68 7904 0 8 + 27 -/+ buffers/cache: 33 7939 Swap: 2047 0 2047 total used free shared buffers cac +hed Mem: 7973 106 7866 0 8 + 27 -/+ buffers/cache: 71 7902 Swap: 2047 0 2047
Re: [OT]What is "buffers" and "cached" memory in Linux system box?
by Joost (Canon) on Sep 19, 2008 at 19:11 UTC

      From my test, the kernel take back all of the "buffers" mem, but leave some for the "cached".

      My box:
      Linux localhost.localdomain 2.6.22.9 #1 SMP Wed Sep 17 10:54:46 CST 2008 x86_64 x86_64 x86_64 GNU/Linux
      And the program I run mainly deal with the network data through loop-back address.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://712434]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-25 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found