Operating system learning notes-memory management

Source: Internet
Author: User
Tags field table

Operating system learning notes-memory management

The content of this article is as follows:

1. Purpose of Memory Management

2. core tasks of Memory Management

3. Various memory management methods:

3.1 partition management.

3.2 Page Management

3.3 segment Management

3.4 segment Page Management

 

1. Purpose of Memory Management

The main purpose of a computer is to execute a program;

The data accessed by these programs must be in the memory during execution (at least part of the data exists in the memory, such as using the virtual memory technology ).

 

CPU scheduling improves the CPU utility and response to users. To improve the performance of CPU scheduling, several processes must be saved in the memory at the same time.

There are multiple management methods for memory management. The purpose of these memory management methods is to save multiple processes in the memory at the same time to allow many program programming. At the same time, management overhead should be reduced.

 

2. core tasks of Memory Management: map the logical address space to the scattered physical address space.

There are two main points in this sentence. It is best to read them together several times.

1. Concepts of logical and physical address spaces

The logical address space is the address space corresponding to the logical address, also called the relative space, virtual space

The physical address space is the address space corresponding to the physical address, also known as absolute space.

 

The address generated by the CPU. The address in the instruction is the logical address (unless you program the address directly based on the physical memory, this method is basically not available now ).

The address of the physical memory unit. The address in MAR is the physical address.

 

2. What is ing?

How to map a logical address in a user program to an address in the physical memory during program execution is the work of the operating system.

FirstTo see how many steps the user program has taken to execute.

Source code, compilation (compile, which refers to the process of translating source code into the target file), link, load ), execute ).

Then,There are roughly three types of address ing time: compile-time ing, load-time ing, and runtime ing.

Compile-time ing,Ing during loadingDuring the compilation and loading phases, the physical address is generated. To execute the program, the memory at the physical address must be available, that is, it is not occupied by other programs,

Both methods are not conducive to program floating (only executed at a fixed address), and do not support virtual storage technology. during compilation, the ing method also requires you to understand the memory usage.

Runtime ingIt is to convert the Logical Address to the physical address at runtime, which facilitates program floating and supports virtual storage technology.

 

The core function of these memory management methods is at runtime (mostly)Map the logical address space to the scattered physical address space.

 

3. Various memory management methods:

Memory Management hasPartition Management,Paging Management,Segment Management,Segment and Page Management. The following describesBasic Ideas,Table Structure,Address ing,

Various management methods are introduced in terms of storage protection, Memory sharing, and memory fragmentation.

 

3.1 partition management.

Partition management supports single partition management and multi-partition management.

Single partition management: The user zone of the memory has only one partition, and only one program can be run at a time. For example, DOS.

Multi-partition management: Memory user partitions are divided into multiple partitions. Each partition runs a program at every time, supporting multi-program design and multi-partition management.Static partition managementAndDynamic partition management.

Static partitions: during system initialization, the system divides the memory into multiple partitions. The number of shards is fixed and the size is fixed. Each partition can only run one program at a time, and a fixed Partition Table is used, recording the location, size, and usage of a partition will produce inner fragments.

Dynamic partition. during system initialization, the user zone memory is only divided into one partition, and the memory is allocated as needed. You need to maintain the Partition Table-manage allocated partitions and idle partition tables-manage idle partitions,

The Partition Distribution algorithms include First-fit, Best-Fit, Worst-Fit, and First-fit, which scan the idle part in sequence. If a hole is larger than or equal to the required size, the partition is allocated. Best-Fit, scan and find the smallest hole of the size equal to or greater than the required size;

Scan Worst-Fit to find the largest of the hole larger than or equal to the required size. Will generate external fragments.

Address ing is as follows:: PA indicates the physical address, LA indicates the Logical Address, base register indicates the start address of the partition, and limit register indicates the size of the partition.

PA = LA + base register

3.2 Page Management

Basic Ideas

Split the physical memory into blocks (frames and frames), and split the job pages (pages). The frames and pages are of the same size.

Page-based memory allocation.

Each page of a job in the memory may not be in a consecutive physical frame, but the page is continuous in a memory block.

You need to use a page table to record frame usage, including allocated, idle, and frame numbers corresponding to page numbers.

The logical address is divided into two parts: page number and page offset)

Allocation example

Address ingAs follows: PA = LA + base register

If the page table is in the memory, at least the instruction should be obtained from the memory, read the page table, and find the frame number read address three times to read the memory, impact efficiency,

You can use hardware support to improve efficiency. You can use TLB, translation look-aside buffers, bypass conversion tables, or associativememory associated storage to search for content quickly and improve efficiency.

Memory Protection

Memory sharing:Condition

Code can only be shared, and it is a read-only pure code that is not self-modified, and the code that can be shared must appear in the same location of their respective logical spaces. Private code and data cannot be shared.

Easy to generate internal fragments

3.3 segment Management

Some facts:

Paging Problems

Inconsistency between the actual memory and the memory that the user understands

Difficult to share (a separate module may be divided into multiple pages)

 

Generally, a program

Main program and several subprograms, functions, processes, methods, etc.

There are also several data structures: tables, stacks, arrays, variables, etc.

Users' Opinions

Each part of the program is a logically independent unit.

It is recommended that you manage the logical unit in the memory.

Easy to share

Basic Ideas

Job segmentation, memory management by dynamic Partition

Memory Allocation in Segments

Each segment has a segment name and length.

A job can be discontinuous in the memory, but continuous in a segment

Logical Address format: <segment number, intra-segment Offset>

Use the field table-the correspondence between the record segment and the memory location

Example

Address ing

Memory Sharing: Condition

Code can only be shared, and it is a read-only pure code that is not self-modified, and the code that can be shared must appear in the same location of their respective logical spaces. Private code and data cannot be shared.

 

3.4 segment Page Management

Basic Ideas

The job is segmented first, each segment is paged, and the memory is divided into pages equal to the page;

Each segment has a segment name;

Memory Allocation is measured in pages;

Each job has a field table that records the starting address and length of the segment in the memory;

Each segment also corresponds to a page table;

Logical Address format: Segment number, intra-segment offset (page number, intra-page offset)

Address ing

 

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.