Docsity

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

Toggle sidebar
bg1
1
CS414: Operating Systems
Today’s Class
•Last time (Tues)
Virtual memory (chapt 10)
•This time
Finish Virtual memory (chapt 10)
File systems interface and implementation
•Next time (tonight OLS 120 6pm / tomorrow OLS
120 3pm)
File systems – interface and implementation (Chapts 11/12)
CS414: Operating Systems
Before we start
•No class next week (Tues and Thurs), no office
hours for me next mon/tues – some email
availability
Yes, blake will have office hours:
Wed Nov 14 5-8pm 002a
Mon Nov 19 5-8pm
I will have office hours Mon Nov 19 1-4pm, Tue Nov 20 10-
11am
ALSO: tomorrow (Nov 9) noon – 3pm
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)
CS414: Operating Systems
Before we start
•FYI: page tables can be huge; e.g., logical address space =
232, page size = 212 (4K), then page table is How big?;
answer: 220; (1 Meg entries)!
Solution: two or more levels (page the page table)
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.
pf3
pf4

Partial preview of the text

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

CS414: Operating Systems

Today’s Class

  • Last time (Tues)

Virtual memory (chapt 10)

  • This time

Finish Virtual memory (chapt 10)

File systems interface and implementation

  • Next time (tonight OLS 120 6pm / tomorrow OLS

120 3pm)

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

CS414: Operating Systems

Before we start

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

hours for me next mon/tues – some email

availability

Yes, blake will have office hours:

Wed Nov 14 5-8pm 002a

Mon Nov 19 5-8pm

I will have office hours Mon Nov 19 1-4pm, Tue Nov 20 10-

11am

ALSO: tomorrow (Nov 9) noon – 3pm

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)

CS414: Operating Systems

Before we start

  • FYI: page tables can be huge; e.g., logical address space =

232 , 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

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.

CS414: Operating Systems

Examples: FIFO

  • 3 page frames (F1, F2, F3)
  • 100 word pages (Note: this is not an OS-oriented page size!)
  • reference string: 642 402 403 404 180 256 401 360 401
  • page trace:

F

F

F

FIFO

Number of page faults:

CS414: Operating Systems

Examples: Optimal

F

F

F

Optimal

Number of page faults:

CS414: Operating Systems

Examples: LRU

F

F

F

LRU

Number of page faults:

F

F

F

When will LRU perform poorly?

Number of page faults:

CS414: Operating Systems

Adding Memory: FIFO

A B C D A B E A B C D E

F

F

F

Number of page faults:

A B C D A B E A B C D E

F

F

F

F

Number of page faults:

CS414: Operating Systems

Adding Memory

  • Does adding memory always reduce the # of page faults?

[Yes] for LRU and MIN, and other stack-based algorithms.

[No] for FIFO (Belady's anomaly)

  • With FIFO, the contents of memory can be completely

different with a different number of page frames.

  • In contrast, LRU, MIN, and other stack-based algorithms

ensure that the contents of memory with X frames is a

subset of the contents with X+1 page frames, so adding memory reduces the number of page faults.

CS414: Operating Systems

Implementing LRU

  • LRU is most widely used; however, an approximation is used because of space and time considerations
  • Perfect LRU -- Keep a time stamp for each page with the

time of the last access. Throw out the LRU page.

  • LRU Approximations

[Hardware Support] a reference bit. Each access to a page causes

the HW to set the reference bit to 1 (periodically resetting to 0)

[Additional-Reference-Hits] OS shifts reference bit right in a counter.

Lowest numbered page is kicked out.

[Second Chance] FIFO queue with a reference bit. Keep pages in a

circular queue. If reference bit is 1, set it to 0. If reference bit is 0,

kick out the page.

CS414: Operating Systems

What’s a Good Page Size?

  • [consideration] page tables take up memory space (we want small tables)
  • [solution]
  • [consideration] when frames are allocated to a process, 1/2 of a page (average) is lost to internal fragmentation
  • [solution]
  • [consideration] I/O for paging dominated by seek time (1 seek/page)
  • [solution]
  • [consideration] paging in a large page may bring in code outside of current locality (never referenced—wasted I/O time and memory)
  • [solution]
  • [consideration] smaller pages  more page faults (increased overhead)
  • [solution]

CS414: Operating Systems

Two Main Approaches for

Implementing Virtual Memory

  • segmentation: use of relocation-limit registers and bounds-checking blocks of memory variable-sized (logical) segments, defined by user (or compiler) virtual address: { <segment number, offset> ) pure segmentation: whole segments are transferred back and forth between primary and secondary memory
  • paging: virtual address space: flat (linear) sequence lacking (as in segmentation): VM system in OS has little knowledge of logical segment instead of variable-sized chunk, fixed-sized unit of transfer (the page) memory manager selectively allocates pages to frames in memory and manages (moves, removes, reallocates) pages in memory
  • Overall: segmentation is probably better suited to behavior of process, although it can be harder to use and harder to implement

CS414: Operating Systems

Implementation of Segmentation

  • Segment table: each entry is base address in memory, length of segment, and protection information (this can be shared, read, modified, etc.)
  • Hardware support: multiple base/limit registers
  • Compiler's job is more challenging, since it must generate virtual address whose upper order bits are a segment number.
  • Same architecture/performance issues as paging. We need something like the TLB in case programs produce lots of segments.

CS414: Operating Systems

Segments and Paging

  • Address space: collection of segments (logical units); each segment is divided into pages and paged.
  • Virtual address: segment number, a page, and an offset. (The segment number has to be generated separately by the compiler; break down of a logical 2^{m} address into a page and offset is the same as in paging.
  • Segment number indexes into the segment table which yields the base address of the page table.
  • Add on the page number to index the page table, which yields the frame (and the rest of this is just like paging).
  • Add the frame and the offset to get the physical address

CS414: Operating Systems

Segments and Paging (cont.)

  • Protection and valid bits can go either in the segment or page table.
  • Pages are used as a convenience to the OS OS can break up and scatter the page tables. OS can leave unused page tables on disk. OS can manage memory in fixed size “pages”
  • Sharing

Share individual pages by copying page table entries. Share whole segments by sharing the page table for that segment. Need protection bits to specify and enforce read/write permission. (Most often, only read-only code is shared.)

  • Where are the segment table and page tables stored? Segment tables are usually in special CPU associative registers; system compilers usually produce a few segments per process. Page tables are usually in main memory with a TLB assist.
  • Can have multiple levels of paging and segmentation when the tables get too big