0

I need your professional advice on using this script on my linux debian server...

The server is used to hosting a website on Magento platform and I have noticed that each 2-3 days when I check the memory its showing like 5-7 GB free memory from total of 64 GB of used...

so I camed across this website :

https://www.tecmint.com/clear-ram-memory-cache-buffer-and-swap-space-on-linux/

Where the script is following:

!/bin/bash # Note, we are using "echo 3", but it is not recommended in production instead use "echo 1" echo echo 3 > /proc/sys/vm/drop_caches now the question is this is this safe to do ? can some damage happen if i put this into crontab that runs this daily ?

they have stated the following :

Is it a good idea to free Buffer and Cache in Linux that might be used by Linux Kernel? When you are applying various settings and want to check, if it is actually implemented specially on I/O-extensive benchmark, then you may need to clear buffer cache. You can drop cache as explained above without rebooting the System i.e., no downtime required.

Linux is designed in such a way that it looks into disk cache before looking onto the disk. If it finds the resource in the cache, then the request doesn’t reach the disk. If we clean the cache, the disk cache will be less useful as the OS will look for the resource on the disk.

Moreover it will also slow the system for a few seconds while the cache is cleaned and every resource required by OS is loaded again in the disk-cache.

I am also wondering i noticed on some other websites the command to load up the memory looks like this :

!/bin/bash

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

So which is better what does "sync" before the echo do ?

Thanks for your explanation

0

I've taken the following excerpt from the tecmint thread you linked, since I feel it answers your question pretty well.

Is it good idea to auto clear RAM cache on production server?

No! it is not ... scheduled script run and clears everything in cache. Now all the user are fetching data from disk. It will result in server crash and corrupt the database. So clear ram-cache only when required,

If you are experiencing increasing memory usage over time, sounds like you have a memory leak somewhere. Instead of just flushing regularly as this will just suppress the actual issue, would be to identify whats causing the high usage and adjusting the code / config to reduce it.

You can find out whats using RAM by running top -c -o %MEM

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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