Sie sind auf Seite 1von 77

MSc-IT

Operating System & Data Storage


Semester - I

Copyright Amity University


PAGING
(Cont)

Copyright Amity University


Divide physical memory into fixed-sized blocks
called frames (size is power of 2, between 512
bytes and 8192 bytes).

Divide logical memory into blocks of same size


called pages.

Copyright Amity University


Keep track of all free frames.

To run a program of size n pages, need to find n


free frames and load program.

Copyright Amity University


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

Internal fragmentation.

Copyright Amity University


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.

Copyright Amity University


Paging Hardware
Page Table Structure
Hierarchical Paging

Hashed Page Tables

Inverted Page Tables

Copyright Amity University


Hierarchical Page Tables

Break up the logical address space into multiple


page tables.

A simple technique is a two-level page table.

Copyright Amity University


Two-Level Paging Example

A logical address (on 32-bit machine with 4K page


size) is divided into:

a page number consisting of 20 bits.

a page offset consisting of 12 bits.


Copyright Amity University
Since the page table is paged, the page number
is further divided into:

a 10-bit page number.

a 10-bit page offset.

Copyright Amity University


Two-Level Paging Example (Cont..)

Thus, a logical address is as follows:


page number page offset
pi p2 d

10 10 12

where pi is an index into the outer page table, and


p2 is the displacement within the page of the outer
page table.

Copyright Amity University


Two-Level Page-Table Scheme
Address-Translation Scheme
Address-translation scheme for a two-level 32-bit
paging architecture.

Copyright Amity University


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.

Copyright Amity University


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

Copyright Amity University


Hashed Page Table
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.

Copyright Amity University


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.

Copyright Amity University


Inverted Page Table Architecture
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.

Copyright Amity University


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.

Copyright Amity University


Shared Pages Example

Copyright Amity University


Segmentation

Memory-management scheme that supports


user view of memory.

Copyright Amity University


A program is a collection of segments. A
segment is a logical unit such as:

main program,

procedure,

function,

method,

Copyright Amity University


object,

local variables, global variables,

common block,

stack,

symbol table, arrays

Copyright Amity University


Users View of a Program
1

4
1

3 2
4

user space physical memory space

Logical View of Segmentation


Segmentation Architecture

Logical address consists of a two tuple:

<segment-number, offset>

Copyright Amity University


Segment table maps two-dimensional physical
addresses; each table entry has:
base contains the starting physical address where
the segments reside in memory.

limit specifies the length of the segment.

Copyright Amity University


Segment-table base register (STBR) points to
the segment tables location in memory.

Segment-table length register (STLR) indicates


number of segments used by a program;
segment number s is legal if s < STLR.

Copyright Amity University


Segmentation Architecture (Cont.)

Relocation.
dynamic

by segment table

Copyright Amity University


Sharing.
shared segments

same segment number

Allocation.
first fit/best fit

external fragmentation

Copyright Amity University


Segmentation Architecture (Cont.)

Protection. With each entry in segment table


associate:
validation bit = 0 illegal segment

read/write/execute privileges

Protection bits associated with segments; code


sharing occurs at segment level.

Copyright Amity University


Since segments vary in length, memory
allocation is a dynamic storage-allocation
problem.

A segmentation example is shown in the


following diagram

Copyright Amity University


Segmentation Hardware
Example of Segmentation
Sharing of Segments
Multiple Choice Questions
Q1. In memory management, a technique called as paging,
physical memory is broken into fixed-sized blocks called
____________________.

a. Pages

b. Frames

c. Blocks

d. Segments

Copyright Amity University


Q2. Paging _________.

a. solves the memory fragmentation problem

b. allows modular programming

c. allows structured programming

d. avoids deadlock

Copyright Amity University


Q3. Which of the following memory allocation scheme suffers

from External fragmentation?

a. Segmentation

b. Pure demand paging

c. Swapping

d. Paging

Copyright Amity University


Q4. Which algorithm is best for selecting free area of
memory for partition?
a. meant fit
b. fest fit
c. worst fit
d. first fit

Copyright Amity University


Q5. In memory management, a technique called as paging,
Logical memory is broken into fixed-sized blocks called
____________________.

a. Pages

b. Frames

c. Blocks

