CS571: Operating Systems - George Mason Universitycsnow/cs571/2003A/lectures/oct08/07_6up.pdf§...

15
CS571 Operating Systems Class 07 08 Oct 03 © Charles M Snow 1 CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 0 7 .1 CS571: Operating Systems CLASS 7 : 08 OCT 2003 16:30 – 19:10 Except where otherwise noted, these slides are copyright Charles Snow, 2003. Permission to copy these slides is granted so long as each slide contains the copyright notice “ C. M. Snow 2003” appears on each page and the copies are made freely available, i.e., not sold. Students are advised that they should not use University consumables (ink, toner,paper) to produce printed versions of these slides. Rights for all other use of this material are reserved by the author; permission for any other use must be obtained in writing from the author. CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 0 7 .2 LFU § Least Frequently Used (LFU): select for replacement the page that is least frequently used needs counter mechanism CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 0 7 .3 LFU § Least Frequently Used (LFU): select for replacement the page that is least frequently used needs counter mechanism § consider this scenario: executing program cross page boundary to P j from P i timeslice switch to another process that other process now has page fault frame holding P j is least frequently used so is replaced § LFU only slightly better than… CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 0 7 .4 Random § Random: select a page at random for replacement poor performance, high page fault rate CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 0 7 .5 “Clock” § let each frame have a use bit § when page first loaded into frame, set use bit to 1 § each subsequent reference set use bit to 1 § also known as second chance will become apparent why CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 0 7 .6 “Clock” § organize frames into circular buffer with next-frame pointer: § when a page is loaded, pointer advances to next frame Page 75 U=1 Page 12 U=1 Page 84 U=0 Page 26 U=0 Page 47 U=1 Page 48 U=1 Page 94 U=0 ··· 6 5 4 3 2 1 0 frame numbers

Transcript of CS571: Operating Systems - George Mason Universitycsnow/cs571/2003A/lectures/oct08/07_6up.pdf§...

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 1

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.1

CS571: Operating Systems

CLASS 7 : 08 OCT 200316:30 – 19:10

Except where otherwise noted, these slides are copyright Charles Snow, 2003. Permission to copy these slides is granted so long as each slide contains the copyright notice “ C. M. Snow 2003” appears on each page and the copies are made freely available, i.e., not sold. Students are advised that they should not use University consumables (ink, toner,paper) to produce printed versions of these slides. Rights for all other use of this material are reserved b y the author; permission for any other use must be obtained in writing from th e author.

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.2

LFU

§ Least Frequently Used (LFU): select for replacement the page that is least frequently used• needs counter mechanism

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.3

LFU

§ Least Frequently Used (LFU): select for replacement the page that is least frequently used• needs counter mechanism

§ consider this scenario:• executing program cross page boundary to Pj from P i• timeslice switch to another process• that other process now has page fault • frame holding Pj is least frequently used so is

replaced§ LFU only slightly better than…

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.4

Random

§ Random: select a page at random for replacement• poor performance, high page fault rate

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.5

“Clock”

§ let each frame have a use bit§ when page first loaded into frame, set use bit to 1§ each subsequent reference set use bit to 1§ also known as second chance

• will become apparent why

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.6

“Clock”

§ organize frames into circular buffer with next-frame pointer:

§ when a page is loaded, pointer advances to next frame

Page 75U=1

Page 12U=1

Page 84U=0

Page 26U=0

Page 47U=1

Page 48U=1

Page 94U=0

···

6

5

43

2

1

0

frame numbers

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 2

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.7

“Clock”

§ to select page for replacement:• scan buffer for frame

with U = 0• while doing this,

clear any U =1 to 0• stop at first frame

with U = 0§ what’s worst case?§ if ignored U bits,

what would this be?

Page 75U=1

Page 12U=1

Page 84U=0

Page 26U=0

Page 47U=1

Page 48U=1

Page 94U=0

···

6

5

43

2

1

0

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.8

Example of Clock (Second Chance)

0

·PF?21

701071021230324302107

PFs:1

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.9

Example of Clock (Second Chance)

0

··PF?2

01770

1071021230324302107

PFs:2

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.10

Example of Clock (Second Chance)

0

···PF?120017770

1071021230324302107

PFs:3

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.11

Example of Clock (Second Chance)

0

····PF?112000127770

1071021230324302107

PFs:4

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.12

Example of Clock (Second Chance)

0

····PF?111200001227770

1071021230324302107

PFs:4

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 3

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.13

Example of Clock (Second Chance)

0

·····PF?311120000012227770

1071021230324302107

PFs:5

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.14

