Virtual memory 1

5.1.1 The basic concept of virtual memory

1. The introduction of virtual memory

Wherein 1) in a conventional storage management

Storage management approach described in the previous chapter referred to as conventional memory management, the following two features in common:

(1) at once. We can only begin to run after the job must be loaded into memory all at once before running.

(2) of the resident. After the job into memory, they remain resident in memory until the end of the job to run.

- and dwell-time properties, many programs do not run in or temporarily unused memory space occupied by a program or data set large, so that some of the job need not be loaded run run; and if a program memory space required exceeds the actual memory capacity of M, then the program must fit into memory to run.

2) principle of locality

Locality can be expressed in two ways:

(1) temporal locality. If the program Cao of an instruction upon execution of the instructions may soon be executed again; if a data is accessed, then shortly after the data can be accessed again. Typical causes temporal locality there is a big circulation procedure.

(2) spatial locality. Program visited a storage unit, then shortly after, near the storage unit will be accessed, an address that is in a period of time the program accessed, may be concentrated in a certain range, which is typically the order of execution of the program.

 

2. Definitions and Characteristics of virtual memory

Based on the principle of locality, before running an application and need not all be loaded into memory, only that part of the current shall start to run programs and data loaded into memory when running the program, and the rest still reside on external memory, when you want to perform instructions or data access is not in memory, then the request is transferred through an automatic function 0S them into memory, so that the program can continue execution: at this time, if the memory is full, the need to pass the permutation function, the temporary memory the unused programs or data transferred to disk, after free up enough memory space, then you want to access a program or data into memory, so the program continues. In this way, they make a big-inch user program can run in less memory space: You can also load more processes at the same time in memory so that they are executed concurrently. From the user's point of view, the system has the most memory capacity than the memory capacity of the actual larger views, we have such a memory system functions and requests transferred permutation function, from a logical extension of the memory capacity to be referred to virtual memory.

Virtual memory has the following main features:

(1) multiple of. Storage Management conventional "disposable" On the contrary, the virtual memory into memory a job into multiple, virtual memory is M times of important features.

(2) to change properties. "Resident" of a conventional storage management contrast, during job runs, virtual memory allows the use of those programs or data temporarily adjusted from memory swapping K, to be later transferred to the memory as needed, thereby effectively improving memory utilization.

(3) virtual sex. Virtual memory is a logical extension to the memory of h, the user sees a large volume pier just a feeling, does not actually exist, so virtual. Virtual sex is the goal of virtual memory.

5.1.2 Implementation of virtual memory

1. Paging Request System

Paging request system is the addition of page requests paging and page replacement feature functions form a virtual storage system on the basis of the paging system. It allows users to program only a few pages into the program (and data) to start the run. Later, again replaced by paging functions and features page after another to the page is about to run into memory while running the page temporarily swapped out to the external memory. When replacement units of pages. In order to fulfill the request paging and page replacement feature, the system must provide the necessary hardware, software and implementation support demand paging.

Hardware Support

The main hardware support are:

(1) Request page table paging mechanism. It is increased, if the data structure is formed as a one thousand demand paging mechanism in the page table pure tab.

(2) page fault mechanism. Whenever you want to access the page the user program has not yet been transferred to the memory, it will produce a page fault, to request 0 S will be missing page into memory.

(3) the address conversion means. It is also the basis of pure paging address translation agencies on the development of formation.

1) Request paging software

This includes software for implementing the request paging and page replacement realization of software. They are in support of the hardware required for the program is running page (not yet in memory) into memory, and then temporarily unused memory page replacement from memory to disk.

2. Request section system

The system is based on a request segment of the segmented system, increasing the demand paging system virtual storage segment segment segment and the permutation function is formed. It allows the user to load the program as long as a few segments (but not all segments) to start running programs and data. After running segment will temporarily recall function by replacing the function call section and section, and then transferred segment is about to run. Replacement is performed in units of segments. In order to fulfill the request segments, the system also need the necessary hardware and software support.

1) Hardware Support

The main hardware support are:

(1) Request the segment table mechanism section. It is increased in several pure segment table mechanism section is formed as a request for the segment data structure.

(2) page fault mechanism. Whenever you want to access user segment has not been transferred to the memory, it will produce a short segment interrupt to request the missing section of the OS into memory.

(3) the address conversion means. It also is based purely on the segmentation address translation means formed on development.

2) Software Support

This includes a request for realizing the software tone segment and the segment permutation implemented software. They, with the support of the hardware, the first memory temporarily without replacement segment from memory to disk, and then the desired program is running section (not yet in memory) into memory.

 

5.2 Demand paging storage management

