Operating System Exam Review - Chapter 4 Memory Management 4.1 4.2

Memory hierarchy:

Multi-layer structure of memory:

Memory is divided into at least three levels: CPU registers, main memory and auxiliary memory.

But it is generally divided into six layers : registers, cache, main memory, disk cache, fixed disk, and removable storage media.

The speed of these parts decreases but the storage capacity increases .

 Only the information stored on fixed disks and removable storage media will be preserved for a long time, and the stored information will not disappear when the power is cut off. The information of registers, cache, main memory and disk cache will not be saved after power off. Registers and caches are also called executable memory.

Main memory and registers

  1. main memory.
    Main memory is referred to as memory or main memory. Since the access speed of the main memory is much lower than the speed of the CPU executing instructions, in order to alleviate this contradiction, registers and caches were introduced in the computer system.
  2. register.
    Registers have the same speed as the processor. It's fast but expensive so the capacity is low. Mainly used to store data when the processor is running. For example, registers are used to store operands, or used as address registers to speed up address conversion, etc.

Cache and disk cache

1. Cache

Cache is a memory between registers and memory. It is mainly used to back up the more commonly used data in main memory. Its capacity is much larger than a register, but about two to three orders of magnitude smaller than a memory.
According to the principle of locality of program execution (that is, the program will show locality rules when executed, and the execution of the program is only limited to a certain part in a short period of time), some frequently accessed information in the main memory is stored in In cache. When the CPU accesses a specific set of information, it first checks whether it is in the cache, and then takes it out for use directly, otherwise it reads it from the main memory.

2. Disk cache

Since the current I/O speed of the disk is much lower than the access speed to the main memory, in order to alleviate the contradiction in speed mismatch between the two. Therefore, temporarily storing some frequently used disk data and information in the disk cache can reduce the number of disk accesses. However, the disk cache is different from the cache. It is not an actual storage medium itself. Instead, it uses part of the storage space in the main memory to temporarily store the information read (or written) from the disk.

Program loading and linking:

To run a user program in the system, it must first be loaded into memory and then converted into an executable program. This usually requires the following steps: 1) Compilation. The compiler compiles the user source code
into Several target modules.
2) Linking. The linker links a set of compiled object modules and the library functions they require together to form a complete load module.
3) Loading, the loading program loads the loading module into the memory.

Program loading:

1. Absolute loading method:

This method can be used when only a single program can be run . After the load module is loaded into memory, the logical address in the program is exactly the same as the actual memory address.

2. Relocatable loading method

Using the relocatable loading method, the load module is loaded into the appropriate location in the memory according to the current situation of the memory. It is worth noting that when a load module is loaded into memory using a relocatable loader, all logical addresses in the load module will be different from the physical addresses actually loaded into memory. Usually the process of modifying the instructions and data addresses in the target program during loading is called relocation. And because the address transformation is usually completed once during loading and will not change later, it is called static relocation.

3. Loading method of dynamic runtime

The dynamic runtime loader does not immediately convert the relative address in the load module to an absolute address after loading the load module into memory, but postpones this address conversion until the program is actually executed. Therefore, all addresses after loading into memory are still relative addresses. In order for address translation not to affect the execution speed of instructions, this method requires the support of a relocation register.

Program link:

1. Static linking

Before the program is run, each target module and the library functions they require are linked into a complete assembly module and will not be disassembled in the future. When assembling these target modules into a load module, the following two problems must be solved:
1) Modify the relative address. This is because in all target modules generated by the compiler, relative addresses are used, and their starting addresses are 0. The address in each module is calculated relative to the starting address.
2) Change the external call symbol. The external call symbols used in each module are also converted into relative addresses.
A complete load module formed by this first link is also called an executable file.

2. Dynamic linking during loading

Refers to the object module obtained after the user source program is compiled. When loading into the memory, the linking method is used to load and link at the same time . This facilitates modification and updating before loading, as well as sharing of target modules.

3. Runtime dynamic linking

The linking of certain modules is postponed until the program is executed . That is, during the execution process, when a called module is found to have not been loaded into the memory, the OS will immediately find the module and load it into the memory. Link it to the caller module. Any target module that is not used during execution will not be transferred into memory and linked to the loading module. This will not only speed up the loading process of the program, but also save a lot of memory space.

Guess you like

Origin blog.csdn.net/m0_53345417/article/details/130534041