The difference between pagination and segmentation

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/wangrunmin/article/details/7967293

I. Paging Storage Management

1. Basic Ideas

The address space of the user program is divided into several fixed-size areas called "pages", where the memory space is divided into several physical blocks, and the size of the page and block is equal. Any page of the user program can be placed in any piece of memory to achieve a discrete allocation.

2. Paging storage-Managed address agencies

15 12 11 0

Page number p page Internal Displacement amount W

Page number 4 bits, each job up to 2 4 times = 16 pages, indicating the page number from 0000~1111 (24-1), the number of digits of the page displacement represents the size of the page, if the amount of displacement in the page 12 bits, 2 12 square =4k, the page size is 4k, the page address from 000000000000~ 111111111111

Given a logical address of a and a page size of L, the

Page number p=int[a/l], in-page address w=a MOD L

3. Page Table

In a paging system, each page of a process is allowed to be stored in the any physical block of memory in a discrete way, in order to be able to find the corresponding physical block of each page in memory, the system establishes a page map table for each process, called the page table. The purpose of a page table is to implement address mappings from page numbers to physical block numbers.

Page table:

Page number physical block number access control

0 2

1 (F)

2 (E)

3 1

4. Address transformation

(1) When the program executes, remove the page table starting address and Page table length (4) from the PCB, loading the page table register ptr.

(2) The paging address transformation mechanism automatically divides the logical address into the page number and the in-page address.

Example: 11406d=0010|110010001110b=2c8eh

Page number is 2 and the displacement amount is c8eh=3214d

or 11406 DIV 4096=2

11406 MOD 4096=3214

(3) Comparing the page number to the length of the page table (2<4), if the page number is greater than or equal to the page table length, the address of this access has exceeded the address space of the process, resulting in an out-of-bounds interrupt.

(4) Add the Product of Page table entry and page number and page table item length to get the position of the page table item in the page table.

(5) Remove the page description to get the physical block number of the page. 2 (E)

(6) Check the access control of the page.

(7) The physical block number into the physical address register, and then the valid address register within the page address directly into the physical address register in the Block Address field, splicing to get the actual physical address.

Example: 0010|110010001101b

1110|110010001101b=ec8eh=60558d

or 14*4096+3214=60558d

5. Address transformation mechanism with fast table

Paging system, the CPU each time to access a data, two times to access memory (access to the page table, access to the actual physical address). In order to improve the speed of address transformation, a special high-speed buffer memory with parallel query capability is added, called "Associative memory" or "fast table", which holds the page table items currently accessed.

Two Segmented Storage Management

1. Basic Ideas

The user program address space is divided into segments of varying sizes, each of which can define a relatively complete set of logical information. When storing allocations, segments and segments can not be contiguous in memory, and discrete allocations are realized.

2. Introduction of segmented storage mode

Easy programming

Segmented sharing

Segmented protection

Dynamic links

Dynamic growth

3. Segmented address structure

The address space for a job is divided into segments, and each segment defines a set of logical information. Examples of program segments, data segments, and so on. Each segment starts at 0 and takes a contiguous address space.

The length of the segment is determined by the length of the corresponding logical information group, and thus the length of each segment varies. The address space for the entire job is two-dimensional.

15 12 11 0

Displacement amount in segment number segment

Segment number 4 bits, each job up to 24=16 segment, indicating the segment number from 0000~1111 (24-1), paragraph displacement of 12 bits, 212=4k, indicating that each segment of the address of the maximum 4K (the length of each segment is different), from 000000000000~111111111111

4. Paragraph table

Segment number Start Address access control

0 1K 4096

1 4K 17500

2 2K 8192

5. Address transformation

(1). When the program executes, remove the segment table from the PCB and the length of the segment Table (3), loading the segment table register.

(2). The logical address is automatically divided into the segment number and the address within the segment by the segmented address transformation mechanism.

Example: 7310d=0001|110010001110b=1c8eh

Segment number is 1, displacement is c8eh=3214d

(3). Compare the segment number to the length of the segment table (1<3), if the segment number is greater than or equal to the length of the segment table, then the address of this access has exceeded the address space of the process, resulting in an out-of-bounds interrupt.

(4). Add the product of the segment table entry to the length of the segment number and the segment table, and get the position of the table entry in the Segment table.

(5). Remove the paragraph descriptor to get the beginning physical address of the segment. 1 4K 17500

(6). Check whether the amount of displacement in the paragraph exceeds the section length (3214<4k), if exceeded, resulting in a cross-border interruption.

(7). Check the access control of the section.

(8). Add the base and the address in the paragraph to get the actual physical address.

Example: 0001|110010001101b

Start address 17500d+ address in paragraph 3214d=20714d

Three The main difference between pagination and segmentation

There are many similarities between pagination and segmentation, such as neither of which requires continuous storage. But conceptually the two are completely different, mainly in the following areas:

(1) The page is the physical unit of information that is paged out for non-contiguous allocation in order to resolve memory fragmentation issues, or paging is due to system management needs. The segment is the logical unit of information, it contains a set of relatively complete information, the purpose of segmentation is to better realize the sharing, to meet the needs of users.

(2) The size of the page is fixed, determined by the system, the logical address is divided into the page number and the page address is implemented by the machine hardware. While the length of the segment is not fixed, it is decided by the user to write the program, usually compiled by the compiler when the source program compiled according to the nature of the information to divide.

(3) The paging job address space is one-dimensional. The address space for a segment is two-dimensional.

