Computer Operating System Study Notes (3) --- Memory Management

Source: Internet
Author: User
Tags field table

 

I. Program loading and linking

It takes three steps to change a user's source code to an executable program: first, the Compilation Program compiles the source code into several target modules. Second, the linking program links these target modules and library functions into a complete loading module. Finally, the loader loads the loaded modules into the memory.

There are two ways to load a program: absolute loading mode and relocatable loading mode. Absolute loading means that the first address of the program is known before it is loaded into the memory, during the loading process, you only need to expand from the first address. The relocatable loading means that you do not know where the program will start loading before loading the memory, only the displacement of each statement relative to the first address is known. The first address is determined during loading. After confirmation, the address of each statement is obtained based on the displacement relative to the first address.

Program links can be divided into static links, that is, before the program is loaded, each target module and their required function libraries have been connected into a complete assembly module; dynamic links during loading, that is, when the program is loaded, each target module and the function libraries they need are connected into a complete assembly module, that is, the link for loading and changing the link; Dynamic Link during the runtime, that is, after the main program is loaded, which module is required to link the module during running;

Ii. Storage Device Allocation Method


1. single continuous allocation

The memory is divided into two parts: the system zone and the user zone. The system zone is only provided to the OS, and the user zone is provided to the user, that is, the entire user is allocated to the user for use; this method only applies to the operating system of a single user or task.

2. Fixed partition allocation

Divide the memory user space into several fixed-size partitions and create a partition use table for them. When a user program is to be loaded, the memory allocation program will retrieve the table, find a partition that meets the requirements and has not been allocated to it.

3. Dynamic partition allocation

