Manually release memory on a Linux Server

Source: Internet
Author: User
Article Title: manually release memory on a Linux server. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

There are always some friends who have doubts about Linux memory management. The previous linux memory management method does not seem to clear everyone's concerns. In the core of the new version, it seems that a new solution has been provided for this problem, so we can refer to it here. Finally, I have attached my comments on this method. You are welcome to discuss it together.

When files are frequently accessed in Linux, the physical memory will soon be used up. When the program ends, the memory will not be released normally, but will always be used as caching. It seems that many people are asking this question, but they have not seen any good solutions. Let me talk about this.

I. general situation

Let's talk about the free command:

[Root @ server ~] # Free-m

Total used free shared buffers cached

Mem: 249 163 86 0 10 94

-/+ Buffers/cache: 58 191

Swap: 511 0 511

Where:

Total memory

Used memory used

Free idle memory

Total memory shared by multiple processes

Buffers Buffer Cache and cached Page Cache disk Cache size

-Buffers/cache (used) memory: used-buffers-cached

+ Buffers/cache (available) memory: free + buffers + cached

Available memory = free memory + buffers + cached

With this foundation, we can know that used is 163 MB, free is 86 MB, buffer and cached are 10 MB and 94 MB respectively.

Let's take a look at the memory changes if I copy the file.

[Root @ server ~] # Cp-r/etc ~ /Test/

[Root @ server ~] # Free-m

Total used free shared buffers cached

Mem: 249 244 4 0 8 174

-/+ Buffers/cache: 62 187

Swap: 511 0 511

After I run the command, used is 244 MB, free is 4 MB, buffers is 8 MB, and cached is 174 MB. Don't be nervous. This is to improve the efficiency of File Reading.

In order to improve disk access efficiency, Linux has made some careful designs, in addition to caching dentry (for VFS, accelerating the conversion of file path names to inode ), two major Cache methods are also adopted: Buffer Cache and Page Cache. The former is used to read and write disk blocks, and the latter is used to read and write inode files. These caches effectively shorten the time for I/O system calls (such as read, write, getdents.

Some people have said that linux will automatically release the memory used in a certain period of time. After waiting for a while, let's try again with free to see if there is any release?

[Root @ server test] # free-m

Total used free shared buffers cached

Mem: 249 244 5 0 8 174

-/+ Buffers/cache: 61 188

Swap: 511 0 511

There seems to be no change. (In practice, memory management is also related to Swap)

Can I manually release the memory? The answer is yes!

[1] [2] Next page

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.