CS 162 Fall 2004 Discussion Section Exercise ============================================ TA: Yitao Duan, Steve Martin (SP04) 1. What is the cause of thrashing? How can we 'solve' thrashing? A: Thrashing occurs because the system doesn't know when it has taken on more work than it can handle. Large amount of computing time is spent in paging overhead, response time goes down. Increase amount of memory, decrease degree of multiprogramming. Can also try changing paging algorithm. 2. What is a working set? How would knowing the working set be useful? A: The set of pages a process is currently working with, the set needed to avoid thrashing. We can avoid scheduling a process if its working set does not fit in main memory, which will avoid thrashing. 3. Page Replacement: Consider a demand paging system with four pages of physical memory that executes the following reference stream. 1; 2; 3; 4; 1; 2; 3; 5; 1; 2; 3; 6 The numbers in this sequence are virtual page numbers (vpn) a) Assuming that memory starts empty and the system uses a FIFO page replacement strategy, determine the number and type of page faults that will occur and the final contents of memory. A: There were nine page faults. Reference Fault Type Memory Frames vpn to be replaced ========================================================= 1 Yes Compulsory | 1 | | | | - --------------------------------------------------------- 2 Yes Compulsory | 1 | 2 | | | - --------------------------------------------------------- 3 Yes Compulsory | 1 | 2 | 3 | | - --------------------------------------------------------- 4 Yes Compulsory | 1 | 2 | 3 | 4 | 1 --------------------------------------------------------- 1 no - | 1 | 2 | 3 | 4 | 1 --------------------------------------------------------- 2 no - | 1 | 2 | 3 | 4 | 1 --------------------------------------------------------- 3 no - | 1 | 2 | 3 | 4 | 1 --------------------------------------------------------- 5 Yes Compulsory | 5 | 2 | 3 | 4 | 2 --------------------------------------------------------- 1 Yes Capacity/Policy | 5 | 1 | 3 | 4 | 3 --------------------------------------------------------- 2 Yes Capacity/Policy | 5 | 1 | 2 | 4 | 4 --------------------------------------------------------- 3 Yes Capacity/Policy | 5 | 1 | 2 | 3 | 5 --------------------------------------------------------- 6 Yes Compulsory | 6 | 1 | 2 | 3 | 1 --------------------------------------------------------- b) Determine the number and type of page faults that will occur and the final contents of memory, assuming the system uses the LRU page replacement strategy. A: There were six page faults. Reference Fault Type Memory Frames vpn to be replaced ========================================================= 1 Yes Compulsory | 1 | | | | - --------------------------------------------------------- 2 Yes Compulsory | 1 | 2 | | | - --------------------------------------------------------- 3 Yes Compulsory | 1 | 2 | 3 | | - --------------------------------------------------------- 4 Yes Compulsory | 1 | 2 | 3 | 4 | 1 --------------------------------------------------------- 1 no - | 1 | 2 | 3 | 4 | 2 --------------------------------------------------------- 2 no - | 1 | 2 | 3 | 4 | 3 --------------------------------------------------------- 3 no - | 1 | 2 | 3 | 4 | 4 --------------------------------------------------------- 5 Yes Compulsory | 1 | 2 | 3 | 5 | 1 --------------------------------------------------------- 1 no - | 1 | 2 | 3 | 5 | 2 --------------------------------------------------------- 2 no - | 1 | 2 | 3 | 5 | 3 --------------------------------------------------------- 3 no - | 1 | 2 | 3 | 5 | 5 --------------------------------------------------------- 6 Yes Compulsory | 1 | 2 | 3 | 6 | 1 --------------------------------------------------------- c) What if MIN is used? Reference Fault Type Memory Frames vpn to be replaced ========================================================= 1 Yes Compulsory | 1 | | | | - --------------------------------------------------------- 2 Yes Compulsory | 1 | 2 | | | - --------------------------------------------------------- 3 Yes Compulsory | 1 | 2 | 3 | | - --------------------------------------------------------- 4 Yes Compulsory | 1 | 2 | 3 | 4 | 4 --------------------------------------------------------- 1 no - | 1 | 2 | 3 | 4 | 4 --------------------------------------------------------- 2 no - | 1 | 2 | 3 | 4 | 4 --------------------------------------------------------- 3 no - | 1 | 2 | 3 | 4 | 4 --------------------------------------------------------- 5 Yes Compulsory | 1 | 2 | 3 | 5 | 5 --------------------------------------------------------- 1 no - | 1 | 2 | 3 | 5 | 5 --------------------------------------------------------- 2 no - | 1 | 2 | 3 | 5 | 5 --------------------------------------------------------- 3 no - | 1 | 2 | 3 | 5 | 5 --------------------------------------------------------- 6 Yes Compulsory | 1 | 2 | 3 | 6 | 1 --------------------------------------------------------- http://www.cs.berkeley.edu/~duan/teaching/cs162-fa04/