Memory Management in computer operating systems

Source: Internet
Author: User
Tags field table

Program running

To convert a user's source program into a program that can be executed in the memory, follow these steps:

1. Compile: Compile the program into several target modules.

2. Link: a set of target modules formed after compilation by the linking program and the library functions they need are linked together to form a complete loading module.

3. Load: The loader loads the modules into the memory.

For more information, seeLoad Module, Load memory:

1. Absolute Loading Mode:Compile the programGenerate the target code with an absolute address, which is only applicableSingle ProgramEnvironment.

2. relocatable Loading Mode: all modules obtained areStart with 0The other addresses in the program areRelative to the starting addressIn this case, the Mount mode can be relocated. According to the memory, the Mount module is loaded to the appropriate location of the memory. Generally, the modification process of commands and data in the target program during loading is called relocation. Because address translation is usually completed at the time of loading and will not be changed in the future, it is calledStatic relocation.

3. Dynamic Running fashion import mode: the previous method can load the loaded module to any location in the memory, so it can be used in multi-channel program environments, but it does not allow the running of the program to move the location in the memory. The dynamic running Fashion import mode does not immediately convert the relative address in the loaded module to an absolute address after loading the memory, but insteadThe address translation is postponed until the program actually needs to be executed.. Therefore, all the addresses after the memory is loaded are still relative addresses. In order not to affect the adverse effects of conversion,Relocation register.

Program Link

After the source program is compiled, a set of target modules can be obtained. Then, the linked program links this set of target modules to form the loaded modules. Based on the Link Time, links can be divided into the following three types:

1. Static link: before running the program, link the target modules and their linked libraries to a complete assembly module.

2. Dynamic Link during loading: when loading a series of target modules into the memory, the link of edge loading and link is used.

3. Dynamic Link during running: this refers to the link to some target modules. It is linked only when the module is required during program execution.

Swap: Why swap?

In a multi-program environment, some processes in the memory are blocked because an event has not yet occurred, but it occupies a large amount of memory space. On the other hand, other jobs are stored and waiting. This creates a waste. Therefore, the concept of "Swap" is referenced.

Swap refers to the transfer of processes or programs and data that can be run in the memory or temporarily not used to external memory, in order to free up enough memory, then, transfer the programs and data required by processes or processes that already have running conditions to the memory.

If the swap unit is the entire process, it is called the overall swap, if the swap unit is a segment or page, it is called part swap.

Swap space management

In OS with swap function, external storage is usually divided into file zone and swap zone. The former is used to store files, and the latter is used to store processes exchanged from memory.

The partition is allocatedContinuous allocationSo the swap space allocation and recovery are the same as the memory allocation and recovery methods in the dynamic partition mode. Generally, the first adaptive algorithm is used, and the first adaptive algorithm or the best adaptive algorithm is used for loop.

Process Entry and Exit:

1. If a process is blocked or has the lowest priority, the program and data are usually swapped out to the swap zone.

2. The system should regularly check the status of all processes, find out the "ready" status but the process has been switched out, replace the process with the longest time as the process, and replace it.

Basic paging Storage Management Methods

The continuous allocation method forms many fragments. Although many fragments can be spliced into available large blocks through the "Compact" method, great overhead is required. If you allow a process to be directly distributed into many non-adjacent partitions, you do not have to compact ". Based on this idea, a discrete distribution method is generated. If the basic unit of discrete distribution isPageIs calledPaging Storage Management; If yesSegmentIs calledSegmented Storage Management.

In paging storage management, if the Page Swap function is not available, it is referred to as the Basic paging storage management mode or the pure paging storage management mode. It does not support implementing the virtual memory function. It requires that each job be loaded into the memory before it can run.

Page and physical block

Paging storage management refers to the processLogical Address SpaceIt is divided into several equal parts, called pages. It also divides the memory space into storage blocks with the same size as the page, called physical blocks or page boxes. Because the last page of the process is often filled with less than one piece, it forms an unusable part, called "intra-page fragmentation"

Page size

The page is too small, which can reduce page fragments and improve utilization. However, this will make the page table too long. If the page is too large, the page can be very short, but the page fragmentation is too large. Therefore, we generally choose a moderate size, and the page size is the power of 2, usually512b-8kb.

Address Structure

The addresses in the paging address are as follows:

A total of 32 bits, 0-11 bits are the displacement (page address, so a page is 4 kb), 12-31 is the page number, so a maximum of 1 m pages are allowed.

