I need your advice on using this script on my Gnu/Linux debian server.
The server is used to host a website using magento platform. I have noticed that every 2-3 days when I check the memory it is showing 5 to 7 GB free memory from total of 64 GB.
I came across this website: How to Clear RAM Memory Cache, Buffer and Swap Space on Linux.
Where the script is as follows:
#!/bin/bash # Note, we are using "echo 3", but it is not recommended in production # instead use "echo 1" echo 3 > /proc/sys/vm/drop_caches
- The question is this, is this safe to do?
- Can some damage happen, if I put this into crontab, that runs it 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 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
Which is better what does "sync" before the echo do?