Example of Clock (Second Chance)

3020

·····PF?311120000012227770

1071021230324302107

PFs:5

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.15

Example of Clock (Second Chance)

3020

······PF?331112000000142227770

1071021230324302107

PFs:6

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.16

Example of Clock (Second Chance)

3020

··············PF?1222220000333311127771111222220000001000003333444422277701071021230324302107

PFs:14

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.17

Second Chance: Improved Version

§ “clock” with 0 bits is simple FIFO§ with 1 bit is second chance we just saw§ add another bit: M for modified

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.18

Second Chance: Improved Version

§ “clock” with 0 bits is simple FIFO§ with 1 bit is second chance we just saw§ add another bit: M for modified

• sometimes called “dirty” bit

recently accessed,modified

not recently accessed,modified

1

accessed recently,not modified

not recently accessed, not modified

010U→

M↓

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 4

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.19

Second Chance: Improved Version

§ enhanced replacement policy:• scan buffer, make no changes to bits• first (0,0) frame is chosen for replacement

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.20

Second Chance: Improved Version

§ enhanced replacement policy:• scan buffer, make no changes to bits• first (0,0) frame is chosen for replacement• scan again, for (U=0,M=1) clearing each frame’s

U bit to 0; pick first (0,1) frame encountered

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.21

Second Chance: Improved Version

§ enhanced replacement policy:• scan buffer, make no changes to bits• first (0,0) frame is chosen for replacement• scan again, for (U=0,M=1) clearing each frame’s

U bit to 0; pick first (0,1) frame encountered• scan again: look for U=M=0; if none, scan one

last time for U=0, M=1: pick first encountered§ this version used in (pre X) Macintosh OS

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.22

Page Buffering

§ used by VMS§ page replacement is FIFO but:

• replaced page is added to the end of 1 of 2 lists (FIFO):

(1) free page list if was unmodified,(2)modified page list is was modified• free page list is list of frames available to receive

pages§ VMS trying to keep a small number of frames

free at all times

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.23

Page Buffering

§ moving pages to lists handled by pointer manipulation: fast

§ page moved to free list is still ‘resident’, so page-in is fast (switch some pointers)

§ modified pages can be written out in batches: more efficient use of I/O

§ simplified version used in Mach• no distinction between modified/unmodified

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.24

Replacement Policies: Comparison

FIFOClockLRUBOR

after results in Baer, J.L., Computer Systems Architecture, 1980

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 5

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.25

Resident Set Management

§ how small or big should resident set be?

less memory allocated more memory allocated

more processes fit in main memory

fewer processes fit in main memory

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.26

Resident Set Management

§ how small or big should resident set be?

less memory allocated more memory allocated

more processes fit in main memory

higher incidence of page faults per process

but

fewer processes fit in main memory

after certain point, more memory doesn’t noticeably help

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.27

Resident Set Management: Fixed RS

§ fixed: each process given fixed number of page frames process may have resident

§ determined by:• type of process (e.g., interactive, batch)• suggestion of programmer and/or sys mgr

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.28

Resident Set Management: Variable RS

§ variable: number of page frames process may have resident varies during life of program• e.g., if have high PFR, may get more frames• e.g., if have low PFR, may lose frames

§ more powerful but:• requires OS overhead to monitor PFR behaviour

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.29

Resident Set Management: Scope

§ when there’s a page fault, and you need to get a frame, where do you look?

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.30

Resident Set Management: Scope

§ when there’s a page fault, and you need to get a frame, where do you look?

§ local: select only from frames holding pages of the process that had the page fault

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 6

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.31

Resident Set Management: Scope

§ when there’s a page fault, and you need to get a frame, where do you look?

§ local: select only from frames holding pages of the process that had the page fault

§ global: select from any frame in memory (of any process)

§ size and scope are related…

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.32

RS Management: Size/Scope Combos

§ fixed + local:• can use any replacement policy already discussed• tricky to ‘guess’ right number of frames to allocate

for good performance across all processes

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.33

RS Management: Size/Scope Combos

§ fixed + local§ variable + global:

• easiest to implement• OS maintains “free frame list”: upon PF, attach a

free frame to process’ list of frames§ processes that PF a lot get more frames

• when no free frames, pick using any policy already discussed

• may degrade overall performance§ possible fix?

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.34

RS Management: Size/Scope Combos

§ fixed + local§ variable + global§ variable + local:

• when new proc starts, give it some frames• page faults fill up initial frame allocation• occasionally re-evaluate the allocation of frames to

this process, adjust as necessary • an example of this scheme…

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.35

Denning’s Working Set

