• No results found

Virtual Memory

N/A
N/A
Protected

Academic year: 2020

Share "Virtual Memory"

Copied!
23
0
0

Loading.... (view fulltext now)

Full text

(1)

Virtual Memory

(2)

INTRODUCTION TO VIRTUAL MEMORY

A technique that allows a process to execute in the main

memory space which is smaller than the process size

Only a part of a process needs to be loaded in the main

memory for execution

If an entire process is not loaded while it executes, it may

be possible that the process requests for an instruction/

data in a page that is not in the main memory rather is

there in the backing store. In that event, the requested

page is brought into the main memory from the backing

store.

(3)
(4)

INTRODUCTION TO VIRTUAL MEMORY

To implement virtual memory, OS extends the page tables with extra bit

“present bit” or “valid bit”; if it is 1 that means the page in loaded and

vice versa.

In such situations, the operating system need to take two kinds of

scheduling decisions:

Page Selection.

When to bring pages into memory

Demand Paging.

Start up process with no pages loaded, load a

page when a page fault for it occurs

Page Replacement.

Which page(s) should be thrown out, and when

(5)

DEMAND PAGING

Demand paging says; bring a page into memory only when it is needed

When ever a process make a request for a page a reference is made to it

invalid reference

abort. (The page a process has requested is

not in its process address space)

not-in-memory

page fault occurs and bring the page to memory

No free frame

Swapping

Advantages of demand paging are:

Potentially Less I/O needed

Potentially Less memory needed

Faster response

(6)

TRANSFER OF A PAGE FROM MEMORY TO DISK

(7)

VALID – INVALID BIT

With each page table entry a valid–invalid bit is

associated

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

Initially valid–invalid but is set to 0 on all entries

Example of a page table snapshot

During address translation, if valid–invalid bit in

page table entry is 0, a page fault occurs

(8)

PAGE TABLE WHEN SOME PAGES ARE NOT IN MAIN MEMORY

(9)

SERVICING A PAGE FAULT

When ever a page reference is made, the operating system checks:

a)

If it is an invalid reference a trap to the OS is made and the

process is aborted

b)

If it is a valid reference then the valid bit of the page table is

checked. If the valid bit is zero that means the page is not loaded in

the memory, so a page fault is generated. To service this page fault

following steps are taken:

1. Locate the page on the disk

2. Allocate an empty frame from the frames allocated to that process and

load the page into that frame

3. If there is no empty frame available with that process then select a

victim frame and swap out that victim frame/page back to the hard disk

4. Swap in the desired page into the selected frame

5. Store the frame number in the appropriate page table entry, and set

(10)

SERVICING A PAGE FAULT

(11)

PAGE REPLACEMNET

Suppose that a page fault has occurred and there is no empty frame available

with that process then the system selects a victim frame and swap out that victim frame/page back to the hard disk.

There are the following two options for page replacement:

a)Local replacement – If a process P1 having no free frame demands a page and

the victim frame selected is of the same process P1 then it is called Local replacement

b) Global replacement – If a process P1 having no free frame demands a page

and the victim frame selected is of some other process then it is called Global replacement

Page fault service routine is modified to include page replacement as wellDirty bit is used to reduce overhead of page transfers, i.e., only modified

(12)

Local Replacement

(13)
(14)

ALLOCATION OF FRAMES

Each process should be given a minimum number of frames so

that its execution may be guaranteed on a given machine .

There are three major allocation schemes:

a)

Fixed Allocation:

Free frames are equally divided among processes

b) Proportional Allocation

Number of frames allocated to a process is proportional to

its size

c) Priority allocation

Priority-based proportional allocation

(15)

ALLOCATION OF FRAMES - Example

Number of free frames = 64

Number of processes = 3

Process sizes: (P1 = 10 pages ; P2 = 40 pages ; P3 = 127 pages)

Fixed allocation

64/3 = 21 frames per process and one put in the free frames list

Proportional Allocation

s

i

= Size of process P

i

S = ∑ s

i

m = Number of free frames

a

i

= Allocation for P

i

= (s

i

/ S) * m

a

1

= (10 / 177) * 64 = 3 frames

a

2

= (40 / 177) * 64 = 14 frames

a

(16)

PAGE REPLACEMNET ALGORTHIMS

