In our company, we have a cloud server running CentOS 7 as our demo server. However, the server’s MariaDB is always shutdown whenever our cronjob tries to restart the MariaDB server. The reason is because the server is running out of memory when the MariaDB server is restarting.
After monitoring the server’s resources usage using top or htop command, we noticed that the memory usage is always high because of the buffer/cache memory is holding the memory.
Linux always tries to use RAM to speed up disk operations by using available memory for buffers (file system metadata) and cache (pages with actual contents of files or block devices). This helps the system to run faster because disk information is already in memory which saves I/O operations.
Reference
The buffer/cache memory is actually useful for the server’s disk operations. However, it’s causing our website to fail. Therefore, we need to find a fix for it. After doing research online, we found a command which we can use to clear the buffer/cache memory.
/bin/sync && echo 3 > /proc/sys/vm/drop_caches
We then add the command above in our cronjob and run it before our cronjob to restart the MariaDB. After that, our server’s MariaDB never shutdowns by itself because of the insufficient memory anymore.
Hope the sharing would help others.
How to clear CentOS Buff/Cache Memory