How Linux uses commands to free memory

  
                

Linux computers have been used for a long time, and many of them are caused by insufficient memory. Users who use vps can easily find that the memory occupied by vps is very high. In order to ensure the normal use of the system, the system memory is released regularly. Importantly, the following is a way to clean up memory by command.

The WEB server built in the VPS runs for a long time, and the memory usage is occupied more and more. For the small memory VPS, the SWAP partition may be directly used, which affects the performance of the system application. . The following is a very simple script to clean up linux memory, as long as you put it into the crontab scheduled task, you can periodically clean up your Linux server memory.

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

where /proc/sys/vm/There are 4 values ​​in drop_caches, respectively 0-3:

0 – do not release

1 – release page cache

2 – release dentries and inodes

3 & ndash; the release of all cache

Scripting and script executable permissions given into the crontab which regularly perform:


supplement: free the memory manually 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”

The above is the way Linux uses commands to clean up memory. The main introduction is the command cleanup. Many tools can play a role in the release of memory.

Copyright © Windows knowledge All Rights Reserved