(Study Notes - Memory Management) Virtual Memory

There is no operating system for single-chip microcomputers. Every time the code is written, the program needs to be burned into it with the help of tools, so that the program can run. In addition, the CPU of the single-chip microcomputer directly operates the [physical address] of the memory .

In this case, it is impossible to run two programs in memory at the same time. If the first program writes a new value at position 2000, it will erase everything stored in the same position by the second program, so it is impossible to run two programs at the same time. Crash immediately.

How does the operating system solve this problem?

The key issue here is that both programs refer to absolute physical addresses, which is what we want to avoid

We can [isolate] the addresses used by the processes, that is, let the operating system assign an independent set of [ virtual addresses ] to each process without interfering with each other. But there is a premise: each process cannot access the physical address. As for how the virtual address finally falls into the physical memory, it is transparent to the process, and the operating system has arranged all these clearly.

The operating system will provide a mechanism to map the virtual addresses of different processes and the physical addresses of different memories .

If the program wants to access the virtual address, the operating system converts different physical addresses, so that when different processes are running, different physical addresses are written, and there will be no conflicts.

So the concept of two addresses is introduced:

  • The memory address used by the program is called the virtual memory address
  • The space address actually stored in the hardware is called the physical memory address

The operating system introduces virtual memory, and the virtual address held by the process will be converted into a physical address through the mapping relationship of the memory management unit (MMU) in the CPU chip, and then access the memory through the physical address:

 How does the operating system manage the relationship between virtual and physical addresses?

There are two main ways: memory segmentation and memory paging

Guess you like

Origin blog.csdn.net/qq_48626761/article/details/131982547
Recommended