Address conversion mechanism-page table

To change the logical address in the user address space to the physical address in the memory space, you must set the address conversion mechanism in the system. The basic task of this organization is to convert the Logical Address to the physical address. Because the addresses on the page correspond to the addresses in the physical block one by one. Therefore, you only need to convert the page number of the Logical Address to the physical block number in the memory.

The page ing table (page table) is used to transform the page number from the page number to the physical block number. Therefore, the task of address transformation relies onPage table.

Basic address translation mechanism

The page table function can be implemented by using a set of special registers. A page table item is implemented using a register, but the page table is too long, the register is small, and expensive. Therefore, we usually place the page table inMemory. In the system, only one page table register PTR is set, and the address and size of the page table stored in the memory are set. When the program is not executed, these two values are placed in the PCB. When the scheduler schedules a process, the two data are loaded into the page table register. Therefore, in a single-processor environment, although multiple processes can be run in the system, only one PTR can be used.

When a process needs to access data in a logical address, the paging address translation Organization automatically divides the valid address into two parts: page number and page address. Then, the page table is retrieved Based on the index of the page number. Search operations are performed by hardware to improve efficiency. First, determine whether the table is out of bounds. If the table is not out of bounds, add the product of the Beginning address of the page table and the length of the page table item to obtain the position of the table item in the page table, then you can get the physical block number of the page and load it into the physical address register. At the same time, the page address in the valid address register is sent to the block address field in the physical address register. This completes the transformation from the logical address to the physical address.

Address translation mechanism with a fast table

Because the page table is stored in the memory, the CPU needs to access the memory twice each time a data is accessed.

The first time is to find the physical block number of the specified page, and then add the physical block number and the address in the page to get the physical address.

The second time, find the corresponding data from the address obtained for the first time.

Is there any improvement solution now. Can I skip the first access? If you do not need it, you should store the page table or a part of the page table.

To increase the speed of address translation, you can add a special high-speed buffer register with parallel search capabilities in the address translation mechanism, also known as the "Lenovo register" or a fast table.

The address transformation process is like this:

After the CPU provides a valid address, the address translation mechanism automatically sends page number P to the cache register and compares the page number with all page numbers in the cache, if there is a page number that matches this, it is sent to the physical address register. If the corresponding page table item is not found in the quick table, you must access the page table in the memory. After finding it, send the physical block number read from the page table item to the address register, and save the table items on this page to a break-through unit in the table, that is, refresh the table. However, if the table is full, the OS must find an old page table item that is no longer considered necessary and replace it.

Due to cost considerations, quick tables cannot be too large, and generally only store16-512Page table items.

The current computer can also have two levels and multi-level page tables

Basic multipart Storage Management Methods

If the main motivation for promoting storage management from fixed partitions to dynamic partition allocation and then to paging storage management is to improve memory utilization, we will introduce the segmented storage management method, this is mainly to meet the programming and usage requirements of users (programmers.

1) convenient programming

Generally, users divide their jobs into several segments according to the logical relationship. Each segment starts from 0. It also has its own name and length. Therefore, the logical address to be accessed is determined by the segment name and the intra-segment address offset. Run the following command:

Load 1, [a] | <D> indicates that the value in Unit D of segment A is read into register 1.

2) information sharing

The sharing of programs and data is based on the logical unit of information. For example, if a function is shared, the page is only a physical block that stores information and does not have the complete meaning. The segment is the logical unit of information. To achieve segment sharing, we hope that the storage management can adapt to the Organization Mode of user program segments.

3) Information Protection

It also protects the logical unit of information.

4) Dynamic Growth

In practical applications, some segments, especially data segments, are constantly increasing, but the size cannot be known in advance. Segment Storage Management can solve this problem well.

5) Dynamic Link

Before the job runs, it does not link several target program segments. To run the program, first load the target program corresponding to the main program into the memory to start running. When a certain segment is called during the running process, the segment is transferred to the memory and connected. It can be seen that dynamic links also require segments as management units.

Basic principles of a segmentation system

1. Segmentation Principle

In the segmented storage management mode, the address space of a job is divided into several segments, each of which defines a set of logical information. For example, the main program segment, subroutine segment, data segment, and stack segment. For the sake of simplicity, a field number is usually used to replace the segment name. Each segment starts from 0 and uses a continuous address space.

A job is a two-dimensional job because it is divided into multiple segments. Therefore, logical addresses are composed of segments and segments.

