Computer Operating System Fundamentals (10)-Virtual Memory in Storage Management

introduction

This article is the tenth chapter, the virtual memory of storage management . Before we formally understand it, there is a question. A game has more than ten gigabytes and the physical memory is only 4 gigabytes. How does this game work? In order to solve this problem, we need the knowledge of virtual memory introduced in this article

Virtual memory overview

  • Some processes actually require a lot of memory, exceeding the capacity of physical memory
  • Multi-program design makes the available physical memory of each process more scarce
  • It is impossible to increase the physical memory indefinitely, there is always time when the physical memory is not enough

For these reasons, it causes a virtual memory technology generated

  • Virtual memory is the key technology of operating system memory management
  • Make multi-program operation and large program operation a reality
  • Divide the memory used by the program, and place part of the temporarily unused memory in auxiliary storage

For example:

The left side is the logical space of the process , the red part is the memory that a program needs to use, the operating system will load the memory into the physical memory, the gray part is the memory that is not used temporarily, this part will be put on the disk first, so You can save physical memory, let more physical memory be used by other processes, and, in this, if the logical space of this process is large, these are large and temporarily unnecessary space can be placed in the disk. Temporary custody

Principle of program locality

The principle of locality refers to the fact that when the CPU accesses the memory, whether it is accessing instructions or accessing data, the memory cells accessed tend to be gathered in a small continuous area . This principle is also a reason why virtual memory technology can be realized

Because of the principle of locality

  • Therefore, when the computer loads the program, there is no need to load all the logic space into the memory, just load the part (the part that needs to be used)
  • If it is found that the used memory is not in the physical memory, a page fault interrupt is issued , a page replacement is initiated, and the page saved in the auxiliary memory is replaced in the physical memory, so that the program can continue to run.
  • From a user perspective, the program has a lot of space, which is virtual memory

Virtual memory is actually an expansion of physical memory, the speed is close to the memory, the cost is close to the auxiliary memory

Virtual memory replacement algorithm

  • First-in-first-out algorithm (FIFO)
  • Least Frequently Used Algorithm (LFU)
  • Least Recently Used Algorithm (LRU)

Cache replacement timing

When the cache is replaced, it mainly occurs when the CPU needs to obtain the cache and finds that there is no corresponding data in the cache. At this time, the cache replacement will occur, that is, the required data is loaded from the main memory.

When to replace the main memory page

When the main memory page is missing, the relevant data will be loaded in the auxiliary memory. At this time, the main memory page will be replaced.

By comparison:

  • The replacement strategy occurs at: cache-main memory level, main memory-auxiliary memory level
  • Cache-main memory level replacement strategy is mainly to solve the speed problem
  • The main memory-auxiliary memory level is mainly to solve the problem of capacity (this is also the reason for the memory storage layering)

It is the core competitiveness of a technical person to find the constant in the rapidly changing technology. Unity of knowledge and action, combining theory with practice

Guess you like

Origin blog.csdn.net/self_realian/article/details/107103658