Docsity

Operating Systems: CS414 Class Notes - Virtual Memory and Page Replacement - Prof. Marty A, Study notes of Operating Systems

Toggle sidebar
bg1
1
CS414: Operating Systems
Today’s Class
•Last time
Memory management (chapt 9)
Virtual memory (chapt10)
PA#3 back
•This time
Virtual memory (chapt 10)
•Next time
File systems – interface and implementation (Chapts 11/12)
•Extra class – Thurs/Fri this week (OLS 120)
•No class next week (Tues and Thurs), no office hours
for me next mon/tues – some email availability
CS414: Operating Systems
Schedule
Sun Tues Thurs Fri
No class – marty
at conference
Virtual memory
6 8
13 15
20 22
protection, security
PA#6 due, PA#7 out
27 29
protection, security
4
protection,
security
File systems
File sys, I/O sys
File sys
I/O sys 9
No class – marty
at conference
I/O sys,Mass-storage
PA#5 due, PA#6 out No class –
Thanksgiving
14
Final exam
10:00-noon
6
Wrap-up
PA#7 due
protection, security
protection,
security
30
CS414: Operating Systems
Before we start: PA#5
•You can use C, C++, Java, or a .NET language, with a
monitor or just semaphores, on any/all of the 3 problems
(can be the same language for all three)
Focus on algorithmic design, not “ sidetracked” by language
“idiosyncratic behavior”
•Dorm-matching is a different beast than the other two
(which are simulations)
15000 students, 25 interests, .3 prob of interest
random placement : 21% disharmony, 2.67 sec
More intelligent placement (not optimal): 5.7% disharmony, 28.78 sec
Can you use more processors (up t o 8) to speed up the “more
intelligent placement”? [May or may not need synchron primitives!]
•Showing correctness (to you AND to the graders) is
critical!
CS414: Operating Systems
Before we start: PA#5
•Strategy
Understand the readers/writers code from the notes
Understand the dining philosophers code (class web page)
Start with coolness …
CS414: Operating Systems
Before we start
•Fragmentation – internal vs. external
CS414: Operating Systems
Paging Hardware
•How do we find addresses when pages are not allocated contiguously in
memory?
•Virtual Address:
Processes generates virtual address to name locations (range: 0 to the size of the process).
The OS lays the process down on pages and the paging hardware translates generated
address to actual physical address in memory.
In paging, the virtual address identifies the page and the page offset.
A page table on a per-process basis keeps track of the page frame in memory in which each
page is located.
pf2

Partial preview of the text

Download Operating Systems: CS414 Class Notes - Virtual Memory and Page Replacement - Prof. Marty A and more Study notes Operating Systems in PDF only on Docsity!

CS414: Operating Systems

Today’s Class

• Last time

Memory management (chapt 9)

Virtual memory (chapt10)

PA#3 back

• This time

Virtual memory (chapt 10)

• Next time

File systems – interface and implementation (Chapts 11/12)

• Extra class – Thurs/Fri this week (OLS 120)

• No class next week (Tues and Thurs), no office hours

for me next mon/tues – some email availability

CS414: Operating Systems

Schedule

Sun Tues Thurs (^) Fri

No class – marty at conference

Virtual memory 6 8

13 15

(^20 ) protection, security PA#6 due, PA#7 out 27 29

protection, security

4

protection, security

File systems File sys, I/O sys

File sys I/O sys 9 No class – marty at conference I/O sys,Mass-storage PA#5 due, PA#6 out

No class – Thanksgiving

14

Final exam 10:00-noon

6

Wrap-up PA#7 due

protection, security

protection, security 30

CS414: Operating Systems

Before we start: PA#

• You can use C, C++, Java, or a .NET language, with a

monitor or just semaphores, on any/all of the 3 problems

(can be the same language for all three)

Focus on algorithmic design, not “sidetracked” by language

“idiosyncratic behavior”

• Dorm-matching is a different beast than the other two

(which are simulations)

15000 students, 25 interests, .3 prob of interest

 random placement : 21% disharmony, 2.67 sec  More intelligent placement (not optimal): 5.7% disharmony, 28.78 sec

 Can you use more processors (up to 8) to speed up the “more

intelligent placement”? [May or may not need synchron primitives!]

• Showing correctness (to you AND to the graders) is

critical!

CS414: Operating Systems

Before we start: PA#

• Strategy

Understand the readers/writers code from the notes

Understand the dining philosophers code (class web page)

Start with coolness …

CS414: Operating Systems

Before we start

• Fragmentation – internal vs. external

CS414: Operating Systems

Paging Hardware

  • How do we find addresses when pages are not allocated contiguously in memory?
  • Virtual Address:  Processes generates virtual address to name locations (range: 0 to the size of the process).  The OS lays the process down on pages and the paging hardware translates generated address to actual physical address in memory.  In paging, the virtual address identifies the page and the page offset.  A page table on a per-process basis keeps track of the page frame in memory in which each page is located.

CS414: Operating Systems

More on the Page Table

  • Use memory as cache for disk
  • Page table -- also indicates if page is currently in physical memory or on disk ( valid bit )
  • For efficiency, “most” memory accesses must be already in physical memory (otherwise, effective memory access time will approach that of the disk).
  • FYI: page tables can be huge; e.g., logical address space = 2^32 , page size = 2^12 (4K), then page table is How big?; answer: 2^20 ; (1 Meg entries)!  Solution: two or more levels (page the page table)

CS414: Operating Systems

Page Fault Mechanism

**1. save the state of the user thread (registers, etc.)

  1. if necessary select a page frame to replace (** page replacement algorithm) **3. if the old page has been modified, write it back to disk
  2. invalidate the old page entry in the “other” page table (** Why? **)
  3. find address on backing store of page to be loaded
  4. start loading new page into memory from disk
  5. start executing another thread** **……
  6. get interrupted when page is loaded in memory
  7. save the state of thread currently being executed
  8. update the page table entry
  9. continue faulting thread {** why not continue the current thread?) by reissuing the faulting instruction ( What if it has side-effects?)

All of this is functionally transparent to the user (it may not be performance transparent); the OS keeps the processor busy by running another thread.

CS414: Operating Systems

Policy: Page Fault

• [fetch policy] when should a page be loaded into primary

memory?

• [replacement policy] which page will be selected as the

victim?

• [placement policy] where should the fetched page be

loaded into primary memory? ( usually straightforward)

• Two types of paging algorithms

[static] allocate a fixed number of page frames to a process when it is

created

[dynamic] number of pages can grow or shrink for a particular

process, depending on the needs of other processes

CS414: Operating Systems

When to Load a Page?

• [Up front, all-at-once] When process begins to execute,

the OS loads all pages

Assumption: virtual address space is less than or equal to the

physical memory

• [Demand paging] Wait until you need a page, page fault

virtual memory can be greater than physical memory

• [Request paging] Process must tell OS before it needs a

page, and then when it is through with a page.

• [Pre-paging] OS guesses in advance which pages the

process will need and pre-loads them into memory. If the

OS is wrong, fall back onto demand paging.

Very difficult and can potentially damage performance.

CS414: Operating Systems

Overview of Page Replacement Algorithms

On a page fault, we need to choose a page to kick out

• [Random] questionable performance

• [Optimal] (aka MIN) Look into the future and throw out

the page that will be accessed furthest into the future

• [LRU] Throw out the page that has not been used in the

longest time. This is too expensive. Why?

• [LFU] must overcome “inertia”

• [FIFO] Throw out the oldest page.