Memory is one of the important resources of a computer system, any program, data, and each control data structure must occupy a certain storage space. Therefore, memory management directly affects system performance. Memory has memory
(
Main memory
)
Existence
(
Consolidate
)
Composition, memory consisting of sequential addressable
"
Block
"
composition.
CPU
only in
Start accordingly
IO
After the device, the memory can be made
versus
External exchange information.
Before the birth operating system, the usage of memory is often used in unmanaged mode, which is the simplest memory usage. Memory does not divide system districts and user regions, and user programs have complete control over the entire memory space and the entire computer. The advantage is that the pure hardware starts load, no other software support, and provides maximum flexibility, users can use any desired memory control. The disadvantage is that there is no convenience service, and the user must consider the whole, and physical details must be considered, and sometimes the means of covering, dynamic loading and other means to alleviate memory capacity. This chapter mainly discusses the basic management of memory in the operating system.
$ 4.1 Memory Management Overview
First, related basic concepts
1, partial principle
Experiments have shown that during the execution of a process, most of the code, data is not frequently accessed, that is, the CPU always accesses some part, rather than randomly having an average access probability of all parts. This phenomenon is called a partial principle. Compared with the number of times the CPU accesses the partial segment content, the change speed of the local segment is quite slow, which makes it possible to efficiently manage storage. In this way, the storage management system puts the contents of the processes in the process into the outer memory, and then transfer them to memory when they need to access them.
2, virtual memory
Due to the role of local principles, how should we arrange their addresses for some of the memory fraction in the case of the partial principle?
(1) Address method
Obviously, there are different addresses for different blocks. Currently, there are two ways to schedule the address of the target code:
1 Physical Address Law: Give the actual physical address according to the location in the physical memory, that is, the actual address (link to physical space) is determined by the compile link. In this way, the target code performs fast, but due to physical capacity limitations, the number of concurrent processes that can be loaded will be greatly reduced, and for larger processes, the required capacity cannot be operated if the actual capacity is exceeded.
2 Virtual Address Law: Compiling link to a linear or multi-dimensional virtual address space (logic space) that starts with 0, including static links and dynamic links. Thus, each instruction and data unit have a determined address in this logical space called a virtual address. Obviously, the process can be discontinuous in this logical space, and the corresponding management mechanism implements the transformation of the virtual address to the actual physical address.
(2) Virtual memory technology
Virtual memory is the core concept of storage management. We integrate virtual spaces consisting of target code, data, etc. in the process, called virtual memory, only specify the relative position of each process, without considering the actual location of information and physical memory. Each process has its own virtual memory, which is determined by the address structure and addressing method of the computer.
The inquiry is inherently incomplete loading of the program. The virtual memory is a technology proposed to improve the memory utilization. In an operating system, if the physical space actually occupied by any user program is not required to be greater than the logical address space equal to the user program, and the implementation of this function is transparent to the user (ie, the user does not have to know the operating system. How to achieve this function), the operating system is called the virtual memory technology, and the corresponding user process space is called the dummy space or the virtual address space.
The dummy is available in pages, segment virtual memory, and segment page type.
(3) The role of the virtual memory technology
The main feature of the virtual memory is that the operating system completes the transformation of the virtual to physical memory with the support of the corresponding hardware support, unified manages memory and external memory data and code automatic exchange. Since each process has a restriction of the physical memory size, its own virtual memory, and the system is not possible to provide enough memory to store all the content, so in memory can only store the content that is often accessed, those Information is not frequently accessed or not accessed in a period of time, and when the information is required during the process, the interrogation is transferred to the memory - ie exchange schedule. In the operating system, introduce the virtual memory technology, you can solve many technical problems, provide users with the greatest convenience, specifically, the benefits of adopting the virtual memory technology: 1 can solve the problem of large procedures in small space, That is, the user program can be run on a physical space that is much smaller than the actual logical space of the user program.
2 Improve the memory utilization, increase the number of ways, improve CPU utilization and system throughput (but the response time or rotation time may not increase). In an execution of a process, those code pages and data pages that do not execute or accesses will never enter memory.
3 Relative to the exchange technology, the virtual memory reduces the amount of IO required to load or exchange. The virtual memory is in units of pages (or segments), while simple switched technology (overall switching techniques) are in units of space at each time switch.
4 relative to override, the user (program) does not have to divide the cover block, simplify the user's programming task.
5 Reduce the burden of user storage management to concentrate on application development. Users don't have to consider the problem of space size and what related technologies (such as coverage), do not have to consider the actual address, do not have to consider the cave in the surprises.
The disadvantage of using the virtual memory is to slow down the speed of the program. So if the funds are sufficient, it is equipped with a large amount of memory. But if the funds are insufficient, and the program is running slowly, then the false memory is a good choice.
3, address transformation
A collection of computer's memory addresses is called memory space or physical address space, which is a one-dimensional linear space. The so-called address transformation refers to the unique one-dimensional physical linear address space of several virtual linear spaces or multi-dimensional linear spaces "transform" to memory. It contains two questions: Division issues of virtual space, address mapping issues (address relocation).
(1) Division of virtual space: (This main guidance compiler, the work of the link)
That is, how the processes are placed in the virtual space (logic space), which is related to the computer architecture, usually divided into system space and user process space, and then more detailed in their respective spaces. Divide.
(2) Address mapping problem: (This mainly guides the work of memory assembly process)
That is, put the content that has been linked in the virtual space into the corresponding memory and map the virtual address to the memory address. Address mapping is to establish a virtual address and memory address, there are two specific methods: static address calibration and dynamic address relocation
a) Static address relocation: That is, the mapping work is completed by the assembly process prior to execution of the virtual space, complete the different continuous address transformations of each first address, but does not require hardware support, but the virtual memory cannot be implemented, and the exchange technology is not supported. Once the program is loaded, it cannot be moved and exchanged, and all the relevant parts must be loaded into memory before execution.
b) Dynamic address relocation:
That is, the content (code, data) address to be accessed is converted into a memory address before the program execution of the CPU, which is completed by the hardware address transform mechanism.
Physical linear address = base address program virtual address
The relocation process of the CPU in the protection mode is to "convert" the relocation information table in the program file "Convert" as a plurality of "descriptive table" information in the process space. If the interrupt relocation information forms an interrupt description table IDT, the local variable relocation information forms a local description table LDT, all variable relocation information forms a full description of the table GDT, and then create a task status description information table SST, stores each tablet store (IDT) , The entrance description of the LDT, TSS is also placed in GDT, setting the process ready state and stores in the ready queue, waiting to be scheduled (execution time description table inlet is stored in GDTR, LDTR, IDTR, TR). The main advantages of dynamic address reprinted are:
· You can discontinuous allocation;
· Provide the basis for realizing virtual memory;
· It is conducive to the sharing of processes and threads.