§ working set = W(t, ? )

is the set of pages of the process that have been referenced in the last ? time units

§ look at example from Stallings…

parameter: interval of time over which process is observed (measured in virtual time units)

some virtual time, t,

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.36

Denning’s Working Set

5432∆ →

241517171824181724231815

2424242424t→

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 7

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.37

Denning’s Working Set

5432∆ →

2415171718241817242318

24,1524,1524,1524,15152424242424

t→

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.38

Denning’s Working Set

5432∆ →

24151717182418172423

24,15,1824,15,1824,15,1815,181824,1524,1524,1524,15152424242424

t→

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.39

Denning’s Working Set

5432∆ →

241517171824181724

24,15,18,2324,15,18,2315,18,2318,232324,15,1824,15,1824,15,1815,181824,1524,1524,1524,15152424242424

t→

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.40

Denning’s Working Set

5432∆ →

2415171718241817

gg18,23,2423,242424,15,18,2324,15,18,2315,18,2318,232324,15,1824,15,1824,15,1815,181824,1524,1524,1524,15152424242424

t→

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.41

Denning’s Working Set

5432∆ →

24151717182418

15,18,23,24,1718,23,24,1723,24,1724,1717gg18,23,2423,2424

24,15,18,2324,15,18,2315,18,2318,232324,15,1824,15,1824,15,1815,181824,1524,1524,1524,15152424242424

t→

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.42

Denning’s Working Set

5432∆ →

g17,15,2417,15,2415,242424,18,17,1518,17,1517,1517,1515

gg18,171717gg24,18,1718,1717

24,17,18g18,24g18g24,17,18g18,2424

18,23,24,17g24,17,1817,181815,18,23,24,1718,23,24,1723,24,1717,2417

gg18,23,2423,242424,15,18,2324,15,18,2315,18,2318,232324,15,1824,15,1824,15,1815,181824,1524,1524,1524,15152424242424

t→

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 8

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.43

WS in a Program

Time →

WSS

transient

stable

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.44

Using WS

§ each process uses pages in its WS§ goal of virtual memory manager:

keep working set resident• so allocate/remove frames as program runs

§ what to do if we run out of free frames?

keep working set resident

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.45

Using WS

§ system wide, S WSSi is demand for frames§ if > number of frames:

• suspend a process using some criterion• make its frames available for re-allocation

§ if < number of frames by some threshold ? , admit another process

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.46

§ system wide, S WSSi is demand for frames§ if > number of frames:

• suspend a process using some criterion• make its frames available for re-allocation

§ if < number of frames by some threshold ? , admit another process

§ WSS provides implicit load control in addition to WS management

Using WS

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.47

Implementing WS

§ need timer • so can examine WS every t time units

§ need to mark pages• so know if has been referenced during window

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.48

Implementing WS

§ need timer • so can examine WS every t time units

§ need to mark pages• so know if has been referenced during window

§ but:• timer/marking impractical• no determinable optimum for ∆

§ so how do we do this in “real life” ?

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 9

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.49

Really Implementing WS

§ instead of watching WS, look only at rate of PFs§ what if PFR for a process is above a threshold θU ?

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.50

Really Implementing WS

§ instead of watching WS, look only at rate of PFs§ what if PFR for a process is above a threshold θU ?

• process having too many PFs so needs more frames allocated to it

§ what if PFR for a process is below a threshold θL?

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.51

Really Implementing WS

§ instead of watching WS, look only at rate of PFs§ what if PFR for a process is above a threshold θU ?

• process having too many PFs so needs more frames allocated to it

§ what if PFR for a process is below a threshold θL?• process has more than enough frames, so can steal

some for allocation elsewhere

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.52

Really Implementing WS

more frames →

PFR

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.53

Really Implementing WS

more frames →

PFR

θU

θL

arrange WS so PFR is between thresholds always

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.54

Page Fault Frequency: PFF

§ PFF: really just the time between page faults§ need a Use bit per frame: set to 1 on each access§ whenever PF happens, log virtual time since last PF

for this process§ define threshold F:

• if time since last PF is < F, add a frame to resident set

• if time since last PF is > F, discard all pages in frames where U=0 (reduce resident set size) and clear all U bits on remaining page frames

§ can use two thresholds for finer control

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 10

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.55

PFF Performance

§ good in “steady-state”§ what about in locality transitions?

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.56

PFF Performance

§ good in “steady-state”§ what about in locality transitions?

• characterized by sudden high demand for new pages

§ PFF becomes short (i.e., PFR is high)• so is < F, so we are adding frames• but frames from this process are not released