Four Segment-page Storage Management

1. Basic idea:

The paging system can effectively improve the utilization of memory, and the segmented system can reflect the logical structure of the program, facilitate the sharing and protection of the segment, combine the two storage methods of pagination and segmentation, and form a section-page storage management mode.

In a section-page storage management system, the address space of a job is first divided into logical segments, each with its own segment number, and then divided into several equal-sized pages for each segment. For main memory space is also divided into equal size pages, the allocation of main memory in page units.

In a section-page system, the address structure of a job contains three parts: the number of page numbers in the segment

According to the address structure of the segmented system, the programmer divides the address into the segment number and the displacement in the segment, and the address transformation mechanism decomposes the displacement into the page number and the amount of the page displacement.

To implement Segment-page storage management, the system should set up a segment table for each process, including the segment number for each segment, the page table start and page table length for that segment. Each segment has its own page table, the page number of each page in the record segment, and the physical block number stored in main memory.

2. The process of address transformation:

(1) When the program executes, remove the section table from the PCB and the length of the table, loading the section table register.

(2) The logical address is automatically divided into segment number, page number and address within the page by the address transformation mechanism.

(3) The segment number and the length of the paragraph table is compared, if the segment number is greater than or equal to the length of the paragraph table, then the address of this visit has exceeded the address space of the process, resulting in an out-of-bounds interrupt.

(4) Adding the product of the paragraph table's initial address and the length of the segment and segment table items, the position of the table item in the segment table is obtained.

(5) Remove the paragraph description to get the page Table start and page table length of the paragraph.

(6) Comparing the page number to the length of the page table, if the page number is greater than or equal to the page table length, the address of this access has exceeded the address space of the process, resulting in an out-of-bounds interrupt.

(7) Add the Product of Page table entry and page number and page table item length to get the position of the page table item in the page table.

(8) Remove the page description to get the physical block number of the page.

(9) Check the access control of the page.

(10) The physical block number into the physical address register, and then the valid address register within the page address directly into the physical address register in the Block Address field, splicing to get the actual physical address.

Five, found on the internet a comparative image of the metaphor, quite good, hehe, listed as follows:For example, you go to a lecture and take notes with a paper notebook. Notebook has 100 sheets of paper, the course has Chinese, math, English three, for the use of this notebook, in order to facilitate the review later, you can have two options.
The first is that you start with the first sheet of paper, and in advance in the book to make a division: the 2nd to the 30th piece of paper in Chinese notes, 31st to 60th paper Math notes, 61st to 100th paper in English notes, and finally in the first paper to make a list, record three notes of their respective ranges. This is the segmented management, the first piece of paper called the paragraph table.
The second is, you take notes from the second piece of paper, the notes of the various classes are linked together: the 2nd piece of paper is math, the 3rd is Chinese, 4th English ... Finally, you made a catalogue in the first piece of paper, recording the Chinese notes in the 3rd, 7, 14, 15 sheets ..., math notes in 2nd, 6, 8, 9, 11 ..., English notes in 4th, 5, 12 ... This is the paging management, the first piece of paper called the page table. You have to review which course, go to the page to search for the relevant paper number, and then turn to that page to review and then paste a post: Paging Concepts: Logical Space page Out, the physical space is divided, the page is the same size as the block, the page continuous block is discrete, page number is used to search the page table, the hardware is converted, the page and theMemory block size is generally selected as a power of 2 (easy to manage)
Page table function: Implementation of mapping from page number to physical address

Request page OutThe basic idea
1. Request page Out= page Out+ Request
2. Request paging provides virtual storage
3. The status bit in the page table entry indicates whether the page is in memory, and if not, produces a Missing pages Interrupt

Page replacement: Swap a page from memory to the swap area of the disk
Jitter: A phenomenon in which system efficiency is reduced due to frequent paging activity causing excessive number of accesses to the disk in a computer with virtual memory
Page orientation:

Commonly used page replacement algorithms:
Advanced first-out method: (More displacement times)
Best Replacement method (OPT): Select a page that will no longer be used in the future or will be accessed in the furthest future (not easy to implement)
least Recently Used displacement method (LRU): When you need to replace a page, select the longest unused page in the most recent time to retire
No Replacement method (NUR) has been used recently: An approximate method of the LRU algorithm that chooses pages that have not been visited in the most recent period of time to be eliminated

Segment-Type managementThe basic idea is:divide a program into segments by content or process (function), each with its own name (number)。 The virtual storage space for a job or process corresponds to a two-dimensional address consisting of a segment number (segment number: The offset within the paragraph), which forms the two-dimensional address directly in the process of compiling the link. Segment management allocates memory in segments, and then translates the segment virtual address into the actual memory physical address through address transformations. and theLike page management, segment management uses only those frequently accessed segments that reside in memory, and places those segments that are not accessed in the future into external memory, and automatically calls in when needed to implement virtual storage.

Segment management The virtual address space of a process is designed into a two-dimensional structure, that is, the segment number (segment number: offset within the paragraph) form. As mentioned earlier, and the page management compiler to produce a one-dimensional continuous address, the section of the management system compiled to form a number of paragraphs and paragraphs of the name or number, the number of paragraphs no sequence relationship. Unlike page-managed pages, the length of a segment is different, and each segment defines a set of logically complete programs or data. For example, in a DOS operating system, a program is divided into body segments, data segments, stack segments, and so on. Each segment is a one-dimensional linear space with a first address of O and a continuous

(turn) The difference between pagination and fragmentation

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.