2-segment table

In the segmented Storage Management System, a continuous partition is allocated for each segment, and each segment in the process can be discretely moved into different partitions in the memory. To enable the program to run normally, that is, to locate the corresponding location of each logical segment from the physical memory, as in the paging system, a field ing table is created for each process in the system, "Field table" for short ".

Each segment occupies one table item in the table, which records the starting address and segment length of the segment in the memory. The field table can be placed in the register, which improves the address conversion speed. But more often, the field table is placed in the memory. After the field table is configured, the process in progress can find the memory zone corresponding to each segment by searching the field table. It can be seen that the field table is used to realize the ing from the logic to the physical memory zone.

3. address conversion mechanism

In order to transform the logical address of a process to the physical address, a field table register is set in the system to store the start address and length of the field table. During address translation, the system compares the segment number in the logical address with the segment table length. If the segment number is too large, it indicates that the segment number is out of bounds, resulting in out-of-bounds interruption information. If the field table is not out of bounds, use the field table's start address + field number to obtain the item of the field table. Then, the base address of the segment is found. Then, determine the size of the displacement and the length of the segment. If the segment is out of the boundary, the information about the out-of-boundary interruption is found; otherwise, the physical address can be found.

4. Differences between paging and Segmentation

1) pages are physical units of information, and pages are used to achieveDiscrete allocationMethodReduce the external zero header of the memory,Improves memory usage. Paging is only for the purpose of system management, while segmentation is for the needs of programmers.

2) The page size is fixed and determined by the system. The system divides the logical address into two parts: the page number and the address in the page, which are implemented by the machine hardware. Therefore, there is only one page of length in the system. The length of the segment is not fixed. The length of the segment is determined by the user-compiled program. Usually, the Compilation Program is divided according to the nature of the information when compiling the source program.

3) The address space of the paging job isOne-dimensional, That is, a single linear address space, while the segment job address isTwo-dimensional.

Segment-and-page storage management

We know that paging is acceptable.Improves memory usageAnd segmentInformation Protection, information sharing, dynamic links, and dynamic growthWait, can it be combined into one? This is the segment-based storage management.

Basic Principles

First, the user program is divided into several sections, and then each segment is divided into several pages. If a job has three segments, the page size is 4 kb. In a segment-based system, the address structure consists of the segment number, segment-based page number, and page address. For example:

Address conversion process

To facilitate address conversion, a field table register must be configured to store the start address and length of the field table. The process is as follows:

In a segment-based system, three accesses to the memory are required to obtain a data.

1. Access the memory field table for the first time and obtain the starting address of the page table;

2. The second access is to access the page table of the memory and obtain the physical block number;

3. The third access is to extract commands and data from the address actually obtained from the second access;

Basic concepts of virtual memory

In the two storage management methods mentioned above, both require that a job be loaded into the memory before it can run. Therefore, there are two situations:

1. Some jobs are very large and it is impossible to load the memory at once.

2. A large number of jobs are required to run, but since the memory capacity is insufficient to accommodate all these jobs, only a few jobs can be loaded into the memory for them to run first, and put a large number of other jobs on external storage for waiting.

Solve the above problem:

1. The most common is to expand the memory. However, this is often restricted by the machine itself and will undoubtedly increase system costs;

2. Another method is to logically expand the memory capacity, which is the virtual storage technology.

Introduction of virtual memory

Features of conventional storage management

1. One-time: one-time loading.

2. Resident: the job has been resident in the memory since it is loaded into the memory until the job stops running. Although there may be multiple Io operations throughout the process, it still occupies the memory.

Locality Principle

1. Time constraints: If a command in the program is executed, the command may be executed again soon. If a data is accessed, the command may be accessed again soon.

2. Space limitations: Once a program accesses a certain storage unit, the nearby storage unit will be accessed soon, that is, the address accessed by the Program within a period of time, it may be concentrated within a certain range. A typical example is sequential execution.

Virtual Memory Definition

It refers to a storage system with the request transfer and replacement functions that can logically expand the memory capacity. The logical capacity is determined by the memory capacity and external capacity. The running speed is close to the memory speed, and each cost is close to the external memory. So it is a good solution.

Virtual Memory Implementation Method

Its implementation is based on the discrete distribution of storage management methods. There are two methods:

1. Paging Request System

2. Request Segmentation System

Memory Management in computer operating systems

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.