Operating system (10) - Virtual Memory

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/m0_37609579/article/details/102766162

First, the definition

A lot of memory in the computer role, computers all running programs need to be run through memory, or if the execution of a great many, it will lead to memory exhausted. To solve this problem, WINDOWS use of virtual memory technology, that is, to come up with a portion of the hard disk space to act as memory usage, this part of the space is called virtual memory , virtual memory on the hard disk is present in the form PAGEFILE.SYS the page file.

[Baidu Encyclopedia] virtual memory is a computer system memory management of a technology. It makes the application thinks it has available contiguous memory (a continuous full address space ), in fact, it is usually separated into a plurality of physical memory chips, and is temporarily stored in the external portion of the disk storage on the need when the data exchange . Currently, most operating systems use virtual memory, such as the Windows family of "virtual memory"; Linux "swap space".

Second, the virtual memory works

Virtual memory is stored information automatically scheduling and management of hardware and operating systems. Its working process comprising six steps: [3] 

  1. A central processor main memory is decomposed into a logical address of a group number B and the group address, and a group number for the address conversion, i.e. a logical group number as an index to search the address translation table, to determine whether the set of information stored in the in the main memory.
  2. If the group number is already in main memory inside, it is executed instead ④; if the group number is not in the main memory, it is checked whether there is an idle area in the main memory, if no, do not put a temporary tune the group taken secondary memory, the set of information transferred to the main memory.
  3. Group to be read out from the secondary memory, and the spare area to the main memory, and that the free physical group number and a logical set of a number registered in the address conversion table.
  4. Reads out a logical group number of a group number from the physical address conversion table.
  5. Physical address from the physical group number and a byte address within a group b.
  6. Access to the necessary information from the main memory according to a physical address.

Third, the virtual memory scheduling

Scheduling methods are paged, segmented, three kinds of page segments. Scheduling is a page logical and physical address spaces are divided into fixed-size page. Main memory in page order number, and each is independently addressable program space has its own page sequence number, may be discretely into main storage pages in different positions through the auxiliary storage page scheduler program, data table and eleven the corresponding retrieval. Page scheduling advantage is a small fraction of the page, the page table is transparent to the programmer, the address conversion fast, simple operation transferred; disadvantage of each page is not an independent program module is not easy to implement a program and data protection. Scheduling stage is divided by a logical structure of the program's address space, the length of segments is arbitrary, and allow elongation, it has the advantage of eliminating a fraction of the memory, the memory protection is easy to implement, easy to assemble dynamic program; disadvantage is transferred complicated operation . Combining the two methods together will constitute scheduling section page. In scheduling section in the page space into the physical page, program modules by segmented, each segment is subdivided into smaller physical space of the same page page. Page scheduling segment combines the advantages of segment and page style. The disadvantage is increased cost of hardware, software is also more complex. Most large-scale general purpose computer system with a page scheduling period.

1. Scheduling page

In paged virtual storage system, a virtual space is divided into pages of equal size, called logical pages or virtual page. Main memory space is divided into equally sized pages, called a physical page or a physical page. Accordingly, the virtual address is divided into two fields: the high field virtual page number, the page address field is low. Real storage address is also divided into two fields: the high field is a real page number, the page address field is low. Meanwhile, the size of the page are rounded to powers of 2 words.

It can be converted into a physical address by the page table virtual address. A page table is provided for each program, in the page table, the virtual page number corresponding to each of one entry, the entry comprising at least the contents of main memory page address (PPN) of the virtual page is located, using it as a real memory addresses the high field; in-page physical page number of the virtual address address spliced, it creates a complete existential address, upon accessing main memory.

2. Scheduling stage

Page in main memory physical space partitioned from the length of the fixed area and the like. Pagination advantage is that the page length is fixed, thereby facilitating configuration page table , easy to manage, and there is no external fragmentation. But the disadvantage is that the logical way paging size pages long and the program is not relevant. For example, there may be a certain time portion of a subroutine in the main memory and partly in the auxiliary storage. This is not conducive to independence in programming, and to swap in / swap-out processing, storage, protection and storage sharing operations cause trouble.

