Operating system ~ high-speed cache technology ideas and virtual address memory technology ideas

Disadvantages of traditional memory management

**One-time: **The job must be loaded into the memory all at once before it can start running. This will cause two problems:
①When the job is very large, it can't be loaded into the memory completely, causing the big job to fail to run;
②When a large number of jobs are required to run, because the memory cannot hold all the jobs, only a small number of jobs can run, resulting in multiple jobs. The program concurrency drops.

Residency : Once the job is loaded into the memory, it will stay in the memory until the job is finished. In fact, within a period of time, only a small part of the data of the job needs to be accessed to run normally. This results in a large amount of temporarily unused data in the memory, which wastes valuable memory resources.

In order to solve the above problems, virtual memory technology is introduced according to the principle of locality

Principle of locality

Time locality : If a certain instruction in the program is executed, then this instruction is likely to be executed again soon; if a certain data has been accessed, the data is likely to be accessed again soon after. (Because there are a lot of loops in the program)

Spatial locality : Once a program accesses a certain storage unit, it is very likely that nearby storage units will be accessed soon. (Because a lot of data is stored continuously in the memory, and the instructions of the program are also stored in the memory sequentially)

Definition and characteristics of virtual memory

Based on the principle of locality, when the program is loaded, the part that will be used soon in the program can be loaded into the memory, and the temporarily unused part can be left in the external memory, and the program can be executed.

In the program execution process, when the accessed information is not in the memory, the operating system is responsible for transferring the required information from the external storage to the memory, and then continue to execute the program.

If the memory space is not enough, the operating system is responsible for swapping out temporarily unused information in the memory to the external memory.
Under the management of the operating system, it seems to the user that there is a memory much larger than the actual memory, which is virtual memory

Insert picture description here
Virtual memory has three main characteristics:
multiple times : it does not need to be loaded into the memory all at once when the job is running, but it is allowed to be divided into multiple transfers into the memory.
Exchangeability : It is not necessary to always reside in the memory when the job is running, but allows the job to be swapped in and out during the running process.
Virtuality : The memory capacity is logically expanded, so that the memory capacity seen by the user is much larger than the actual capacity.

Cache technology ideas

According to the principle of program locality, the data that will be frequently accessed in the near future is placed in a higher-speed memory, and the temporarily unused data is placed in a lower-speed memory.

For example, in the following code, when the while loop is executed, all the data of array a can be read into the cache
Insert picture description here

Guess you like

Origin blog.csdn.net/Shangxingya/article/details/113813724