DJ4-1 memory hierarchy

Table of contents

4.1.1 Memory Hierarchy

1. Main memory (memory, main memory, executable memory)

2. Registers

3. Cache

4. Disk cache

Characteristics of the Memory Hierarchy

4.1.2 Purpose and function of memory management

1. Allocation and management of main memory

2. Improve the utilization of main memory

3. Expand the capacity of the main memory

4. Protection of storage space

4.1.3 Three ways of storage allocation

1. Direct designation method

2. Static allocation method

3. Dynamic allocation method

4.1.4 Basic concepts

1. Logical address (relative address, virtual address)

2. Physical address (absolute address, real address)

3. Three Spaces


 

4.1.1 Memory Hierarchy

Registers, caches, main memory, and disk caches are all under the jurisdiction of the operating system's storage management, and the information they store no longer exists after power failure. The low-level fixed disk and removable storage media are under the jurisdiction of device management, and the information stored in them will be preserved for a long time.

1. Main memory (memory, main memory, executable memory)

It is used to store programs and data when the process is running. The control unit of the CPU can only get instructions and data from the main memory to the CPU registers; similarly, the data in the CPU registers can be stored in the main memory. The exchange of data between the CPU and peripherals must rely on the main memory.

 

 

2. Registers

Used to store data when the processor is running. Registers are the fastest to access and work in harmony with the CPU.

3. Cache

Used to back up more commonly used data in main memory. The speed at which the CPU accesses the cache is between that of accessing main memory and accessing registers. According to the principle of locality of program execution, some frequently accessed data in the main memory are stored in the cache to reduce the number of accesses to the main memory and improve the execution speed of the program.

The principle of locality of program execution: In a short period of time, the execution of the program is limited to a certain part.

Some computer systems have two levels of cache, the first level cache and the second level cache.

4. Disk cache

It is used to temporarily store some frequently used disk data and information to reduce the number of disk accesses. To alleviate the speed mismatch between main memory and disk.

Disk cache is not an actual memory, but uses part of the storage space in the main memory to temporarily store information read or written from the disk. That is, a storage area in the main memory, corresponding to a fixed disk, temporarily stores disk data (such as data prefetch)

Characteristics of the Memory Hierarchy

① Tertiary storage, from cache to internal memory to external storage, the capacity of storage is getting bigger and bigger, while the speed of accessing data is getting slower and cheaper, and the price is getting cheaper. For example: the maximum transmission speed of the cache is a few tenths to a few hundredths of a nanosecond, while the transmission speed of the main memory is several nanoseconds.

The operation of these memories is coordinated by the operating system.

② The user's program should be stored in the main memory when it is running, so that the processor can access it.

Among them, direct access requires that the memory speed be as fast as possible to match the CPU instruction fetch speed, and the memory capacity needs to be large enough to hold the currently running program and data, otherwise the CPU execution speed will be affected by the memory speed and capacity. not fully exploited.

③ Due to the limited capacity and speed of the main memory, put the programs and data that do not need to be used immediately in the external memory, and read them into the main memory when needed.

4.1.2 Purpose and function of memory management

1. Allocation and management of main memory

  • Allocate appropriate storage space to corresponding jobs according to user requirements
  • It should be recycled as soon as the user is no longer using it, so it can be used by another user

To this end, this storage allocation mechanism should have the following three functions:

  1. Record the status of each storage space
  2. Implement storage allocation
  3. Accept storage space freed by the system or user

2. Improve the utilization of main memory

Enable multi-programs to dynamically share main memory and share information in main memory.

3. Expand the capacity of the main memory

With the help of virtual memory or other automatic overlay technologies, users are provided with an address space larger than the storage space of the main memory.

4. Protection of storage space

Ensure that each user job is operated in the allocated storage space without interfering with each other.

4.1.3 Three ways of storage allocation

Storage allocation, to solve the problem of sharing main memory among multi-task jobs. Determine when and how to allocate all the information for a job, or the information that the job needs first to run, into main memory, and make these issues as "transparent" to the user as possible.

1. Direct designation method

Programmers use actual storage space addresses when writing programs or compiling programs when compiling source programs.

  • In a multiprogramming environment, it should be ensured that the addresses used by each job do not overlap with each other.

The premise of using the direct designation method is that the available space of the memory is given or can be designated, which is no problem for a single-user computer system.

In the initial stage of multiprogramming development, the storage space is usually divided into several fixed partitions of different sizes, and corresponding partitions are assigned to different jobs. Therefore, the available memory space is known to the programmer or to the compiler.

The essence of the direct designation method is that when the programmer writes the program or the compiler compiles the source program, he needs to designate the location of all the information of a job in the main memory. Therefore, this directly specified storage allocation scheme not only makes users feel inconvenient, but also makes the utilization of storage space less effective. (shortcoming)

2. Static allocation method

The static allocation method refers to the method of allocating fixed storage space during the running of the program.

When the programmer writes the program or the compiler compiles the source program, he can start from the zero address of its address space; when the assembly program connects and loads it, it determines their corresponding positions in the main memory, so that Generate an executable program. That is, storage allocation is implemented at load time.


The characteristics of the static allocation method:

  • The full amount of storage required by a job must be allocated when it is loaded;
  • If there is not enough storage space, the job cannot be loaded;
  • Once a job enters memory, it occupies all the storage space allocated to it until it exits the system;
  • Jobs cannot be moved in memory during the entire running process, nor can they apply for storage.

The memory management of the static allocation method is very simple, but it cannot effectively share memory resources in a multiprogramming system.

  • The amount of storage required for a job must be estimated
  • May waste memory space due to locality of program execution

3. Dynamic allocation method

The characteristics of the dynamic allocation method:

  • The location of a job in storage space, also determined when it is loaded;
  • Additional storage space can be applied for as needed during its execution;
  • When part of the storage area occupied by a job is no longer needed, it can be requested to be returned to the system;

That is, this storage allocation mechanism can accept requests for unpredictable allocation and release of storage areas, and realize the allocation and recovery of individual storage areas.

  • The size of the storage area is variable;
  • Allows jobs to be moved in memory.

When the free storage space is scattered, move the jobs in the memory to piece together a complete storage space to store a new large job.

At present, most computer systems adopt static or dynamic storage allocation methods, so in this chapter, we only discuss the implementation technologies of these two storage allocation technologies, and focus on the realization of various dynamic storage allocation technologies.

4.1.4 Basic concepts

1. Logical address (relative address, virtual address)

The user's program is assembled or compiled to form an object code. The object code is usually in the form of a logical address, and its first address is 0, and the addresses in other instructions are all addressed relative to the first address.

Note: Logical addresses cannot be used to read information in memory.

2. Physical address (absolute address, real address)

The address of a storage unit in memory, which is directly addressable.

3. Three Spaces

① Name space: The space where the source program is stored is called the name space.

namespace 名空间名 {
    ...
}

② Address space: the set of addresses used by the program to access information, which is a set of logical addresses, generated by the compiler.

③ Storage space: a collection of actual memory unit addresses, which is a collection of physical addresses.

The size of the storage space is determined by the actual capacity of the memory.

  • The address space is a virtual concept, and the storage space is a real object.
  • When the target program needs to run on the computer, it is loaded into the storage space.
  • A job exists in different spaces before and after compilation and loading.

Guess you like

Origin blog.csdn.net/m0_64140451/article/details/130343676