Another addressable memory space division method called segment. Segments are divided according to the natural process boundaries, the region length can be changed dynamically. Typically, the programmers subroutine divided into different types of data such as constants and operands into different segments, and each program may have a plurality of segments of the same type. 

In virtual storage system segment, and the segment number of the virtual address within the address segments, converting virtual addresses into real memory addresses achieved by the segment table. A table is provided for each program segment, each segment table entry corresponding to a segment, each entry includes at least three fields: a valid bit (indicating whether the segment has been transferred to main memory), from section address (in the segment existence of the first address) and the segment length (the actual length of the segment recording). 

3. Page scheduling section

Segment is paged virtual memory segment in conjunction with a virtual memory and a page of virtual memory.

First, the real storage is equally divided into pages. After the virtual memory page segment, the logical structure of the program segments, then each segment in accordance with the size of the paging existential page program operation according swapped in and out of the page, but it may be shared segment and protection. Thus, it can segment and combines the advantages of page mode system. Its disadvantage is the need to address multiple look-up table in the image process, the virtual address into a physical address is carried out by positioning a segment table and a set of page tables. Each entry in the segment table corresponds to a segment, each entry has a start address of the segment table page (page number) of the segment and points to the protective control channel segment page table indicates the pages in main memory and whether the position is loaded, modified, and other signs.

Fourth, the virtual memory scheduling

A virtual memory address translation there are three substantially shaped virtual memory operating procedure formula: Legend full conversion, direct conversion, and converting the group association. Any logical page space to physical space can be converted to any page position is called full associative transform. Each page of the logical space to physical space can transform a particular page is called direct conversion. Lenovo Group transformation means between the groups is a direct conversion, while the group through each page is full Lenovo transformation. Alternatively replacement rules for determining which part of the main memory, the main memory to vacate part, to be transferred to auxiliary storage storing part from that. Common replacement algorithm has four.

  1. Random algorithm: generator determines replace pages with software or hardware random number.  
  2. FIFO: first transferred to the main memory of the first page replacement.
  3. Least Recently Used algorithm (LRU, Least Recently Used): the longest time without replacing the page. 
  4. Optimal algorithm: page after replacing the most time before use. This is the ideal algorithm, only as a measure of the merits of various other algorithms. 

The efficiency of virtual memory is an important part of the performance evaluation system, which is related to the main memory capacity, page size, hit rate, program locality and replacement algorithms and other factors.

Fifth, the role of virtual memory

Virtual memory provides three important capabilities: cache , memory management , memory protection

  1. Regarded as the main memory address space is stored on a disk cache, main memory is stored only in the active area, and to transfer data between main memory and disk as needed
  2. Provides a consistent address space for each process, simplify memory management
  3.  Protection of each process's address space is not destroyed by another process

VI Summary

  1. Scheduling: deciding which programs and data should be transferred to the main memory.
  2. Address mapping problem: accessing the virtual main memory address stored physical address becomes the master (referred to as an address translation process); secondary memory when accessing the virtual address into a physical address of the secondary memory (a process known external address conversion) in order to feed. Moreover, it should solve the main memory allocation, memory protection and relocation program and other issues.
  3. Alternatively problem: deciding which programs and data to be transferred out of main memory.
  4. Update issues: ensuring consistency of main memory and secondary storage.

Under the control of the operating system, hardware and system software for users to solve these problems, so that greatly simplify the programming of the application.

 


My micro-channel public number: architecture Scriptures (id: gentoo666), shared Java dry, high concurrency programming, popular technical tutorials, and distributed micro-services technology, architecture, design, block chain technology, artificial intelligence, big data, Java interview questions, as well as cutting-edge information and so popular. Updated daily Oh!

Reference article

  1. https://baike.baidu.com/item/ virtual memory / 101812? fr = aladdin
  2. https://www.jianshu.com/p/baf3a13c47db

Guess you like

Origin blog.csdn.net/m0_37609579/article/details/102766162