Exam 3/Final Review
Exam 3 u Mean adjusted score: 62% ( C ) u Correct multiple choice answers: 1. D 2. B 3. E 4. A 5. E 6. C 7. A 8. B or C 9. E 10. B 11. C
Problem 4 u Assume a disk has 100 cylinders labeled 0-99, the read- write head is positioned over cylinder 52 heading toward cylinder 0, accessing data requires 1 time unit, and incoming requests arrive as follows: u What is the order of the requests which will be serviced by time 64 (cylinder of request is given) by the LOOK disk scheduling algorithm? Arrival time Cylinder
Problem (52,0) (26,27) (20,34) (10,45) (29,64) Time Cylinder
Problem 5 u Assume a disk has 100 cylinders labeled 0-99, the read- write head is positioned over cylinder 21 heading toward cylinder 0, accessing data requires 1 time unit, and pending requests are as follows: 1, 16, 24, 71, 8, 18, 94, 3 (listed in order of arrival). Which disk scheduling algorithm will finish servicing the requests first? SSTF (break tie by moving toward cylinder 0.) LOOK FCFS C-Scan None of the above: there is a tie.
Problem 5 u SSTF (21 – 18) + 1 Tie between 18 and 24, move to 18 +(18 – 16) + 1 +(16 – 8) + 1 Tie between 8 and 24, move to 8 +(8 – 3) + 1 +(3 – 1) + 1 +(24 – 1) + 1 +(71 – 24) + 1 +(94 – 71) + 1 =
Problem 5 u Look (21 – 18) + 1 +(18 – 16) + 1 +(16 – 8) + 1 +(8 – 3) + 1 +(3 – 1) + 1 Do not go to 0, turn around +(24 – 1) + 1 +(71 – 24) + 1 +(94 – 71) + 1 =
Problem 5 u FCFS (21 – 1) + 1 +(16 – 1) + 1 +(24 – 16) + 1 +(71 – 24) + 1 +(71 – 8) + 1 +(18 – 8) + 1 +(94 – 18) + 1 +(94 – 3) + 1 =
Problem 5 u C-Scan (read/write heading toward zero) (21 – 18) + 1 +(18 – 16) + 1 +(16 – 8) + 1 +(8 – 3) + 1 +(3 – 1) + 1 +(1 – 0) +(99 – 0) +(99 – 94) + 1 +(94 – 71) + 1 +(71 – 24) + 1 +(24 – 1) + 1 =
Final Exam Review u More disk scheduling u Exponential moving average for predicting next burst u Banker’s algorithm
SSTF (static) u Assume the R/W heads hold stationary when there is no pending request, and that seek decisions are never reversed on new arrival u What is the total time to service all requests? (28 – 3) (16 – 3) +1 + (58–16) (98 – 58) (98 – 71) (71 – 12) (56 – 12) + 1 = 256 Arrival TimeCylinder
SSTF (static) Arrival TimeCylinder
SSTF (static) Arrival TimeCylinder
SSTF (dynamic) u Assume the R/W heads continue moving toward cylinder 50 when there is no pending request, and that seek decisions can be changed dynamically u What is the total time to service all requests? (28 – 3) (16 – 3) +1 + (58–16) (98 – 58) (98 – 71) (71 – 48) + (56 – 48 ) (56 – 12) + 1 = 229 Arrival TimeCylinder
SSTF (dynamic) Arrival TimeCylinder
SSTF (dynamic) Arrival TimeCylinder
Page Replacement
Clock page replacement (2 nd chance) u The use bit is shown to the right of the frames u The arrow denotes the position of the clock pointer 0, 1, 3, 5, 2, 1, 4, 5,
Clock page replacement (2 nd chance) u The use bit is shown to the right of the frames u The arrow denotes the position of the clock pointer 0, 1, 3, 5, 2, 1, 4, 5,
Clock page replacement (2 nd chance) u The use bit is shown to the right of the frames u The arrow denotes the position of the clock pointer 0, 1, 3, 5, 2, 1, 4, 5,
Clock page replacement (2 nd chance) u The use bit is shown to the right of the frames u The arrow denotes the position of the clock pointer 0, 1, 3, 5, 2, 1, 4, 5,
Clock page replacement (2 nd chance) u The use bit is shown to the right of the frames u The arrow denotes the position of the clock pointer 0, 1, 3, 5, 2, 1, 4, 5,
Clock page replacement (2 nd chance) u The use bit is shown to the right of the frames u The arrow denotes the position of the clock pointer 0, 1, 3, 5, 2, 1, 4, 5,
LRU approximation (shift bits) u Each ‘c’ denotes a clock shift event u The reference bit and clock bits are shown to the right of the frame 0, 1, 3, 5, c, 3, 2, c, 1, 2, 4, c,
LRU approximation (shift bits) u Each ‘c’ denotes a clock shift event u The reference bit and clock bits are shown to the right of the frame 0, 1, 3, 5, c, 3, 2, c, 1, 2, 4, c,
LRU approximation (shift bits) u Each ‘c’ denotes a clock shift event u The reference bit and clock bits are shown to the right of the frame 0, 1, 3, 5, c, 3, 2, c, 1, 2, 4, c,
LRU approximation (shift bits) u Each ‘c’ denotes a clock shift event u The reference bit and clock bits are shown to the right of the frame 0, 1, 3, 5, c, 3, 2, c, 1, 2, 4, c,
LRU approximation (shift bits) u Each ‘c’ denotes a clock shift event u The reference bit and clock bits are shown to the right of the frame 0, 1, 3, 5, c, 3, 2, c, 1, 2, 4, c,
LRU approximation (shift bits) u Each ‘c’ denotes a clock shift event u The reference bit and clock bits are shown to the right of the frame 0, 1, 3, 5, c, 3, 2, c, 1, 2, 4, c,
LRU approximation (shift bits) u Each ‘c’ denotes a clock shift event u The reference bit and clock bits are shown to the right of the frame 0, 1, 3, 5, c, 3, 2, c, 1, 2, 4, c,
LRU approximation (shift bits) u Each ‘c’ denotes a clock shift event u The reference bit and clock bits are shown to the right of the frame 0, 1, 3, 5, c, 3, 2, c, 1, 2, 4, c,
Banker’s Algorithm
Example of Banker’s Algorithm u 5 processes P 0 through P 4 ; 3 resource types A (4 instances), B (5 instances), and C (6 instances). u Snapshot at time T 0 : AllocationMaxAvailable A B CA B C A B C P P P P P
Example of Banker’s Algorithm u Is the system currently safe? u Suppose a request for came from P 1. AllocationMaxAvailable A B CA B C A B C P P P P P Need A B C
Example of Banker’s Algorithm u Suppose a request for came from P 1 Is the request legal? Are the resources available? AllocationMaxAvailable A B CA B C A B C P P P P P Need A B C
Example of Banker’s Algorithm u Suppose a request for came from P 1 Make a hypothetical grant of the resources Test to see if the state is safe AllocationMaxAvailable A B CA B C A B C P P P P P Need A B C
Example of Banker’s Algorithm u Suppose a request for came from P 1 Make a hypothetical grant of the resources Test to see if the state is safe AllocationMaxWork A B CA B C A B C P P P P P Need A B C P1P1
Example of Banker’s Algorithm u Suppose a request for came from P 1 Make a hypothetical grant of the resources Test to see if the state is safe AllocationMaxWork A B CA B C A B C P P P P P Need A B C P1P1
Example of Banker’s Algorithm u Suppose a request for came from P 1 Make a hypothetical grant of the resources Test to see if the state is safe AllocationMaxWork A B CA B C A B C P P P P P Need A B C P1P4P3P1P4P3
Example of Banker’s Algorithm u Suppose a request for came from P 1 Make a hypothetical grant of the resources Test to see if the state is safe AllocationMaxWork A B CA B C A B C P P P P P Need A B C P1P4P3P0P1P4P3P0
Example of Banker’s Algorithm u Suppose a request for came from P 1 Make a hypothetical grant of the resources Test to see if the state is safe AllocationMaxWork A B CA B C A B C P P P P P Need A B C P1P4P3P0P2P1P4P3P0P2
Example of Banker’s Algorithm u Suppose a request for came from P 1 Make a hypothetical grant of the resources Test to see if the state is safe AllocationMaxWork A B CA B C A B C P P P P P Need A B C P1P4P3P0P2P1P4P3P0P2
Detection Algorithm 1.Let Work and Finish be vectors of length m and n, respectively Initialize: (a) Work :- Available (b)For i = 1,2, …, n, if Allocation i 0, then Finish[i] := false;otherwise, Finish[i] := true. 2.Find an index i such that both: (a)Finish[i] = false (b)Request i Work If no such i exists, go to step 4.
Detection Algorithm 3.Work := Work + Allocation i Finish[i] := true go to step 2. 4.If Finish[i] = false, for some i, 1 i n, then the system is in deadlock state. Moreover, if Finish[i] = false, then P i is deadlocked. Algorithm requires an order of m x n 2 operations to detect whether the system is in deadlocked state.
Example of Detection Algorithm u Five processes P 0 through P 4 ; three resource types A (7 instances), B (2 instances), and C (6 instances). u Snapshot at time T 0 : AllocationRequestAvailable A B C A B C A B C P P P P P u Sequence will result in Finish[i] = true for all i.
Example (Cont.) u P 2 requests an additional instance of type C. Request A B C P P P P P u State of system? Can reclaim resources held by process P 0, but insufficient resources to fulfill other processes; requests. Deadlock exists, consisting of processes P 1, P 2, P 3, and P 4.