until PFs are far enough apart in time (PFR is low)§ so PFF is quick to give frames, slow to reclaim

them.

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.57

Improving PFF

§ want way to be able to get rid of pages fast when “lots is happening”• so need F to be smaller when “it should be”

§ try variable-interval sampled working set (VSWS)• evaluate WS at sampling interval (elapsed virtual

time)

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.58

VSWS

§ at start of interval:• clear all use bits

§ at end of interval:• only referenced pages have U=1: keep these• release all other pages

§ RS size decreases only at end of an interval§ RS size can increase during interval as faulted

pages are added to RS

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.59

VSWS

§ uses 3 parameters:• M: minimum duration of sampling interval• L: maximum duration of sampling interval• Q: # of PFs allowed between successive samples

§ if virtual time, t, since last sampling reaches L:• suspend process• scan use bits

§ if Q PFs occur before L has elapsed:• if t < M, wait until M then suspend and scan use bits• if t ≥ M, suspend process and scan use bits

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.60

VSWS

§ goal: set parameters so sampling occurs on Qth

page fault after last scan§ VSWS trying to reduce peak memory demands

during transients by increasing sampling frequency• hence rate at which unused pages drop out of WS

§ used in GCOS 8 (Honeywell)§ more effective than PFF

• as easy to implement

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 11

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.61

Cleaning Policy

§ policy for how to ‘clean’ memory frames§ demand-cleaning: write frame out only when it

has been selected for replacement§ pre-cleaning: write out frame before needed for

replacement• can batch write several frames

§ which is better? downsides?

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.62

Cleaning Policy

§ precleaning: üefficient I/O by use of batch writingüleaves unmodified frames, faster to replace× modified frame may be modified again before

needed for replacement× need more writes, can clog disk ↔memory

bandwidth§ demand cleaning:

× a process may wait for 2 disk xfers before resuming

§ compromise?

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.63

Practical Cleaning Technique

§ use pre-cleaning with page buffering• writes out only modified pages from list • moves them to unmodified list• subsequent modification moves it back to

modified list

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.64

Load Control

§ virtual memory lets us increase multiprogramming

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.65

Load Control

§ virtual memory lets us increase multiprogramming§ “Too much of a good thing…” isn’t good

• [J.T. Kirk, commenting on tribbles]§ if multiprogramming level too low: CPU is

underutilized• why might this be?

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.66

Load Control

§ if multiprogramming level too low: CPU is underutilized• high probability of all processes being blocked• e.g., try “top” on UNIX/linux: see what CPU idle % is

§ if multiprogramming level too high: CPU is

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 12

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.67

Load Control

§ if multiprogramming level too low: CPU is underutilized• high probability of all processes being blocked• e.g., try “top” on UNIX/linux: see what CPU idle % is

§ if multiprogramming level too high: CPU is underutilized• each process has small RSS• so PFR goes up

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.68

Load Control

§ high PFR ⇒ processes blocked waiting for pages ⇒ idle time ⇒ CPU underutilized

§ but wait: it can get worse!

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.69

Thrashing

multiprogramming →

CPU

utili

zatio

n →

thrashing: point where most (eventually, all) of CPU time is spent waiting for and handling page faults, none for actual processing of jobs

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.70

(1) PFF- or WS-based techniques implicitly include load control§ by controlling size of RS

(2) Denning’s “L=S” criterion:§ adjust multiprogramming level so that:

mean time between faults ≈mean time to service faults

§ this is point of highest CPU utilization(3) “50% Rule”: keep use of paging mechanism at

50%§ again, point at which CPU utilization highest

Multiprogramming without Thrashing

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.71

Multiprogramming without Thrashing

(4) derived from Clock algorithm: monitor how fast cycle through list (pointer circles ring): if rate is low then eitheri. few PFs happening (few requests to advance ptr)ii. on each request, average number of frames scanned

is small ⇒ many unreferenced resident frameseither way: can increase multiprogramming

But, if rate is high then eitheri. high PFRii. hard to find replaceable frames then reduce multiprogramming

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.72

Reducing Multiprogramming

§ how reduce multiprogramming?• get rid of, i.e., suspend, some programs

§ how to choose…

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 13

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.73

Reducing Multiprogramming1. lowest priority process2. faulting process§ faulting because doesn’t have RS resident§ so suspending it causes little impact

3. last process activated§ is process least likely to have WS resident

4. process with smallest RS§ easiest to reload later§ unfair to programs with very good locality

5. largest process:§ frees up largest # frames with least effort

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.74

Secondary Memory