FIFO - First in First Out

Replace the page that has been in main memory the longest

LRU - Least Recently Used

Replace the page that has not been used for the longest time

Optimal Algorithm

Evaluate algorithm by running it on a particular string of memory

references (reference string) and computing the number of page

faults on that string

(17)

PAGE REPLACEMNET ALGORTHIMS

FIFO - First in First Out

Replace the page that has been in main memory the longestSimplest algorithm

Windows NT uses FIFO

Example 1

Number of frames allocated = 4Number of page faults = 12

(18)

PAGE REPLACEMNET ALGORTHIMS

FIFO – Example 2

Number of frames allocated = 3Reference string:

1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

Number of page faults = 9

1 1 1 4 4 4 5 5 5

2 2 2 1 1 1 3 3

3 3 3 2 2 2 4

• FIFO – Example 3

• Number of frames allocated = 4 • Reference string:

1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 • Number of page faults = 10

1 1 1 1 5 5 5 5 4 4

2 2 2 2 1 1 1 1 5

3 3 3 3 2 2 2 2

4 4 4 4 3 3 3

(19)

PAGE REPLACEMNET ALGORTHIMS

LRU - Least Recently Used

Replace the page that has not been used for the longest time

Example 1

(20)

PAGE REPLACEMNET ALGORTHIMS

LRU – Example 3

Number of frames allocated = 3Reference string:

1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

Number of page faults = 10

1 1 1 4 4 4 5 3 3 3

2 2 2 1 1 1 1 4 4

3 3 3 2 2 2 2 5

• LRU – Example 4

• Number of frames allocated = 4 • Reference string:

1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 • Number of page faults = 8

1

1

1

1

1

1

1

5

2

2

2

2

2

2

2

3

3

5

5

4

4

4

4

3

3

3

(21)

PAGE REPLACEMNET ALGORTHIMS

Optimal Algorithm

Best possible algorithm, but impossible to implement

Replace the page that will not be used for the longest period of time.

Used as Bench Mark, whenever an algorithm is to be evaluated its performance is

compared with the optimal replacement algorithm

(22)

THRASHING

If a process does not have “enough” frames, the page-fault rate is very high.

This leads to:

Low CPU utilizationHigh disk utilization

OS thinks that it needs to increase the degree of multi - programmingAnother process is added to the system and that cause serious problems

Thrashing is a phenomenon in which CPU spends much of its time swapping

pages in and out, rather than executing instructions

Thus in order to stop thrashing:

The degree of multiprogramming

needs to be reduced

The effects of thrashing can be reduced

by using a local page replacement. So if one process starts thrashing it cannot steal frames from another process and cause the later to thrash also.

(23)

PAGE REPLACEMNET ALGORTHIMS – SAMPLE PROBLEM

Consider a paging system with physical memory of 6 Bytes,

Virtual Memory 16 bytes & Page size of 2 Bytes. A program stores

and accesses characters A to P. Compute the physical addresses of

logical addresses where following program instructions are

loaded:

F, C, K, A, M, B, J, N

Use FIFO while constructing the Page Table

References

Related documents

Squares are for NEXTMap’s DSM, and most analogous filter to its DTM (Fig.. Recoveries of H and V for individual drumlins using the ‘best’ practical quantification method, E8 and

Determine the (a) depreciable cost (b) double-declining-balance rate, and (c) double- declining-balance depreciation for the first year. After two years of straight line

We suggest that investors should look at the long term contract price of uranium when analyzing Berkeley and other developers because this is the market in which we will

Mondo Wi-Fi has three main menu headings Stations , Configure and Media Player .To select a radio station, use the < > buttons until the word STATIONS appears, then press the

ê In developing countries, occupational noise and urban, environmental noise (especially traffic noise) are increasing risk factors for hearing impairment.. ê Developing countries

Cap diameter: 3.2 mm Base metal: AIMg3 Sheet thickness: 5 mm Welding amperage: 185 A Welding voltage: 15.6 V AC balance: 0 / Control panel of TT 2500 Standard.. All plAin

purchases should be written out and evidence provided that the decision-makers have considered the guidelines when allowing disbursements. Activity funds must not take on the image

In conclusion, we describe a correlation between cumulative biological dysregulation and excess weight in children and adolescents, suggesting that AL could be a useful index of