1

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.

H6.
  • 277
  • 6
  • 13
  • 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 03:24

2 Answers2

5

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.

Mike Scott
  • 7,903
  • 29
  • 26
  • 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
-1

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

Marki555
  • 1,488
  • 1
  • 14
  • 27