Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This question already has an answer here:

I am running a server with 24G of RAM. The only thing running here is a MySQL server configured as Master.

When I check the memory via free -m I am getting this:

             total       used       free     shared    buffers     cached
Mem:         24158      24027        131          0        131      23050

Approx. 23G is in cache. Which seems a lot to me.

I also set caching to 0 in the my.cnf

query_cache_size        = 0

How can I check what is exactly cached? Also a restart of mysql doesn't clear the cache. A flush tables also didn't help.

share|improve this question

marked as duplicate by Michael Hampton Aug 6 at 4:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
If you want the computer to use less RAM, remove some RAM from the computer. It's not like if you use only 12GB today you can use 36GB tomorrow. –  David Schwartz Dec 30 '11 at 3:24

2 Answers 2

up vote 5 down vote accepted

You're looking at two different caches. free -m tells you how much memory the operating system is using for the disk cache, not how much MySQL is using for the database cache. And the operating system should be using as much memory as it can for the disk cache -- why wouldn't you want as big a cache as possible? That memory is always available to be used if an application needs it. See here for a good discussion of Linux memory usage for caching.

share|improve this answer
    
Thanks a lot for this explanation and the fine link. –  High6 Dec 29 '11 at 18:38
    
This is precisely why 'free -m' has more lines of output, after the one that you showed above; the stuff after "+/- buffers/cache" shows how much RAM is actually being used. –  Keith Dec 30 '11 at 15:02

This means that almost all the memory is used by the kernel to cache data. You have probably almost idle system, so it doesn't matter so much, but to optimize it, you should look at the mysql config...

If you think you can benefit from query-cache, enable it and give it for example 128 MB. Then you can check in mysql how it is utilized. If you run mostly SELECT queries and not many INSERT/UPDATE, the query cache may be good for you. It very rarely causes issues, so you can safely leave it enabled.

Then if you are using MyISAM storage engine, so should enable some memory via kay_buffer variable. If using InnoDB, the general advise is to give 50-80% of available memory to innodb_buffer_pool_size (if this is dedicated mysql server). Mysql and InnoDB know better what exactly to cache than the linux kernel.

For freeing mysql (read) caches, I think only mysql restart helps. To free system caches, use command:

echo 3 > /proc/sys/vm/drop_caches

http://linux-mm.org/Drop_Caches

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.