Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My system is Centos 5.5 with 2G memory, I have no permission setup a swap. I have set restart mysqld, httpd in 3:00 every day with crontab, and I also want to free memory every hour.

So how to free memory with crontab? I write some code below styding from web, but it seems not work...

crontab -e

6 * * * * sync;echo 3 > /proc/sys/vm/drop_caches

EDIT here is my.cnf, however I need fulltext search sometimes used oderby date.

key_buffer_size = 256M
max_allowed_packet = 8M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 2M
myisam_sort_buffer_size = 256M
thread_cache_size = 8
query_cache_size= 128M
thread_concurrency = 8
share|improve this question
Why do you think you need to do this? What benefit do you believe you are getting? It sure seems like are making your system run worse. – Zoredache Mar 1 '12 at 7:36
@Zoredache, yesterday, I find my system out of memory, see, the system slowly and hard to do anything, even restart mysqld,httpd, finnally I reboot my server. So i am trying to find someway to free memory automaticlly. thanks. – yuli chika Mar 1 '12 at 7:47
Restarting services or the server is the wrong solution. Adjust the mysql configuration so that it won't go over certain limits. You could also setup something like monit so that it only acts when there is actually a problem. – Zoredache Mar 1 '12 at 7:54
@Zoredache, I have update my.cnf, is it set reasonable? thanks. – yuli chika Mar 1 '12 at 8:05
up vote 2 down vote accepted

The code you cited will cause the kernel to discard any cached data it has ... which is exactly the memory that it would have discarded as soon as anything wanted to use more memory anyhow. It will have no practical effect on your system.

Ultimately, other than running less software, or restarting processes, there is nothing you can do to reclaim extra memory. Linux has no mechanism to signal memory pressure to an application before killing it as "out of memory".

share|improve this answer
yesterday, I find my system out of memory, the server become slowlly, it is hard to access SSH via putty because always timeout, so I am try to find some way to avoid out of memory. – yuli chika Mar 1 '12 at 7:45
The approach you have cited above will absolutely, without doubt, not solve your problem. The only way to solve your problem is to run less software, or to make the software you run consume less memory. That requires specific configuration of the software in question, and cannot possibly be done in a generic way on that platform. – Daniel Pittman Mar 1 '12 at 7:48
the most problem maybe mysql, I have update my.cnf setting. thanks. – yuli chika Mar 1 '12 at 8:06

A better way to Free memory is to first know that what is eating up your EXTRA memory. To find it out, you can use command 'htop', which will tell you that which process is eating up how much amount of memory.

and check the memory with 'free -m' .

Then you have to ONLY restart that process or evaluate that why it is taking large amount of memory.

share|improve this answer
I find mysqld occupied 740MB, others, many php script, each cost 5-18MB... and if user online rising, the system will out of memory, and the server become slow... – yuli chika Mar 1 '12 at 7:59
Then i would recommend that you must carefully evaluate your application's memory requirements, may be it is taking much more memory. Otherwise you Must add more memory (And Swap as well), otherwise the server might crash as well, if it can out of memory. – Farhan Mar 1 '12 at 8:05

If you have a reasonable high hit rate on your server, why not consider adding more RAM? This should solve the issue after tuning mysql/httpd parameters to make sure it did not eat your memory again.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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