Linux eats my memory.

Source: Internet
Author: User
Tags server memory

Linux eats my memory.

In the case of Windows Explorer to see memory usage, if the usage reaches more than 80%, then run the large program can feel the system is not smooth, because in the case of memory shortage using swap partition, frequently swapping out from disk to swap out page will greatly affect the performance of the system. When we use the free command to view the memory usage of the Linux system, we find that memory usage is always at a high level, even though the system does not run much software at this time. This is the difference between Windows and Linux in memory management, and at first glance, the Linux system eats our memory (Linux ate my RAM), but this is the memory management feature.

Linux eats my memory.
Free Command Introduction

The following is the result of using the free command to view our lab file server memory, and the-M option indicates the use of MB:

Linux eats my memory.

The second line of output represents the usage of system memory:

Mem:total (total) = 3920MB,

Used (used) = 1938MB,

Free (idle) = 1982MB,

GKFX (Shared memory) = 0MB,

buffers = 497MB,

cached = 1235MB

Note: The previous four items are better understood, buffer and cache can not find the right words to translate, the difference is:

A buffer is something that have yet to being "written" to disk.

A cache is something that have been "read" from the disk and stored for later use.

That is, buffer is used to store the data to be output to disk, while the cache is read from disk and stored in memory for future use. All of them are introduced to provide IO performance.

The third line of the output represents the-/+ Buffers/cache based on the second line:

–buffers/cache used = Mem used–buffers–cached = 1938MB–497MB–1235MB = 205MB

+ Buffers/cache free = Mem Free + buffers + cached = 1982MB + 497MB + 1235MB = 3714MB

The third line of the output indicates the usage of the swap partition:

Swap:total (total) = 4095MB

Used (use) = 0MB

Free (idle) = 4095MB

The swap partition is not used because the system currently has sufficient memory.

The result of the above output is more difficult to understand may be the third row, why to show the user this line of data? What does memory usage minus the memory representation of the system buffer/cached? What does the system free memory plus buffer/cached memory mean?
Classification of memory

We have divided the memory into three categories, from the user and operating system point of view of their use of different names:

Linux eats my memory.

The something in the table above represents exactly the "buffers/cached" Memory in the free command, since this memory is actually used from the operating system's point of view, but if the user wants to use it, this block of memory can be quickly recycled by the user program. Therefore, this memory should be zoned as idle from the user's perspective.

Returning to the output of the free command again, the result of the third line of output should be understandable, and the number in this line indicates the usage of the system memory from the user's point of view. Therefore, if you use the top or the free command to see how much memory is left in the system, you should actually add the buffer/cached memory to the idle memory, which is the actual system idle memory.
Buffers/cached Benefits

Linux memory management has done a lot of careful design, in addition to caching the Dentry (for VFS, accelerating file path name to Inode conversion), but also adopted two main cache mode: Buffer Cache and Page cache, in order to improve the performance of disk IO. Reading data from a low-speed block device is temporarily stored in memory, even though the data is no longer needed at the time, but it can be read directly from memory when the application next accesses it, bypassing low-speed block devices, thereby improving the overall performance of the system.

And Linux will make full use of these idle memory, the design idea is that memory is idle rather than to cache some data, and so the next time the program to access the data faster, and if the program to use memory and the system is not enough memory, this is not the use of swap partition, but quickly reclaim part of the cache, Leave them to the user program for use.

Therefore, it can be seen that buffers/cached is really hundred benefits without a harm, the real harm may allow users to create an illusion--linux consumption of memory! In fact, Linux does not eat your memory, as long as you have not used the swap partition, your memory is very little, you should be thankful, because Linux cache a lot of data, perhaps the next time you will benefit from it!
Experimental proof

The following is an experiment to verify the above conclusions:

We have read into a large file, comparing two reads into the practice:

Linux eats my memory.

As seen above, the first time to read this 1G file is about 18s, and the second time to read again, only time-consuming 0.3s, a full increase of 60 times times!
Resources:

Https://groups.google.com/forum/#!topic/shlug/Dvc-ciKGt7s/discussion Lab Seniors previously raised the "CP command takes up double memory problems", the discussion on Slug, It's the doubt that's always in my heart

http://www.11.qixoo.com.com/two days ago in hacker news see "Linux ate my Ram" This page, write easy to understand, but also to solve the heart of a lot of doubts

Http://www.linuxatemyram.com/play.html The author gives other experiments to verify the effect of disk cache on program allocation, swap partition, program load time, etc.

http://www.cnblogs.com/coldplayerest/archive/2010/02/20/1669949.html a blog about the free command

Linux eats my memory.

At present 100000+ people have been concerned about joining us

Linux eats my memory Linux eats my memory Linux eats my memory Linux eats my memory Linux eats my memory Linux eats my memory Linux eats my memory Linux eats my memory

Linux eats my memory Linux eats my memory Linux eats my memory Linux eats my memory Linux eats my memory Linux eats my memory Linux eats my memory Linux eats my memory


Linux eats my memory.

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.