Explain memory - cached, shared, buffers and free

Posted on 2011-03-20
Last Modified: 2012-05-11
Hi experts,

I have recently installed some server monitoring software on my web server which has the ability to send me various alerts. I can set the alert based on Cached, Shared, Buffers or Free but I have no idea which is most relevant. I'm guessing a combination of shared and buffers.

The server has 1.5GB ram and is hosting a website that is getting around 1000 visits a day but that is expected to increase steadily (or rapidly). In the last hour it has averaged

Cached: 1067MB
Shared: 226MB
Buffers: 76MB
Free: 107.22MB

What should I be looking out for?

Question by:mstrelan
LVL 12

Expert Comment

ID: 35178476
LVL 10

Author Comment

ID: 35178535
Does not really help ... what I want to know is what sort of figures would be alarming. For example perhaps Shared should not exceed 1GB.

Expert Comment

ID: 35178538
My $0.02 would be to monitor free memory. In theory the cache will fill up until the memory it uses is required, then it'll start to clear the oldest information first.

Are you able to set a maximum cache size? What is the size of the content you are serving? How is your visitor load distributed (all between 6AM and 8AM, throughout the whole day, 6AM - 10PM, etc...)?
LVL 10

Author Comment

ID: 35195850
@Vampireofdarkness - if I understand correctly I should only be alarmed when free memory hits 0? In which case linux will start freeing up memory from cache anyway? I would have thought it would be good to monitor the amount of Shared memory, so I could be alarmed when it is using say 50% of the memory. And perhaps monitor swap space?

Accepted Solution

Anton74 earned 500 total points
ID: 35196034
The OS tries to make the most efficient use of RAM. It will use lots of RAM for cache if it can (meaning, if it's not otherwise needed), and with growing RAM demand it will be less, but normally never zero. Put somewhat differently, because unused (free) RAM is not useful until it is actually used, the OS will happily use it for cache rather than keep it free. Because of this, free memory is typically low; cache memory is easily and quickly freed as otherwise needed.

Between the numbers of cached/shared/buffers/free, shared and buffers tend to be a pretty low number and won't tell you much, so you'd want to focus on cached and free. Individually those won't tell you very much because free memory is almost always low as it'll be used for cache as explained above, but you can look at how much free memory you would have not considering cache - this is actually displayed on the second line. To really put this in useful perspective you have to compare to the amount of physical RAM you have. In your example, you have 1.5GB of RAM, and after subtracting cache and free memory only a few hundred MB is really used by programs (and the kernel), so you currently have plenty of RAM to spare.

The very best indicator of running low on RAM in my opinion is swap space usage. Very low swap usage is fine, but when it starts to become a significant amount (relative to the amount of physical RAM) it will affect performance. Nothing will kill performance like lack of RAM because it results in high swap file usage, and this tends to result in continuous disk activity (thrashing), grinding things to a halt.

To provide some rough percentages based on my opinion and experience (and the actual impact depends on the type of workload), swap file usage of about 5-10% of physical RAM means you are fairly moderately short on RAM, 20-30% it starts to get pretty noticeable and much above that it'll start to really hurt. Most OSs by default provide for something like 1 to 2 times the amount of RAM in swap space, but if you have anywhere close to that in actual swap usage, you probably won't have any performance left.

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
is my large folder zipped corrupted 4 66
Error Message during CentOS 7 Minimal Install 3 43
aws pricing 2 46
Can't ping New Linux Servers 40 66
Hyper-convergence systems have taken the IT world by storm and have quickly started to change our point of view of how the data center should and could be architected. In this article, I’ll explain the benefits of employing a hyper-converged system …
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question