5.2.1 request paging hardware support

1. The requested page table mechanism

In demand paging system is the main data structure needed request the page table, the basic role of the logical address is a physical address in the user address space mapped into memory space.

 

 

 

Wherein each of the fields are now described as follows:

(1) status bit (presence bit) P: Since the demand paging system, only part of the application transferred to the memory, some are still in the external memory disk, it is required to increase the presence of a bit field in the page table. Since only one of the fields, it is also known bit word. It is used to indicate whether the page has transferred to the memory for reference when accessing the program.

(2) Access Field A: Page number recording for a period of time to be accessed, or has recorded how long the page has not been accessed recently, to provide a replacement algorithm (program) when changing the selected reference page.

(3) the modified bit M: after identifying the page into memory has not been altered. Since each page in memory of all keep a copy on the external memory, therefore, at the time of the replacement page, if not be modified, then you do not need to write the page back to the external memory to reduce system and pins Jian the number of startup disk: if has been modified, you must rewrite the page to the external memory, external memory in order to ensure a copy retained always up to date. In short, when the M-bit reference page for replacement.

(4) the external memory address: is used to indicate the page addresses in the external memory, the physical block number is usually for reference when transferred to the page.

  1. Memory Allocation

(1) the minimum number of physical block

(2) Memory allocation

① fixed <----> partially

② variable <----> partially

③ variable <----> Global

(3) allocation algorithm

① evenly

② pro rata

③ priority

  1. Call strategy

(1) When (pre-tune, tune request)

(2) where (Small: modified; in: transferred to the memory; Large: All)

4. The address conversion mechanism

Demand paging system address translation mechanism is based on the address conversion unit of the paging system for virtual memory, add some functions such as generating and page fault handling.

 

 

 

During address translation, first retrieve the table fast, try to find out the Court party page i want to ask. If found, modify the access-bit page table entries Cao, the reference time for replacement algorithm to scroll through the pages. For a write command, the position must be modified to "1" indicates the page has been modified into memory. Then use the physical block number and the page address page table entry physical address given form. Address translation process ends.

If the page is not found in the page table entry fast table, you should go into memory page table to find apricot, and then from page table entry found in the P status bit to see if the page has loaded into memory. If the page is already loaded into memory, then a page table entry should be written into the page table fast. When the table has full speed, you should call out to the page table entry of the page identified by an algorithm, and then write the page page table entry: If this page has not been loaded into memory, then the page fault to be generated Cao off, requests the OS from the external memory page into memory.

5.3 page replacement algorithm

1.FIFO

The process has been transferred to a memory page according to the order of the chain turn into a queue and set a pointer, called to replace the pointer so that it always points to the oldest page. But the law of the algorithm and the actual running processes are incompatible, because in the process, some pages frequently accessed, for example, a page containing the global variables, commonly used functions, routines, etc., FIFO algorithm can not guarantee that these pages are not to be eliminated. Here, we give an example, using the FIFO page replacement algorithm.

 

 

 

When the process first visit to page 2, page 7 will be swapped out, because it is the first to be loaded into memory: In the first visit to page 3, turn the page 0 swapped out, because it existing 2,0,1 three pages is the oldest of the page. As it can be seen from Figure 5-4, when using the FIFO method, conducted 12 page replacement, just more than the optimal replacement algorithm doubled.

  1. LRU

The reason why the FIFO replacement algorithm performance is poor, because it is based on the condition that each time a page into memory, and the page has redeployed does not reflect the usage of the page. LRU page replacement algorithm is to make decisions based on the use of the paged memory. Unable to predict future usage of each page, can only use the "recent past" as the "near future" approximation, therefore, LRU replacement algorithm is to select the least recently used page to be eliminated. The algorithm gives each page a visit field to a record since the last page is accessed since the elapsed time t, when the need to eliminate a page, select an existing page in its largest t value, that is least recently use the page to be eliminated. LRU algorithm by using the following Examples.

 

 

 

When the process first visit to page 2, page 7 is due to be accessed least recently, so it will be replaced out. When the process first visit to page 3, page 1 become the least recently used page, it will be swapped out. FIG dishes that can be, the same as the optimal image conversion method before buying five times, but this is not inevitable. Because the optimal replacement algorithm is from the "backward-looking" point of view, that it is judged based on usage after each page: The LRU algorithm is "looking forward", that is based on previous usage of each page to judge, but there is no necessary link between the past and the future direction of the page.

Additional an example, for a clearer understanding of FIFO and LRU

 

 

 

 

 

 

 

By the way, Belady described in this phenomenon .

Guess you like

Origin www.cnblogs.com/giaogiaogiao/p/12667062.html