Sharing Memory - Lecture Slides - Operating Systems | CMSC 412, Study notes of Operating Systems

Material Type: Notes; Professor: Hollingsworth; Class: Operating Systems; Subject: Computer Science; University: University of Maryland; Term: Spring 2004;

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-02o-2
koofers-user-02o-2 🇺🇸

10 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CMSC 412 – S04 (lect 11)
Announcements
zReading:
Today: Chapter 9.4-9.6
zMidterm:
Tuesday
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Sharing Memory - Lecture Slides - Operating Systems | CMSC 412 and more Study notes Operating Systems in PDF only on Docsity!

Announcements

z

Reading:– Today: Chapter 9.4-9.

z

Midterm:– Tuesday

Sharing Memory

z

Pages can be shared– several processes may share the same code or data– several pages can be associated with the same page frame– given read-only data, sharing is always safe

z

when writes occur, decide if processes share data– operating systems often implement “copy on write” - pages

are shared until a process carries out a write

  • when a shared page is written, a new page frame is

allocated

  • writing process owns the modified page• all other sharing processes own the original page
    • page could be shared
      • processes use semaphores or other means to coordinate

access

What Happens when a virtual address

has no physical address?

z

called a

page fault

  • a trap into the operating system from the hardware

z

caused by: the first use of a page– called

demand paging

  • the operating system allocates a physical page and the

process continues

  • read code from disk or init data page to zero

z

caused by: a reference to an address that is not valid– program is terminated with a “segmentation violation”

z

caused by: a page that is currently on disk– read page from disk and load it into a physical page, and

continue the program

z

causde by: a copy on write page

–^

NOACCESS: attempts to read, write or execute will cause an accessviolation

-^

READONLY: attempts to write or execute memory in this region causean access violation

-^

READWRITE: attempts to execute memory in this region cause anaccess violation

-^

EXECUTE: Attempts to read or write memory in this region cause anaccess violation

-^

EXECUTE_READ: Attempts to write to memory in this region cause anaccess violation

-^

EXECUTE_READ_WRITE: Do anything to this page

-^

WRITE_COPY: Attempts to write will cause the system to give aprocess its own copy of the page. Attempts to execute cause accessviolation

-^

EXECUTE_WRITE_COPY: Attempts to write will cause the system togive a process its own copy of a page. Can’t cause an access violation

OS Protection attributes (Win32)

Page Fault – Page is Paged out

PageDirectory

Page Table

PageFrames

P ReferenceTo this page

  1. Fault

  2. Read from Disk

  3. MakeEntry

  4. Continue

Page State (hardware view)

z

Page frame number (location in memory or on disk)

z

Valid Bit^ – indicates if a page is present in memory or stored on disk

z

A

modify

or

dirty

bit

  • set by hardware on write to a page– indicates whether the contents of a page have been modified

since the page was last loaded into main memory

  • if a page has not been modified, the page does not have to

be written to disk before the page frame can be reused

z

Reference bit^ – set by the hardware on read/write– cleared by OS– can be used to approximate LRU page replacement

z

Protection attributes– read, write, execute

Page Replacement Algorithms

z

FIFO–

Replace the page that was brought in longest ago

-^

However

-^

old pages may be great pages (frequently used)

-^

number of page faults may increase when one increases number ofpage frames (discouraging!)

  • called belady’s anomaly– 1,2,3,4,1,2,5,1,2,3,4,5 (consider 3 vs. 4 frames)

z

Optimal–

Replace the page that will be used furthest in the future

-^

Good algorithm(!) but requires knowledge of the future

-^

With good compiler assistance, knowledge of the future issometimes possible

Page Replacement Algorithms

z

FIFO–

Replace the page that was brought in longest ago

-^

However

-^

old pages may be great pages (frequently used)

-^

number of page faults may increase when one increases number ofpage frames (discouraging!)

  • called belady’s anomaly– 1,2,3,4,1,2,5,1,2,3,4,5 (consider 3 vs. 4 frames)

z

Optimal–

Replace the page that will be used furthest in the future

-^

Good algorithm(!) but requires knowledge of the future

-^

With good compiler assistance, knowledge of the future issometimes possible

FIFO Example (3 frames)

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

•^

access 1 - (1) fault

-^

access 2 - (1,2) fault

-^

access 3- (1,2,3) fault

-^

access 4 - (2,3,4) fault, replacement

-^

access 1 - (3,4,1) fault, replacement

-^

access 2 - (4,1,2) fault, replacement

-^

access 5 - (1,2,5) fault, replacement

-^

access 1- (1,2,5)

-^

access 2 - (1,2,5)

-^

access 3 - (2,5,3) fault, replacement

-^

access 4 - (5,3,4) fault, replacement

-^

access 5 - (5,3,4)

  • 9 page faults