Operating system memory management knowledge points

Source: Internet
Author: User

1. Multi-level memory

1) storage hierarchy can be divided into three layers: register, main memory (RAM), secondary storage (disk);

2) There are corresponding caches between different levels to reduce the degree of mismatch between different levels of reading and writing speed; In short, main memory is also the cache between registers and secondary storage;

3) Different levels of memory reading and writing efficiency is not the same, read and write faster, the higher the cost.

4) Register, main memory, cache, etc. belong to the category of operating system management, the data will be lost after power outage, and the disk belongs to the category of device management, the data will not be lost after power failure.

2. Program loading

1) Absolute Loading mode: The program compiles the address after the memory is loaded, the program's logical address and actual memory address exactly the same, do not need relocation, this method is only suitable for single-channel batch processing system;

2) relocatable Mount mode: Once the program is loaded into memory, recalculate its absolute address immediately, which is the logical address plus the address offset.

3) Dynamic fashion mode: After loading the program into memory, it does not calculate its absolute address immediately, but does not recalculate its absolute address until the module is really needed.

3. Program Link mode

1) Static Link: directly to the target module and the required library link to become a whole, the link will not be opened after completion;

2) dynamic Link when loading: When the program is loaded into memory, the edge is loaded into the side link, which facilitates the sharing of each target file;

3) dynamic link at runtime: When a module needs to be linked;

4, Memory allocation method

Continuous allocation: The program is loaded into a contiguous area of memory

1) Single continuous allocation: only applicable to single-user single-tasking operating system

2) fixed partition allocation: Divides the memory area into multiple partitions, each partition is loaded into one job, and the fixed partition size can be divided into two ways: equal, unequal, equal may cause memory wasting or some large programs cannot be loaded.

3) Dynamic Partition allocation: the establishment of an idle partition chain or an idle partition table, when the need for memory, in the chain to find the size matching memory area;

Partition matching algorithm: The first adaptive algorithm (the area that the first block size satisfies), the cyclic first-time adaptation algorithm (from the place of the last search to find, compared to the previous method, can make the free partition more uniform), the best adaptive algorithm (Can meet the requirements, and is currently the smallest free partition, resulting in a lot of small fragments can not be reused), the worst-fit algorithm (always pick the current maximum partition for the job to use, the advantage is that the free partition is not too small to use, but will make the memory of the maximum storage space), fast adaptation algorithm (Create multiple linked lists, the same size of the free partition into the same linked list, need to use, directly remove the corresponding list of the first partition for the program to use, do not cut, but will cause partition recycling complex).

4) Partner system: Regardless of the allocated partition or unallocated partition, its size is 2 K power, this method allocation and recycling can cause multiple cuts, each cut is divided by 2.

5) hashing algorithm: The partition size as a keyword, when used to remove the corresponding partition address;

There are two solutions to the problem of not having enough room to load the job:

1) relocatable partition allocation: When the sum of the fragmented partition size is larger than the memory required by the program, the memory can be organized in a "compact" way, the scattered areas are stitched together, and other programs need to be relocated.

2) Swap: Pull out the memory temporarily unable to run the process or the temporarily unused program and the data to the external memory, frees up enough memory space. The units of the swap can be: process, page, paragraph;

Discrete distribution method

1) Paging storage: Divides the logical address space of the process into several equal-sized pages, divides the memory space into equal-sized blocks of storage, loads the pages of the process into memory-space blocks (the storage blocks are not necessarily contiguous), and establishes a mapping of the page table-page to the physical block. page Table Structure: page number block number

Page Size Determination: The page is too small, causing the page table to be too large, the page is too large, resulting in excessive page fragmentation (the last page of each job is often unsatisfactory);

Page Table: the page table is saved in the page number and physical block number mapping, the page table generally resides in memory, page table registers are stored in the page table of the beginning and page table length;

