• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 467
  • Last Modified:

what is cache and buffers in 'free' command output in Linux?


I would like to understand the difference between cache and buffer in Linux OS. Also I see the output of 'free' contains data related to 'cache' and 'buffer'. I would like to understand them.

$ free -m
             total       used       free     shared    buffers     cached
Mem:          1655       1641         13          0         53        198
-/+ buffers/cache:       1389        266
Swap:            0          0          0

Open in new window

  • 2
  • 2
1 Solution
Zephyr ICTCloud ArchitectCommented:
In short: A buffer is a temporary place to store data for one particular application as where cache is a memory place where frequently used data is used, this allows faster access. Also a Buffer is used only once as where cache can be used multiple times.

That's the main difference really.

For the free command, you need to calculate the difference between the used RAM minus the buffers+cache...
So in your case 1641 - 198 -53 = approx. 1389
Your "free" output screams in pain for a swap file.
beer9Author Commented:
Thanks Gheist. So, if we have a swap file/partition then there would not be a buffer and cached used in physical memory?
Zephyr ICTCloud ArchitectCommented:
Yes, there will always be buffer and cached, swap is what you want to avoid because that means your local disk will be used as temporary memory, which is always slower, even when using SSD. That being said, it's always good to have swap, it can help when you get memory spikes, the system will be slow but at least it will (should) remain online ... But it should definitely be avoided to use as an extension on the RAM (as in long term).
What is disk cache?
What are IO buffers?
Do you think concepts differ from Windows?

No, you dont have free memory on your system. That is the problem.

You cannot eliminate disk IO in system. There will be some buffers to interact with disk, others to chat with network etc. And otherwise free ram will be used to store disk blocks to save disk IO
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now