Linux kernel source code learning (5) swap in/out of Memory Page

Source: Internet
Author: User

Linux kernel source code learning (5) swap in/out of Memory Page

--- Flyli

 

The main purpose of physical Page Swap-in and swap-out is to swap infrequently used memory pages to the hard disk when the physical memory is insufficient to ensure normal operation of the program.

In computer theory, time resources and space resources are a pair of conflicting topics. We often see time-for-space or space-for-time algorithms, which cannot be evaluated separately, however, in the corresponding environment, there is always a better fit for us.

In linux, Page Swap is a typical practice of Time-to-space swap. When our memory is insufficient, I move the memory I don't need to use to the hard disk, then, increasing our memory and available space is indeed a good way, although the hard disk read and write speed is slow (this is why the memory in the same space is not as expensive as the hard disk ), however, it is much better to slow down than to open the program.

 

Today, I have read the chapter "linux kernel source code Scenario Analysis" about this content. To be honest, my memory is now 2 GB and I have always turned off the virtual memory when running linux, because my memory usage rarely exceeds 1 GB... So I don't really want to conduct in-depth analysis on this part of content. I wanted to find an article for reference on the Internet to ensure the continuity of the blog. Finally, I thought it was meaningless to copy it by referring to other articles, write it by yourself, by the way, huh, huh.

 

Like physical memory management, disk swap zone management also has a corresponding data structure to manage it, which is swap_info_struct. This structure contains the location and size of a SWAp area, usage and other information are declared in the source code in the form of an array. Through this struct, all swap intervals are managed. The specific management method is different from memory management, for example, if a user is released when it is used by multiple users, the user is only allowed to record the number of users. When the number of users is reduced to 0, the user is truly idle, in memory management, if a user releases the memory, and the user only uses the memory, in this case, the programmer's biggest headache is "segment error", also called "memory overflow "...

 

Basically speaking of the memory swap method, there is nothing to say about it. So far today, you can go to bed ~~~

Today, the company evaluated a new possible project and the results were good. Thanks to Wubq for help and zouj for help, but when it was done, they all left for work... Let them see it tomorrow. If possible, I should be responsible for this project. After all, I have already made the core part. Well, I have a good job, make more money, and buy a house early, but we still need to stick to the ideal.

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.