Understanding Virtual Memory: Concept, Benefits, and Page Fault Handling, Slides of Computer Science

An in-depth exploration of virtual memory, its importance in allowing large logical address spaces, and the conceptual separation of user logical memory from physical memory. It covers demand paging, page replacement algorithms, and the steps to handle a page fault. The document also discusses the requirements and performance of demand paging.

Typology: Slides

2012/2013

Uploaded on 03/28/2013

ekana
ekana 🇮🇳

4

(44)

370 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
9: Virtual Memory 1
OPERATING SYSTEMS
VIRTUAL MEMORY
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Understanding Virtual Memory: Concept, Benefits, and Page Fault Handling and more Slides Computer Science in PDF only on Docsity!

9: Virtual Memory 1

OPERATING SYSTEMS

VIRTUAL MEMORY

9: Virtual Memory 2

VIRTUAL MEMORY

WHY VIRTUAL MEMORY?

  • We've previously required the entire logical space of the process to be in memory before the process could run. We will now look at alternatives to this.
  • Most code/data isn't needed at any instant, or even within a finite time - we can bring it in only as needed.

VIRTUES

  • Gives a higher level of multiprogramming
  • The program size isn't constrained (thus the term 'virtual memory'). Virtual memory allows very large logical address spaces.
  • Swap sizes smaller.

9: Virtual Memory 4

VIRTUAL MEMORY

Demand paging When a page is touched, bring it from secondary to main memory.

Overlays Laying of code data on the same logical addresses - this is the

reuse of logical memory. Useful when the program is in phases or

when logical address space is small.

Dynamic loading A routine is loaded only when it's called.

Definitions

9: Virtual Memory 5

VIRTUAL MEMORY

When a page is referenced, either as code execution or data access, and that

page isn’t in memory, then get the page from disk and re-execute the statement.

Here’s migration between

memory and disk.

Demand Paging

9: Virtual Memory 7

VIRTUAL MEMORY

STEPS IN HANDLING A PAGE FAULT

1. The process has touched a page not currently in memory.

2. Check an internal table for the target process to determine if the reference was

valid (do this in hardware.)

3. If page valid, but page not resident, try to get it from secondary storage.

4. Find a free frame; a page of physical memory not currently in use. (May need

to free up a page.)

5. Schedule a disk operation to read the desired page into the newly allocated

frame.

6. When memory is filled, modify the page table to show the page is now resident.

7. Restart the instruction that failed

Do these steps using the figure you can see on the next page.

Demand Paging

9: Virtual Memory 8

VIRTUAL MEMORY Demand Paging

9: Virtual Memory 10

VIRTUAL MEMORY

PERFORMANCE OF DEMAND PAGING

We are interested in the effective access time: a combination of "normal" and "paged"

accesses.

It’s important to keep fraction of faults to a minimum. If fault ratio is "p", then

effective_access_time = ( 1 - p ) * memory_access_time

+ p * page_fault_time.

Calculate the time to do a fault as shown in the text:

fault time = 10 milliseconds ( why )

normal access = 100 nanoseconds ( why )

How do these fit in the formula?

Demand Paging

9: Virtual Memory 11

VIRTUAL MEMORY

Some of the pages belonging

to this process are in

memory, and some are on the

disk.

A bit in the page table tells

where to find the page.

The Picture When All

Pages Are Not In Memory

pmap on linux shows where these pages get mapped.

“pmap –x

Check out also “lsof”

9: Virtual Memory 13

PAGE REPLACEMENT ALGORITHMS:

When memory is overallocated, we can either swap out some process, or overwrite some pages. Which pages should we replace?? <--- here the goal is to minimize the number of faults.

Here is an example reference string we will use to evaluate fault mechanisms:

Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

VIRTUAL MEMORY Page Replacement

FIFO

Conceptually easy to implement; either use a time-stamp on pages, or organize on a queue. (The queue is by far the easier of the two methods.)

5 10 page faults

9: Virtual Memory 14

OPTIMAL REPLACEMENT

  • This is the replacement policy that results in the lowest page fault rate.
  • Algorithm: Replace that page which will not be next used for the longest period of time.
  • Impossible to achieve in practice; requires crystal ball. Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

VIRTUAL MEMORY Page Replacement

6 page faults

9: Virtual Memory 16

PAGE REPLACEMENT ALGORITHMS :

Using another string:

VIRTUAL MEMORY Page Replacement

FIFO

OPTIMAL

LRU

9: Virtual Memory 17

LRU APPROXIMATION

Uses a reference bit set by hardware when the page is touched. Then when a fault occurs, pick a page that hasn't been referenced.

Additional reference bits can be used to give some time granularity. Then pick the page with the oldest timestamp.

Second chance replacement: pick a page based on FIFO. If its reference bit is set, give it another chance. Envision this as a clock hand going around a circular queue. The faster pages are replaced, the faster the hand goes.

Maintain a modified bit, and preferentially replace unmodified pages.

VIRTUAL MEMORY Page Replacement

Second-Chance (clock)

Page-Replacement Algorithm

9: Virtual Memory 19

ALLOCATION OF FRAMES:

What happens when several processes contend for memory? What algorithm

determines which process gets memory - is page management a global or local

decision?

A good rule is to ensure that a process has at least a minimum number of pages.

This minimum ensures it can go about its business without constantly thrashing.

ALLOCATION ALGORITHMS

Local replacement -- the process needing a new page can only steal from itself.

(Doesn't take advantage of entire picture.)

Global replacement - sees the whole picture, but a memory hog steals from

everyone else

Can divide memory equally, or can give more to a needier process. Should high

priority processes get more memory?

VIRTUAL MEMORY Page Allocation

9: Virtual Memory 20

Suppose there are too few physical pages (less than the logical pages being actively

used). This reduces CPU utilization, and may cause increase in multiprogramming

needs defined by locality.

A program will thrash if all pages of its locality aren’t present in the working set.

Two programs thrash if they fight each other too violently for memory.

VIRTUAL MEMORY Thrashing