GATE 2007
184 questions
MCQ 1841-mark 184
Questions 141–145 of 184
Let a memory have four free blocks of sizes 4k, 8k, 20k, 2k. These blocks are allocated following the best-fit strategy. The allocation requests are stored in a queue as shown below.
The time at which the request for J7 will be completed will be
The time at which the request for J7 will be completed will be
Answer: (B)
Best fit gives each request the smallest free block that is big enough. Blocks are fixed (4k, 8k, 20k, 2k) and are not split. Requests are served in queue order, so a request that does not fit waits and the ones behind it wait too. A job runs for its usage time from the moment it gets a block, and jobs do not slow each other down.
t = 0: J1 (2k) takes the 2k block, ends at 4. J2 (14k) takes the 20k block, ends at 10. J3 (3k) takes the 4k block, ends at 2. J4 (6k) takes the 8k block, ends at 8.
J5 (6k): no block is free, so it waits. The 4k block frees at t = 2 and the 2k block at t = 4, but neither can hold 6k.
t = 8: J4 leaves. J5 takes the 8k block and ends at 12.
t = 10: J2 leaves. J6 (10k) fits only the 20k block, so it takes it and ends at 11.
t = 11: J6 leaves. For J7 (7k) the free blocks are 4k, 2k and 20k (the 8k block is busy until 12). Only the 20k block fits, so J7 takes it and runs 8 units.
J7 completes at .
Answer: (B)
t = 0: J1 (2k) takes the 2k block, ends at 4. J2 (14k) takes the 20k block, ends at 10. J3 (3k) takes the 4k block, ends at 2. J4 (6k) takes the 8k block, ends at 8.
J5 (6k): no block is free, so it waits. The 4k block frees at t = 2 and the 2k block at t = 4, but neither can hold 6k.
t = 8: J4 leaves. J5 takes the 8k block and ends at 12.
t = 10: J2 leaves. J6 (10k) fits only the 20k block, so it takes it and ends at 11.
t = 11: J6 leaves. For J7 (7k) the free blocks are 4k, 2k and 20k (the 8k block is busy until 12). Only the 20k block fits, so J7 takes it and runs 8 units.
J7 completes at .
Answer: (B)
A process has been allocated 3 page frames. Assume that none of the pages of the process are available in the memory initially. The process makes the following sequence of page references (reference string): 1, 2, 1, 3, 7, 4, 5, 6, 3, 1.
Least Recently Used (LRU) page replacement policy is a practical approximation to optimal page replacement. For the above reference string, how many more page faults occur with LRU than with the optimal page replacement policy?
Least Recently Used (LRU) page replacement policy is a practical approximation to optimal page replacement. For the above reference string, how many more page faults occur with LRU than with the optimal page replacement policy?
Answer: (C)
LRU (3 frames):
1 F [1]; 2 F [1,2]; 1 hit; 3 F [1,2,3]; 7 F, evict 2 [1,3,7]; 4 F, evict 1 [3,7,4]; 5 F, evict 3 [7,4,5]; 6 F, evict 7 [4,5,6]; 3 F, evict 4 [5,6,3]; 1 F, evict 5 [6,3,1].
Faults = 9.
Optimal (evict the page used farthest in the future, or never again):
1 F; 2 F; 1 hit; 3 F [1,2,3]; 7 F, evict 2 (never used again) [1,3,7]; 4 F, evict 7 [1,3,4]; 5 F, evict 4 [1,3,5]; 6 F, evict 5 [1,3,6]; 3 hit; 1 hit.
Faults = 7.
LRU has more faults.
Answer: (C)
1 F [1]; 2 F [1,2]; 1 hit; 3 F [1,2,3]; 7 F, evict 2 [1,3,7]; 4 F, evict 1 [3,7,4]; 5 F, evict 3 [7,4,5]; 6 F, evict 7 [4,5,6]; 3 F, evict 4 [5,6,3]; 1 F, evict 5 [6,3,1].
Faults = 9.
Optimal (evict the page used farthest in the future, or never again):
1 F; 2 F; 1 hit; 3 F [1,2,3]; 7 F, evict 2 (never used again) [1,3,7]; 4 F, evict 7 [1,3,4]; 5 F, evict 4 [1,3,5]; 6 F, evict 5 [1,3,6]; 3 hit; 1 hit.
Faults = 7.
LRU has more faults.
Answer: (C)
A process has been allocated 3 page frames. Assume that none of the pages of the process are available in the memory initially. The process makes the following sequence of page references (reference string): 1, 2, 1, 3, 7, 4, 5, 6, 3, 1.
If optimal page replacement policy is used, how many page faults occur for the above reference string?
If optimal page replacement policy is used, how many page faults occur for the above reference string?
Answer: (A)
Optimal replacement: when all frames are full and a fault occurs, replace the page whose next use is farthest in the future (or that is never used again).
Pages 1, 2, 3 each cause a fault (the second reference to 1 is a hit): 3 faults.
Page 7: the rest of the string is 4, 5, 6, 3, 1. Page 2 is never used again, so replace it. Fault.
Page 4: the rest is 5, 6, 3, 1. Page 7 is never used again, so replace it. Fault.
Page 5: the rest is 6, 3, 1. Page 4 is never used again, so replace it. Fault.
Page 6: the rest is 3, 1. Page 5 is never used again, so replace it. Fault.
Pages 3 and 1 are still in memory, so they are hits.
Total faults .
Answer: (A)
Pages 1, 2, 3 each cause a fault (the second reference to 1 is a hit): 3 faults.
Page 7: the rest of the string is 4, 5, 6, 3, 1. Page 2 is never used again, so replace it. Fault.
Page 4: the rest is 5, 6, 3, 1. Page 7 is never used again, so replace it. Fault.
Page 5: the rest is 6, 3, 1. Page 4 is never used again, so replace it. Fault.
Page 6: the rest is 3, 1. Page 5 is never used again, so replace it. Fault.
Pages 3 and 1 are still in memory, so they are hits.
Total faults .
Answer: (A)
A virtual memory system uses First In First Out (FIFO) page replacement policy and allocates a fixed number of frames to a process. Consider the following statements:
P: Increasing the number of page frames allocated to a process sometimes increases the page fault rate.
Q: Some programs do not exhibit locality of reference.
Which one of the following is TRUE?
P: Increasing the number of page frames allocated to a process sometimes increases the page fault rate.
Q: Some programs do not exhibit locality of reference.
Which one of the following is TRUE?
Answer: (B)
P is true. FIFO shows Bélády's anomaly. For the string 1 2 3 4 1 2 5 1 2 3 4 5, FIFO gives 9 faults with 3 frames but 10 faults with 4 frames.
Q is true. A program that jumps around, for example one that reads a row-major array column by column, has poor locality of reference.
Is Q the reason for P? No. The anomaly occurs because FIFO is not a stack algorithm: with more frames, the set of pages in memory need not contain the set held with fewer frames. It comes from FIFO's eviction rule, not from how a program accesses memory. LRU and optimal are stack algorithms and never show the anomaly, whatever the locality.
So both are true and Q does not explain P.
Answer: (B)
Q is true. A program that jumps around, for example one that reads a row-major array column by column, has poor locality of reference.
Is Q the reason for P? No. The anomaly occurs because FIFO is not a stack algorithm: with more frames, the set of pages in memory need not contain the set held with fewer frames. It comes from FIFO's eviction rule, not from how a program accesses memory. LRU and optimal are stack algorithms and never show the anomaly, whatever the locality.
So both are true and Q does not explain P.
Answer: (B)
Consider the following relation schemas :
b-Schema = (b-name, b-city, assets)
a-Schema = (a-num, b-name, bal)
d-Schema = (c-name, a-number)
Let branch, account and depositor be respectively instances of the above schemas. Assume that account and depositor relations are much bigger than the branch relation.
Consider the following query:
Which one of the following queries is the most efficient version of the above query ?
b-Schema = (b-name, b-city, assets)
a-Schema = (a-num, b-name, bal)
d-Schema = (c-name, a-number)
Let branch, account and depositor be respectively instances of the above schemas. Assume that account and depositor relations are much bigger than the branch relation.
Consider the following query:
Which one of the following queries is the most efficient version of the above query ?
Answer: (A)
Rule: do selections early, and join small results before big relations. and are much bigger than .
(C), (D) are invalid. They apply to , but has no attribute.
(B) joins with first. Both are big, and the Agra filter on is applied only afterwards. So the big join covers the negative-balance accounts of every branch.
(A) first selects the Agra branch (a few tuples), joins it with and then keeps only . Only this small set of accounts is joined with the big relation. This is the cheapest plan.
Answer: (A)
(C), (D) are invalid. They apply to , but has no attribute.
(B) joins with first. Both are big, and the Agra filter on is applied only afterwards. So the big join covers the negative-balance accounts of every branch.
(A) first selects the Agra branch (a few tuples), joins it with and then keeps only . Only this small set of accounts is joined with the big relation. This is the cheapest plan.
Answer: (A)