Top Banner
1 CS 4410 Operating Systems Memory: Paging Summer 2011 Cornell University
23

Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

Apr 10, 2018

Download

Documents

lamtuyen
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

1

CS 4410Operating Systems

Memory:Paging

Summer 2011Cornell University

Page 2: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

2

Today● What is paging and why do we need it?● Paging● Address translation scheme● Page table● Implementation of page table● TLB● Structure of page table in memory

Page 3: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

3

Paging● Memory management scheme.● Noncontiguous physical address space of a

process.● The process is allocated physical memory wherever

the latter is available.● It avoids external fragmentation.

Page 4: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

4

Paging● Divide physical memory into fixed-sized blocks called

frames (size is power of 2, between 512 bytes and 8,192 bytes)

● Divide logical memory into blocks of same size called pages

● Keep track of all free frames.To run a program of size n pages, need to find n free frames and load program

● Set up a page table to translate logical to physical addresses

Page 5: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

5

Paging

Page 6: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

6

Address Translation Scheme● Address generated by CPU is divided into:

● Page number (p) – used as an index into a page table which contains base address of each page in physical memory

● Page offset (d) – combined with base address to define the physical memory address that is sent to the memory unit

p d

m - n n

page number

page offset

Page 7: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

7

Address Translation Scheme

Page 8: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

8

Address Translation Scheme0000 a0001 b0010 c0011 d0100 e0101 f0110 g0111 h1000 i1001 j1010 k1011 l1100 m1101 n1110 o1111 p

logical memory

00 10101 11010 00111 010

page table

00000

00100 ijkl

01000 mnop

01100

10000

10100 abcd

11000 efgh

physical memory

Page 9: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

9

Paging● User's view: memory is one single space● Actual view: the program is scattered

throughout physical memory● The OS manages physical memory.

● Frame table: Availability and owner of every frame

Page 10: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

10

Hardware Support● The OS allocates one page table per process.● A pointer to the page table is stored in the PCB.● The dispatcher defines the correct hardware

page-table values.

Page 11: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

11

Implementation of page table● Set of dedicated registers.

● Fast● Small

● In memory● Page-table base register (PTBR)● Slow● Large

● TLB + memory● Translation look-aside buffer● Special, small, fast-lookup hardware cache● Contains a few of the page-table entries● If page_number is in TLB get frame_number out

Page 12: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

12

Paging Hardware With TLB

Page 13: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

13

Memory Protection● Implemented by associating protection bit with

each frame.

Page 14: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

14

Shared Pages● Shared code

● One copy of read-only (reentrant) code shared among processes (i.e., text editors, compilers, window systems).

● Shared code must appear in same location in the logical address space of all processes

● Private code and data ● Each process keeps a separate copy of the code and data● The pages for the private code and data can appear

anywhere in the logical address space

Page 15: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

15

Structure of the Page Table● Hierarchical Paging● Hashed Page Tables● Inverted Page Tables

Page 16: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

16

Hierarchical Paging

Page 17: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

17

Hierarchical Paging● Two-Level Paging Example● A logical address (on 32-bit machine with 4K page size) is divided into:

● a page offset of 12 bits● a page number of 20 bits

● Since the page table is paged, the page number is further divided into:● a 10-bit page number ● a 10-bit page offset

● Thus, a logical address is as follows:

page number page offset

p1 p2 d

10 10 12

Page 18: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

18

Hierarchical Paging

Page 19: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

19

Hashed Page Tables● Common in address spaces > 32 bits● The virtual page number is hashed into a page table.

This page table contains a chain of elements hashing to the same location.

● Virtual page numbers are compared in this chain searching for a match. If a match is found, the corresponding physical frame is extracted.

Page 20: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

20

Hashed Page Tables

Page 21: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

21

Inverted Page Table● One entry for each real page of memory.● Entry consists of the virtual address of the page stored

in that real memory location, with information about the process that owns that page.

● Decreases memory needed to store each page table, but increases time needed to search the table when a page reference occurs.

● Use hash table to limit the search to one — or at most a few — page-table entries.

Page 22: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

22

Inverted Page Table

Page 23: Memory: Paging - Cornell University · 2 Today What is paging and why do we need it? Paging Address translation scheme Page table Implementation of page table TLB Structure of page

23

Today● What is paging and why do we need it?● Paging● Address translation scheme● Page table● Implementation of page table● TLB● Structure of page table in memory