d. Segments

Copyright Amity University


Virtual Memory

Copyright Amity University


Background

Demand Paging

Process Creation

Page Replacement

Copyright Amity University


Allocation of Frames

Thrashing

Operating System Examples

Copyright Amity University


Basic Facts
Virtual memory separation of user logical memory
from physical memory.
Only part of the program needs to be in memory for execution.

Logical address space can therefore be much larger than


physical address space.

Allows address spaces to be shared by several processes.

Allows for more efficient process creation.

Copyright Amity University


Virtual memory can be implemented via:

Demand paging

Demand segmentation

Copyright Amity University


Virtual Memory That is Larger Than Physical Memory
Demand Paging

Bring a page into memory only when it is needed.


Less I/O needed

Less memory needed

Faster response

More users

Copyright Amity University


Page is needed reference to it

invalid reference abort

not-in-memory bring to memory

Copyright Amity University


Transfer of a Paged Memory to Contiguous Disk Space
Valid-Invalid Bit

With each page table entry a validinvalid bit is


associated (1 in-memory, 0 not-in-memory)

Initially validinvalid but is set to 0 on all entries.


During address translation, if validinvalid bit in page table
entry is 0 page fault.

Copyright Amity University


Valid-Invalid Bit (Cont..)
Example of a page table snapshot.

valid-invalid bit
Frame #
1
1
1
1
0

0
0
page table

During address translation, if validinvalid bit in page table entry is 0


page fault.
Copyright Amity University
Page Table When Some Pages Are Not in Main Memory
Page Fault
If there is ever a reference to a page, first reference will trap
to OS page fault.

OS looks at another table to decide:


Invalid reference abort.

Just not in memory.

Get empty frame.

Copyright Amity University


Page Fault
Swap page into frame.
Reset tables, validation bit = 1.
Restart instruction: Least Recently Used
block move

auto increment/decrement location

Copyright Amity University


Steps in Handling a Page Fault
What happens if there is no free frame?

Page replacement find some page in memory, but not


really in use, swap it out.
algorithm

performance want an algorithm which will result in minimum


number of page faults.

Same page may be brought into memory several times.

Copyright Amity University


Performance of Demand Paging

Page Fault Rate 0 p 1.0


if p = 0 no page faults

if p = 1, every reference is a fault

Copyright Amity University


Effective Access Time (EAT)
EAT = (1 p) x memory access
+ p (page fault overhead
+ [swap page out ]
+ swap page in
+ restart overhead)

Copyright Amity University


Demand Paging Example
Memory access time = 1 microsecond

50% of the time the page that is being replaced


has been modified and therefore needs to be
swapped out.

Copyright Amity University


Swap Page Time = 10 msec = 10,000 msec
EAT = (1 p) x 1 + p (15000)
1 + 15000P (in msec)

Copyright Amity University


Process Creation
Virtual memory allows other benefits during
process creation:

- Copy-on-Write

- Memory-Mapped Files

Copyright Amity University


Copy-on-Write
Copy-on-Write (COW) allows both parent and
child processes to initially share the same pages
in memory.

If either process modifies a shared page, only


then is the page copied.

Copyright Amity University


COW allows more efficient process creation as
only modified pages are copied.

Free pages are allocated from a pool of zeroed-


out pages.

Copyright Amity University


Memory-Mapped Files
Memory-mapped file I/O allows file I/O to be
treated as routine memory access by mapping a
disk block to a page in memory.

Copyright Amity University


A file is initially read using demand paging. A
page-sized portion of the file is read from the file
system into a physical page. Subsequent
reads/writes to/from the file are treated as
ordinary memory accesses.

Copyright Amity University


Simplifies file access by treating file I/O through
memory rather than read() write() system calls.

Also allows several processes to map the same


file allowing the pages in memory to be shared.

Copyright Amity University


Memory Mapped Files
Operating System Concepts
Multiple Choice Questions
Q1. Virtual Memory is commonly implemented by _____.

a. Segmentation

b. Swapping

c. Demand Paging

d. None of the above


Q2. Advantages of Demand Paging are:
a. Less I/O needed
b. Less memory needed
c. Faster response
d. More users
e. All of the above
Thank You

Das könnte Ihnen auch gefallen