How to release memory in linux

Source: Internet
Author: User
In linux, the memory release operation is in Linux. we generally do not need to release the memory because the system has managed the memory well. But there are exceptions in everything. sometimes the memory is occupied by the cache, which affects the system performance by using SWAP space, in this case, you need to release the memory. (in linux, we usually do not need to release the memory because the system has managed the memory well. But there are exceptions in everything. sometimes the memory will be occupied by the cache, which will affect the system's performance by using SWAP space. in this case, you need to release the memory (clear the cache. The caching mechanism in Linux is quite advanced. it will be used for dentry (for VFS, to accelerate the conversion from file path to inode) and Buffer Cache (for disk block read/write) and Page Cache (for file inode read/write. However, after a large number of file operations, the cache will basically use up memory resources. But in fact, we have completed file operations, and this part of the cache is no longer available. At this time, can we only watch the cache to occupy the memory space? Therefore, it is necessary to manually release the memory in Linux, that is, to release the cache. To release the cache, we need to first understand the key configuration file/proc/sys/vm/drop_caches. This file records the cache release parameters. the default value is 0, that is, do not release the cache. The value can be 0 ~ Any number between 3 represents a different meaning: 0-do not release 1-release page cache 2-Release dentries and inodes3-release all cache after knowing the parameters, we can use the following commands to perform operations as needed. First, we need to use the sync command to write all the unwritten system buffers to the disk, including modified I-nodes, delayed block I/O, and read/write ing files. Otherwise, unsaved files may be lost during the cache release process. # Sync next, we need to write the required parameters into the/proc/sys/vm/drop_caches file. for example, if we need to release all the caches, enter the following command: # echo 3>/proc/sys/vm/drop_caches this command takes effect immediately after it is input. you can check that the available memory is significantly increased. To query the parameters of the current cache release, enter the following command: # cat/proc/sys/vm/drop_caches
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.