According to the process, the memory space is dynamically allocated as needed, and the size is just right, so there is no waste of storage space. The data structure in partition allocation includes the idle Partition Table (a table is used to record the partition sequence number, start address, and size of each idle partition) and idle partition chain (use a pointer to connect each idle partition into a linked list. The partition allocation algorithm includes the first adaptive algorithm (the first suitable partition allocation is detected from the beginning) the first adaptive algorithm for loop (the first suitable partition allocation is detected from the last allocation position) and the best adaptive algorithm (the list of idle partitions is sorted from small to large, from scratch, we can find a partition not smaller than the size of the applied partition. When we cut down and apply for partition size allocation, the remaining partitions are inserted into the linked list, which may easily generate fragments ).

4. relocated partition allocation

Dynamic Allocation can cause many small idle zones that cannot be used, which are called "zero-header" or "fragments". In this case, you can relocate the addresses of multiple jobs distributed in the memory, concatenate or compact them, so that those "zero-header" or "fragments" are connected to a larger continuous storage space for allocation. The relocated partition allocation is basically the same as the dynamic partition allocation, except that the former adds a compact function.

5. Swap and coverage

Swap Technology: Transfers processes or programs and data that are temporarily unavailable in the memory to external memory to free up more memory space;

Coverage technology: a program is divided into several relatively independent functional blocks, so that those that do not execute at the same time share a piece of memory.

Iii. Storage Management


1. Paging Management

Page and page table: A process's logical address space is divided into several equal-size slices, called pages. The system creates a page ing table for each process, referred to as a page table.

Address conversion mechanism:

Basic: the page number of the logical address is used together with the start address of the page table in the page table register to obtain the page table entry address of the page number in the page table, obtain the first address of the physical block number corresponding to the page number from the page table, and then add the first address of the physical block number to the address of the Logical Address to obtain the physical address.

If there is a fast table: Add "Lenovo register" or "Fast table" to the basic address conversion mechanism and place some page tables in the fast table, if you find that there is no page table item corresponding to this page number in the quick table, search the page table in the memory. Remember to add the table items on this page to the quick table after execution.

2. Request paging Management

Request pagination is based on basic pages. In order to support the virtual memory function, the request paging and Page Replacement functions are added.

(1) Hardware Support

Page table mechanism: this mechanism is more effective than the basic page table (State bit P, access field A, modify bit M, and store address bit );

Page-missing interrupt mechanism: unlike general interruptions, it generates and processes interrupt signals during command execution, and a command may produce multiple page-missing interruptions during execution;

Address translation mechanism: it provides some functions than the address translation mechanism of the basic paging system, such as generating and processing page breaks, and switching a page from memory.

(2) Memory Allocation Policy

The allocation policies of physical blocks include:

Fixed allocation of local replacement means that each process is allocated a certain number of physical blocks. During page replacement, only one of the n pages of the process in the memory can be selected for replacement;

The global replacement of Variable Allocation means that a certain number of physical blocks are allocated to each process first, and the OS also maintains an idle physical block queue. When a process is missing a page, the OS will allocate it again, after replacement, you can select one of all pages of all processes for replacement;

The variable allocation is a local replacement, that is, a certain number of physical blocks are allocated to each process first, and the OS also maintains an idle physical block queue. When a process is missing a page, the OS will allocate it again, after replacement, only one page of the Process requesting page adjustment can be selected for replacement.

(3) Memory Allocation Algorithm

Physical block allocation algorithms include:

The draw allocation algorithm allocates all physical blocks in the system to each process on average;

The proportional allocation algorithm allocates physical blocks to each process based on the process size;

Considering the priority allocation algorithm, one part is allocated to each process proportionally, and the other part is allocated to each process based on the priority of each process, after appropriately increasing the corresponding share.

(4) page replacement policy

The external storage in the request paging system is divided into two parts: the file area used to store the file and the swap area used to store the swap area, usually because the swap area uses the continuous allocation method, the file area adopts the discrete distribution mode, so the disk I/O speed in the SWAp area is higher than that in the file area.

* The system has enough swap zone space to transfer all the required pages from the swap zone;

* If the system does not have enough swap area space and the page will not be modified, the page will be changed and transferred from the swap area;

* In UNIX mode, pages that have not been run are transferred from the file area. pages that have been run are transferred from the swap area.

(5) Page Replacement Algorithm

* Optimal Replacement Algorithm (Optimal): The selected page to be deleted will be a page that will never be used or will not be accessed for the longest time;

* FIFO algorithm: the Advanced page is replaced first;

* The least recently used replacement algorithm (LRU): An access field is added to each page to record how long the page has not been accessed, and the pages that have not been used for the most recent time are replaced first;

* Clock replacement algorithm: two access fields A and M are added to each page. A records whether the access is recently accessed (0 indicates that the access is not accessed), and M records whether the access is modified (0 indicates that the access is not modified ); search for the elimination page in three steps: the first step is to find the page (A = 0, M = 0), and the second step is to find the page (A = 0, M = 1, set all A to 0, and repeat Step 1 in step 3. If necessary, repeat Step 2. At this time, you can find the elimination page (A = 0, M = 0) or (A = 0, M = 1 );

3. segment Management

Segment and field table: a job is divided into several segments according to the logical relationship. The system creates a field ing table for each process, referred to as the field table.

Address conversion mechanism: the field number of the Logical Address is added to the start address of the field table in the field table register to obtain the field table items in the field table, so as to obtain the base address of the field number corresponding to the memory, the physical address can be obtained based on the base address of the memory and the address in the logical address segment.

4. Manage request segments

Request segments are also based on basic segments.

(1) Hardware Support

Field table mechanism: this mechanism is more effective than the basic field table (status bit P, access field A, modify bit M, external address bit, access method, and add bit );

Segment interruption mechanism: the interrupt signal is generated and processed during command execution, and multiple segment interruptions may occur during command execution, but segment information is a logical unit, it is impossible for an instruction or a group of information to be divided into two segments;

Address translation mechanism: it provides some functions than the address translation mechanism of the Basic Segmentation System, such as generating and processing segment interruptions, and switching a segment from memory.

(2) segment sharing and protection

You can configure a shared field table in the system. All shared segments have one table item in this table. Each table item includes the shared process count, that is, the number of processes in this segment are shared; the access control field, that is, different processes can have different access permissions. The segment number, that is, different processes can share the segment with different segments. There are also information such as segment length, memory start address, and bit existence.

Segment protection includes cross-border check and access control check.

5. Main differences between paging and Segmentation

(1) The page is the physical unit of information, while the segment is the logical unit of information;

(2) The page size is fixed and determined systematically, while the segment length is not fixed, and the programs written by users are different;

(3) The paging job address is one-dimensional, while the segmented job address space is two-dimensional. When a programmer identifies an address, he must give a segment name, you must also provide the intra-segment address.

6. segment-based Page Management

The segment-based mode not only effectively improves the memory usage like the paging system, but also satisfies user needs as well as the segment-based system:

Address conversion mechanism:


 


From Linuxer's Blog

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.