Study on memory usage mechanism in Linux

Source: Internet
Author: User
Study on memory usage mechanism in Linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. With the advent and Development of linux and more applications and servers, we should be very clear about the various management mechanisms of linux. A complete linux system mainly includes storage management and memory management, the file system and process management are composed of several aspects, and some good articles have been posted before. Share with you!

The following describes the swap and buffer cache mechanisms.

Linux supports virtual memory. virtual memory refers to the use of disks as RAM extensions, so that the available memory size increases accordingly. The kernel will write the content of memory blocks that are not currently used to the hard disk, so that this memory can be used for other purposes. When raw content needs to be used, they are re-read into the memory. These operations are completely transparent to users. Programs Running in Linux only see a large amount of memory for use, and do not notice that some of them reside on the hard disk from time to time. Of course, reading and writing hard disks is much slower than using real memory directly (several thousand times slower), so the program will not run as fast as it has been running in the memory. The hard disk used as the virtual memory is called the swap space ).

In general, pages in the swap space are first swapped into the memory; if there is not enough physical memory to hold them, they will be swapped out (to other SWAP spaces ). If you do not have enough virtual memory to accommodate all these pages, Linux will fluctuate and become abnormal. However, after a long period of time, Linux will recover, but the system is no longer available.

Sometimes, although there is a lot of idle memory, there is still a lot of swap space in use. This situation may occur. For example, if there is a need for swap at a certain moment, but then a large process that occupies a lot of physical memory ends and releases the memory. The exchanged data is not automatically exchanged into the memory unless necessary. In this case, the physical memory remains idle for a period of time. There is nothing to worry about, but it doesn't matter if you know what it is.

Many operating systems use virtual memory. Because they only need swap space at run time to avoid using swap space at the same time, except for the swap space of the currently running operating system, others are a waste. So it will be more efficient for them to share a swap space.

Note that if several people use this system at the same time, they will all consume memory. However, if two people run a program at the same time, the total memory consumption is not doubled, because only one copy of the code page and shared library exists.

The swap space is often used in Linux to keep as much free physical memory as possible. Even if there is no need for memory, Linux will swap out memory pages temporarily unused. This avoids the time required to wait for the swap: When the disk is idle, the swap can be done in advance.

Swap space can be dispersed on several hard disks. This improves the performance of related disks and access modes.

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.