Study on the memory usage mechanism of Linux operating system

Source: Internet
Author: User
Tags memory usage

Linux generation and development, more applications and servers, then for the various management mechanism of Linux to be very clear, a complete Linux system is mainly storage management, memory management, file system and process management, such as a few aspects of the composition, posted some of the previous study of a good article. Share with you!

The following is the main description of swap and buffer cache mechanism

Linux supports virtual memory (virtual memory), which refers to the use of disk as a ram extension, so that the available memory size increases accordingly. The kernel writes the contents of the unused memory block to the hard disk, so that this memory can be used for other purposes. When the original content needs to be used, they are read back into memory. These operations are completely transparent to the user; A program running under Linux simply sees a lot of memory available and doesn't notice that part of it resides on the hard drive at times. Of course, reading and writing hard drives is much slower (thousands of times times slower) than using real memory directly, so the program won't be as fast as it has been running in memory. Part of the hard disk used as virtual memory is called swap space.

In general, pages in swap spaces are first swapped into memory, and if there is not enough physical memory at this time to accommodate them, they will be swapped out (into other swap spaces). If you don't have enough virtual memory to hold all of these pages, Linux will fluctuate, but after a long time Linux will recover, but the system is now unavailable.

Sometimes, although there is a lot of free memory, there will still be a lot of swap space being used. This can happen if, for example, there is a need to exchange at some point, but then a large process that takes up a lot of physical memory ends and frees up memory. The data that is exchanged is not automatically exchanged into memory unless it is needed. At this point the physical memory remains idle for some time. There's nothing to worry about, but it doesn't matter what it is.

Many operating systems use the method of virtual memory. Because they only need to swap space at run time to resolve not to use swap space at the same times, so in addition to the current operating system's swap space, the other is a waste. So it would be more efficient to have them share a swap space.

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

Linux systems often use swap space to keep as much free physical memory as possible. Even if there is nothing to do with memory, Linux will swap out memory pages that are temporarily unused. This avoids the time it takes to wait for the swap: When the disk is idle, you can exchange it in advance.

You can spread the swap space over several hard drives. This can improve performance for the speed of the associated disk and the mode of access to the disk.

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.