preface

This article is a summary of learning when learning virtual memory. If there are any mistakes, please correct them.

The body of the

The source code is compiled and linked to generate an executable object file. Here is the structure of the executable object file again:

See summary – How the linker works for details

A page table

How does the CPU map virtual addresses to real addresses? The computer divides virtual addresses into pages of fixed size (say 64KB), and each page is represented by a page entry, thus forming a page table. Let’s take program loading as an example:

Through such a model, the working pressure of loader is greatly reduced. Loading has also become a seemingly easy task. Such a model seems to work well, but it will inevitably encounter a situation, assuming that we only have 4G main memory now, and assuming that 4G space is occupied. Now an application requests 4KB of space, what to do? The computer might think, “Oh hoo! Over calves, no space, direct abnormal report!” . Usually there is another solution, the operating system allows a certain space on the disk configuration development main memory (called virtual main memory), then the operating system will choose one or more pages in main memory out main memory, storage to the virtual main memory, modify the corresponding page table entry to put its status is not cache, and modify the pointer to the corresponding disk address. When the program accesses the page again, it calls from disk to main memory.

  • In this model, each process has its own completely independent address space, which greatly simplifies the complexity of address allocation when multiple processes apply for memory.
  • In this model, main memory acts as a cache for disks, perhaps similar to the L1 and L2 caches we discussed earlier. But there is one big difference between them. The cache and main memory cache blocks are mapped by address. The relationship between them is very absolute, and the handling of cache conflicts is very absolute and the flushing of conflicting blocks back to main memory. However, the mapping between virtual pages in virtual memory and disk is not one-to-one based on address, it is maintained by an additional page table. That is to say, only when the main memory is full, there will be insufficient space allocation, and dealing with this situation is not an absolute selection of a map page to call out main memory, determine which page to call out depends on the page scheduling algorithm of the operating system.