Zend certified PHP/Magento developer

Linux debian automatic script to free up memory – advice

i need your proffesional 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