In: Computer Science
b) Given fixed memory partitions of 200 KB, 100 KB, 400 KB, 300 KB, and 400 KB (in order), how would each of the algorithms from (a) place processes in memory if they required 187 KB, 228 KB, 126 KB, 306 KB (in order)? c) A system has five page frames. The time of loading, time of last access, and the Referenced and Modified bit for each page are shown in the following table (with time in clock ticks). Frame Loaded Last referenced Referenced Modified 0 76 115 1 0 1 99 118 1 0 2 68 76 0 1 3 63 78 1 0 4 12 86 0 1 For each of the following algorithms, which page would be the next to be replaced? i. Second chance ii. Clock
b) memory partitions of 200 KB, 100 KB, 400 KB, 300 KB, and 400 KB and assuming the algorithms are first fit, best fit and worst fit:
Order : 187 KB, 228 KB, 126 KB, 306 KB
First Fit:
187KB is put in 200KB partition
current situation: 13KB(new partition),100KB,400KB,300KB,400KB
228KB is put in 400KB partition
current: 13KB,100KB,172KB(new partition),300KB,400KB
126KB is put in 172KB partition
current: 13KB,100KB,46KB(new partition),300KB,400KB
306KB is put in 400KB partition
current: 13KB,100KB,46KB,300KB,94KB(new partition)
Best Fit:
187KB is put in 200KB partition
current situation: 13KB(new partition),100KB,400KB,300KB,400KB
228KB is put in 300KB partition
current situation: 13KB,100KB,400KB,72KB(new partition),400KB
126KB is put in 400KB partition
current: 13KB,100KB,274KB(new partition),72KB,400KB
306KB is put in 400KB partition:
current: 13KB,100KB,274KB,72KB,94KB(new partition)
Worst Fit:
187KB is put in 400KB partition
current situation: 200KB,100KB,213KB(new partition),300KB,400KB
228KB is put in 400KB partition
current situation: 200KB,100KB,213KB,300KB,172KB(new partition)
126KB is put in 300KB partition
current situation: 200KB,100KB,213KB,174KB(new partition),172KB
306KB must wait
2nd part:
Frame | Loaded | Last Referenced | Referenced | Modified |
0 | 76 | 115 | 1 | 0 |
1 | 99 | 118 | 1 | 0 |
2 | 68 | 76 | 0 | 1 |
3 | 63 | 78 | 1 | 0 |
4 | 12 | 86 | 0 | 1 |
Second chance:
In case of second chance algorithm the frame to be replaced next is frame 4 as it arrived the earliest and has referenced bit = 0
Clock algorithm:
When we check the last referenced time of each frame we see last examined page is 1 and the earliest examined frame is 2 so if we keep them in order we get
1 0 4 3 2 the hand of the clock will be pointing to frame 1.
But the referenced bit of frame 1 is 1 so it cant be evicted, so we set the referenced bit of frame 1 to 0 and move to next frame
Next frame is frame 0, whose referenced bit again is 1, so moving to the next frame
Next frame is 4 and the referenced bit of 4 is 0 so frame 4 will be evicted.