Deep understanding of memory (3): Memory switching technology, virtual memory

Source: Internet
Author: User

We know that whenWhen multiple processes coexist in the memory, if the memory is sufficient enough, it would be ideal for everyone to have peace of mind.But the reality is often not that good. Sometimes the memory will be full,Not enough. At this time, the process must be moved from the memory to the hard disk. When there is space, it may be moved back to the memory.A professional point is called roll-out, roll-in, or exchange.

 

You may think of either of the two methods when performing a swap-out.

(1) Exchange in Process UnitsThis is the simplest and easiest way to think of, but it is obviously not flexible enough, because a process requires a large amount of memory space, so this exchange technology is currently not used much.

(2) only part of the process is exchanged.
Page-based or segmented Memory Management
First, divide the virtual address space of the process into several pages or segments, so that the page or segment can be exchanged during the switch.

 

Page Storage Management

The so-called paging refers to dividing the virtual address space of a process into a large, small, and even page.(In fact, the process is broken into several small pieces.) For example, if the page is 1 KPhysical memory is also divided into one pageAnd then map the two. For example, Ah found that sometimes say a bunch of words to learn as a map with, the following figure is copied from elsewhere, the original address of the image http://www.doc88.com/p-982340562158.html

 

Of course, the information of this ing relationship must be stored in the register. The process for finding physical addresses through logical addresses is as follows:

 

Segmented Storage Management

When paging is performed, it means that no matter which one of them is, all of them are one-size-fits-all.ProgramSplit into even one page. however, we know that a program actually runs into many modules. For example, a function may be a module. it may be more reasonable to divide the program into smaller components based on the logic structure of the program. because the program execution can also be divided into small units for execution. here we call the smaller unit of the program job

However, the concept of multipart storage management is the same as that of pagination management. It is easy to switch by dividing programs into smaller units.However, segments are not evenly divided into pages of a fixed size, but are divided into uneven segments based on actual conditions.At this time, because the segment sizes are different, in addition to knowing the start address of each segment, you must also have information on the segment table length.

 

Logical and physical address conversion is as follows:

 

 

Combine paging and Segmentation

Paging and segmentation naturally have their own advantages. If each segment is too large, it is not very good, it is better to simply switch the entire program out, so you don't have to worry about it.

So some people want to combine these two methods, called segment-page storage management. You need to use the paging technology again within a segment.

 

 

Virtual Memory

We previously talked about how to allocate 2 GB of virtual address space for every program running on Windows 32. if you increase the value, it can be 3 GB at most. in this sentence, we can extend some conclusions.

1. Because 32 system addressing space is only 4 GB, it is a waste of resources for your memory larger than 4 GB.. The system will only use 4 GB of memory.

2. You may think that every process is a virtual address space of 2 GB. Isn't it enough for a process to load into the memory? Actually, it doesn't becauseAllocate 2 GB address space to you. You may not use so much space., It may only use 10 MB. In this way, only the actually used memory is loaded. In additionThat is, it does not allocate the memory required by all processes at one time and then load the program.Instead, load the programs that are temporarily needed.CodeOr Data

3Because the maximum address space of each process is 3 GB.If your process requires 4 GB of address space to run, your computer will not be able to support it.So if some large games require a very large amount of memory, your 32 system won't be able to play.

 

In addition, you will certainly have questions. in the past few years, when we bought computers, it seems that many of them had 512 MB of memory, and even 1 GB was too much. then it is basically a 32 system. what if a program is actually useful for 1 GB memory? Although the virtual address space allocated in the program is used, if you actually use 1g in the 2G virtual address space, finally, we need to map it to the actual memory. in addition, you cannot repeat the 1 GB memory address. in this case, the 512 memory is definitely not enough.

AThe concept of virtual memory is to specify a part of the hard disk for memory usage. Virtual Memory is used when the memory actually used in the virtual memory space is larger than the physical memory.. In Windows, you can set the virtual memory size in advanced system settings. no matter if it is 32-bit, the virtual memory plus the actual memory must not be greater than 4 GB, otherwise the extra part will be useless.

Let's assume that the above example contains MB of memory and then 1 GB of process. you can get a 1 GB virtual memory. then, during the ing, the ing is first performed in the actual memory, and 300 is left in addition to the part required by the system. so we first map the 300 memory, and then map the remaining memory to the virtual memory.

You only need to send a logical address when using it,The operating system has an MMU (Memory Management Unit) with a page table. You enter the logical address and convert it to the physical memory address or hard disk address..

Details are troublesome. the general idea is that a process generally uses paging technology to divide the process into many pages of the same size, with numbers on each page. in the page table, the specific memory of each page is stored. when the number exceeds 300, it actually corresponds to the virtual memory. (In fact, it is a SWP file on the hard disk), there must be a sign that this part is on the hard disk. so when a process is running and needs to use an address, it will be mapped to the virtual memory. The so-called missing page will appear. The page is not in the memory, so we need to read data from the hard disk into the memory. If the memory is full, we need to replace some pages. therefore, you have set the virtual memory. If it is used at last, you will see that the hard disk is quickly converted, and then the program runs slowly. hard Disk operations are much slower than memory operations

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.