Memory Management in computer operating systems

Source: Internet
Author: User
ArticleDirectory
    • Why is swap used?
    • Swap space management
    • Process Entry and Exit:
    • Introduction
    • Page and physical block
    • Page size
    • Address Structure
    • Address conversion mechanism-page table
    • Basic address translation mechanism
Memory Management in computer operating systems Program Run

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

L compile: Compile the program into several target modules.

L 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.

L load: The loader loads the loaded modules into the memory.

 

We will discuss how to mount a module into the memory:

L absolute Loading Method: Compile the program to generate a target with an absolute addressCodeOnly applicable to single-channel program environments.

L relocatable Loading Mode: The obtained modules start with 0, and other addresses in the program are calculated relative to the starting address. In this case, the bit loading mode can be rewritten. Based on the memory, load the loaded module 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 transformation is usually completed at the time of loading, it will not be changed in the future, so it is called static relocation.

L Dynamic Running fashion import mode: In the previous method, the loading module can be loaded to any location in the memory. Therefore, it can be used in multi-channel program environments, but cannot be used to move the position in the memory when the program is running. 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, instead, the 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 negative effects of conversion, a relocation register is generally used.

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:

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

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

L 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.

Because swap partition allocation is a continuous allocation method, the swap space allocation and recovery are the same as the memory allocation and recovery methods in the dynamic partition mode. First-time adaptationAlgorithm, Loop first adaptive algorithm or the best adaptive algorithm.

 

Process Entry and Exit:

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

L 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 switch-in process, and replace it.

 

 

Introduction to 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 is page, it is called the paging storage management method; if it is a segment, it is called the segmented storage management method.

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 dividing the logical address space of a process 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, the page size is usually kb, and the page size is the power of 2.

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 address translation task is completed by using the page 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, the page table is generally stored in the memory. 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.

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.