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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.