CS 341 Spring 1991 Operating Systems page 1 MEMORY MANAGEMENT -- EXAMPLES 1. Example This example shows some local page replacement algorithms applied to the reference string of a single process. 2. Address to (page, offset) Conversion Consider the following sequence of program space byte addresses gen- erated by an executing program (addresses, pages, and offsets all start with 0). 116 14 29 33 5 50 7 73 42 52 4 52 46 28 43 8 31 115 13 16 Convince yourself that if the page size is 16 bytes then the follow- ing is the sequence of page references and offsets corresponding to the above sequence of addresses. For example, 116 is 001110100 in binary. The right-most 4 bits give us the offset 4 and the rest of the bits give us the page number 7. The hardware splits the address into fields; the human divides by the page size more quickly. page 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 offset 4 14 13 1 5 2 7 9 10 4 4 4 14 12 11 8 15 3 13 0 3. First In First Out Suppose that the FIFO algorithm is used for page replacement (re- place the page that has been in physical memory the longest), and that the program has been allocated 3 page frames in physical memory. Then the following shows the page faults (indicated by *'s) and the program space pages in the 3 allocated page frames. Note the cyclic page replacement pattern. There are 15 page faults. 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 * * * * * * * * * * * * * * * page frame 1 7 7 7 2 2 2 2 4 4 4 0 0 0 0 0 0 0 7 7 7 page frame 2 0 0 0 0 3 3 3 2 2 2 2 2 1 1 1 1 1 0 0 page frame 3 1 1 1 1 0 0 0 3 3 3 3 3 2 2 2 2 2 1 4. Least Recently Used Now suppose that LRU replacement is used (replace the page that has been referenced least recently). The LRU stack is also shown. Note that the top 3 pages on the LRU stack are the ones in physical memory. There are 12 page faults. Memory Management Examples Handout 4 October 20, 1992 CS 341 Spring 1991 Operating Systems page 2 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 * * * * * * * * * * * * page frame 1 7 7 7 2 2 2 2 4 4 4 0 0 0 1 1 1 1 1 1 1 page frame 2 0 0 0 0 0 0 0 0 3 3 3 3 3 3 0 0 0 0 0 page frame 3 1 1 1 3 3 3 2 2 2 2 2 2 2 2 2 7 7 7 LRU stack 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 7 0 1 2 2 3 0 4 2 2 0 3 3 1 2 0 1 7 7 7 1 1 2 3 0 4 4 4 0 0 3 3 2 2 2 7 7 1 1 1 1 1 1 4 4 4 4 3 3 3 7 7 7 7 7 7 7 7 7 7 4 4 4 5. Belady's Optimal This non-realizable policy, called MIN or OPT and discovered by Be- + lady , calls for replacing the page that will be needed or refer- enced furthest in the future. The following shows the page faults (indicated by *'s) and the program space pages in the 3 allocated page frames. There are 9 page faults. 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 * * * * * * * * * page frame 1 7 7 7 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 7 page frame 2 0 0 0 0 0 0 4 4 4 0 0 0 0 0 0 0 0 0 0 page frame 3 1 1 1 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 6. Working Set Now suppose that the working set policy with a window size of 3 is used (the pages in physical memory are exactly those that have been referenced in the last 3 references). Note that working set has more faults but a smaller average memory allocation that LRU with the same parameter. There are 13 page faults. 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 * * * * * * * * * * * * * page frame 1 7 7 7 2 2 2 4 4 4 0 0 0 1 1 1 1 1 1 1 page frame 2 0 0 0 0 0 0 0 0 3 3 3 3 3 0 0 0 0 0 page frame 3 1 1 1 3 3 3 2 2 2 2 2 2 2 2 7 7 7 LRU ordered 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 working set 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 7 0 1 2 3 0 4 2 0 3 1 2 0 1 7 Average memory allocation is 54/20 = 2.70 frames -------------------- + Immortalized in the 1987 song by Aerosmith, "Dude Looks Like Bela- dy". Memory Management Examples Handout 4 October 20, 1992