How Linux uses commands to free memory
This article mainly explains "Linux how to use commands to release memory", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Linux how to use commands to release memory" bar!
The WEB server built in VPS runs for a long time, and the use of memory becomes higher and higher. For VPS with small memory, SWAP partition may be used directly, thus affecting the performance of system applications. Here is a very simple script to clean up linux memory. As long as you put it into the crontab scheduled task and execute it regularly, you can clean up your Linux server memory on a regular basis.
The code is as follows
#! / bin/bash
# Data is written to the disk cache
Sync
# Clean Page Cache
Echo 1 "/ proc/sys/vm/drop_caches
Sync
# Clean All Cache
Echo 3 "/ proc/sys/vm/drop_caches
There are 4 values in / proc/sys/vm/drop_caches, which are 0-3:
0-No release
1-release the page cache
2-release dentries and inodes
3-release all caches
Write a script and give the script executable permission to be executed on a regular basis in crontab:
Add: manual memory release method
The code is as follows
Sudo sh-c "echo 1" / proc/sys/vm/drop_caches "
Sudo sh-c "echo 2" / proc/sys/vm/drop_caches "
Sudo sh-c "echo 3" / proc/sys/vm/drop_caches "
Thank you for reading, the above is the content of "Linux how to use commands to release memory". After the study of this article, I believe you have a deeper understanding of how Linux uses commands to release memory, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!