§ made necessary by volatility of primary memory§ made software “portable”§ early systems (as still used today) based on

magnetic recording• on drums• on tape• on disks

§ we’ll look mostly at disks• still mostly magnetic recording technology• optical coming into widespread use, but slower

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.75

Magnetic Recording

§ “ferrous” particles randomly distributed over recording medium (tape, disk)

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.76

Magnetic Recording

§ “ferrous” particles randomly distributed over recording medium (tape, disk)

§ in presence of electromagnetic field, can rearrange the particles into an orderly pattern

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.77

Magnetic Recording

§ “ferrous” particles randomly distributed over recording medium (tape, disk)

§ in presence of electromagnetic field, can rearrange the particles into an orderly pattern

§ imposing that magnetic field on the medium is done by a head

IMAGE © FROM: http://hyperphysics.phy-astr.gsu.edu/hbase/audio/tape2.html

in tape recorder, medium (tape) moves past stationary Read/Write head

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.78

Magnetic Disks

§ have ≥ 1 disk coated with magnetic material• may be made of mylar: floppy or flexible disk• may be made of aluminum: hard or rigid disk

(called platter )§ disk rotates on center axis§ head is fixed onto arm that moves radially

across surface of disk§ with floppy, head is in contact with medium

• like with tape recorder§ with hard disk, head never contacts medium

• floats above it on air cushion (e.g., 30 µm)

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 14

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.79

Magnetic Disks

recordable surface

arm travels across surface (head is on tip of arm)

disk rotates at, e.g., 3600 RPM(1 rev takes 16.667 ms)

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.80

Magnetic Disks

move arm to first radial position over surface‘write’ a signal onto disk at 2 ms intervals

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.81

Magnetic Disks

move arm to 2nd, 3rd, etc., radial position over surface‘write’ a signal onto disk at 2 ms intervals

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.82

Magnetic Disks

join ‘dots’ axially to make rings called tracks

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.83

Magnetic Disks

join ‘dots’ radially to make wedges called sectorsNOTE: “sector” usually refers to a single arc (strip of a track) between two radial lines, so, here each “track” is said to have 8 sectors (also called blocks)

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.84

Disk Layout

§ each sector holds (typically) 512 bytes of data§ may have one “runt” sector at end of track§ track/sector layout handled by “hard format”

• drive usually hard formatted at factory§ some typical numbers:

• tracks: 80 on floppy disk, 9732 on hard disk• sectors per track: 63 on hard disk

CS571 Operating Systems Class 0708 Oct 03

© Charles M Snow 15

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.85

Disk Layout

§ hard disks can have multiple platters per spindle• and use both top and bottom surfaces of each

platter§ track j on top surface of platter i is also track j

on bottom surface of platter i• same for all n platters because all arms move

together§ think of projecting (geometrically) all tracks j:

you’d have a cylinder§ CHS=6296/16/63, 512 bytes per sector ⇒

3,249,340,416 bytes raw capacityCS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.86

Using Disks

§ what are timing considerations?§ data rate: how fast do bits move by the head?

• 3600 RPM, 60 sectors/track ⇒ ≈ 1.75 Mbytes/sec• drives typically have buffer memory to smooth-

out data rate• have different data xfer rates:

• but head has to be in right place…

24.244.254.2

Sustained write

Sustained read

Peak medium xfer

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.87

Using Disks

§ data rate: how fast do bits move by the head?§ moving the head called a seek :

• from one track to an adjacent track, typically 5 ms)• from one edge of the disk to the other (max. seek

distance) typically 20 ms§ usually work with average seek time as time to

seek half-way across the disk• typically 8.5 ms

§ and disk has to be in right place…

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.88

Using Disks

§ data rate: how fast do bits move by the head?§ moving the head called a seek§ once head is “on station” have to wait for

rotational delay: get the correct sector to where head is• determined by rotation speed• at 3600 RPM full rotation is 16.67 ms• average rotational delay is half a rotation: 8.33 ms

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.89

Using Disks

§ so average latency to access data is• average seek time + average rotational delay

§ these delays totally overwhelm data transfer delay times

§ anything we can do to mitigate these delays goes long way toward improving efficiency…

CS571 Operating Systems 08 Oct 2003 © C. M. Snow 2003 07.90

Optical Disks

§ delays for CDROM/CDRW optical disks are same as for magnetic disks, but worse:• rotation delay: disk spins more slowly and• change rotation motor speed: varies from 400 to

200 RPM (nominally, for audio CD)• seeks are slower (typ. average 100 – 120 ms)• another possible delay: focus time once head “on

stationӤ and, for DVD:

• layer change time