When the CPU needs to read a certain data, it first accesses the in-memory page table, obtains the corresponding physical address, and then accesses the memory again to get the required data, so it needs to access memory two times. In order to improve the efficiency of access, you can store a fast table in the cache, a fast table with part of the page number, the CPU needs to read the data, you can first find the corresponding page number in the Fast table, if not found again to the memory of the lookup.

When the logical address space is very large, the page table is also very large, the workaround: A Level Two page table or just a subset of the page table into memory.

2) Segmented storage: The program by function divided into several different sizes of segments, the storage location of the segment can be discontinuous. Segment Table structure: Segment number start address segment

Pagination and Segmentation differences: The page is the physical unit of information, the page itself has no actual meaning, mainly to improve the use of memory efficiency, and the paragraph is the logical unit of information, the paragraph has its complete information, mainly to meet user needs; the size of the page is fixed and equal, its size is determined by the system, and the segment size is not fixed Its size is determined by the program written by the user, the address space of the page is one-dimensional, only the physical block number, and the address space of the segment is two-dimensional, not only the physical segment number, but also the offset address of the paragraph, pointing to the same data area, the number of Cong is generally less than the page table, when the data area The number of required segment tables is much smaller than the page table, and segments are more suitable for information sharing.

3) segment page storage: Each segment is divided into several pages, the address structure: Paragraph number, the page number in the paragraph, the page address; When the CPU reads the data, it first accesses the memory segment table, reads its segment start address and section length, accesses the page table in memory for the second time, reads the corresponding physical block number, and then reads the data So it takes three times to access the memory.

5. Virtual memory

When the job is large or has a large number of jobs to run, it causes insufficient memory; solution: Extend the logical memory.

1) Base:

Local principle: In a relatively short period of time, the execution of the program is confined to a certain part, accordingly, the storage space it accesses is also confined to a certain area;

2) Virtual Storage:

Before the program runs, it is not necessary to load all modules into memory, only the required pages or segments are loaded into memory, the remainder is persisted on the disk, and when the memory is low, the temporarily unneeded segments or pages are swapped to disks, which is equivalent to extending memory.

3) virtual memory features: multiple times, a job is divided into memory operation, switching, allowing the job to be swapped out at runtime, virtual, the user sees the memory capacity is much larger than the actual capacity;

4) Virtual Memory implementation method:

(I) Paging Storage Management Method

A, three elements: page table mechanism, missing pages interrupt mechanism, address transformation mechanism

B, page replacement algorithm: The best replacement algorithm (the eliminated page will never be used later, perhaps in the longest time is no longer accessed page, the method can not be implemented, only for evaluation of other methods), FIFO page replacement algorithm (Always eliminate the first page to go into memory, that is, choose to retire the page that has been in memory for the longest time), the most recent unused displacement algorithm (choose the most recent unused page to displace, hardware support required), the least use of the displacement algorithm (Choose the most recent period he uses the fewest pages as the elimination page, need hardware support), the page buffer algorithm (the page will be eliminated temporarily does not move out of memory, but instead of moving to a linked list, and then moved out after a certain number)

C, Paging policy

Paging time: Pre-paging policy (based on prediction), request paging policy

Where to page: external memory can be divided into two parts, a file area for storing files and a swap area for storing the swap pages. The swap area is usually continuous storage, while the file area is a discrete store. So the I/O speed of the swap area is high.

When the swap space is sufficient, all pages should be copied to the swap area before the program is run, and the required pages will be swapped from the swap area.

When the system lacks swap space, files that are not modified are swapped in directly from the file area and do not have to be swapped out because they will not be modified and swapped in directly from the file area when needed again. For the part that may be modified, you need to swap out to the swap area and swap in from the swap area when needed.

Unix mode, for non-appearing unification from the file area, and for the occurrence of the swap area from the exchange.

(II) Segmented storage Management method

A, three elements: Paragraph table mechanism, missing segment interrupt mechanism, address transformation mechanism

6, segmented sharing: Set up a shared segment table, maintain the number of processes shared by each segment count, when Count==0, the segment can be recycled.

Operating system memory management knowledge points

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.