Page 1 CS162!Operating Systems and!Systems Programming!Lecture 10!Caches and TLBs"February 23, 2011!Ion Stoica!http://inst.eecs.berkeley.edu/~cs162!Lec 10.2!2/23! Ion Stoica CS162 ©UCB Spring 2011!Review: Address Segmentation "1111 1111"stack!heap!code!data!Virtual memory view"Physical memory view"data!heap!stack!0000 0000"0001 0000"0101 0000"0111 0000"1110 000"0000 0000"0100 0000"1000 0000"1100 0000"1111 0000"Seg #"base"limit"00"0001 0000"10 0000"01"0101 0000"10 0000"10"0111 0000"1 1000"11"1011 0000"1 0000"seg #! offset"code!Lec 10.3!2/23! Ion Stoica CS162 ©UCB Spring 2011!Review: Address Segmentation "1111 1111"stack!heap!code!data!Virtual memory view"Physical memory view"data!heap!stack!0000 0000"0100 0000"1000 0000"1100 0000"seg #! offset"code!What happens if stack grows to 1110 0000?!1110 0000"0000 0000"0001 0000"0101 0000"0111 0000"1110 000"Seg #"base"limit"00"0001 0000"10 0000"01"0101 0000"10 0000"10"0111 0000"1 1000"11"1011 0000"1 0000"Lec 10.4!2/23! Ion Stoica CS162 ©UCB Spring 2011!Review: Address Segmentation "1111 1111"stack!heap!code!data!Virtual memory view"Physical memory view"data!heap!stack!0000 0000"0100 0000"1000 0000"1100 0000"1110 0000"seg #! offset"code!No room to grow!! Buffer overflow error!0000 0000"0001 0000"0101 0000"0111 0000"1110 000"Seg #"base"limit"00"0001 0000"10 0000"01"0101 0000"10 0000"10"0111 0000"1 1000"11"1011 0000"1 0000"Page 2 Lec 10.5!2/23! Ion Stoica CS162 ©UCB Spring 2011!Review: Paging"1111 1111"stack!heap!code!data!Virtual memory view"0000 0000"0100 0000"1000 0000"1100 0000"1111 0000"page #!offset"Physical memory view"data!code!heap!stack!0000 0000"0001 0000"0101 000"0111 000"1110 0000"11111 11101"11110 11100"11101 null "11100 null "11011 null"11010 null"11001 null"11000 null"10111 null"10110 null"10101 null"10100 null"10011 null"10010 10000"10001 01111"10000 01110"01111 null"01110 null "01101 null"01100 null"01011 01101 "01010 01100 "01001 01011"01000 01010"00111 null"00110 null"00101 null "00100 null "00011 00101"00010 00100"00001 00011"00000 00010"Page Table"Lec 10.6!2/23! Ion Stoica CS162 ©UCB Spring 2011!Review: Paging"1111 1111"stack!heap!code!data!Virtual memory view"0000 0000"0100 0000"1000 0000"1100 0000"page #!offset"Physical memory view"data!code!heap!stack!0000 0000"0001 0000"0101 000"0111 000"1110 0000"11111 11101"11110 11100"11101 null "11100 null "11011 null"11010 null"11001 null"11000 null"10111 null"10110 null"10101 null"10100 null"10011 null"10010 10000"10001 01111"10000 01110"01111 null"01110 null "01101 null"01100 null"01011 01101 "01010 01100 "01001 01011"01000 01010"00111 null"00110 null"00101 null "00100 null "00011 00101"00010 00100"00001 00011"00000 00010"Page Table"1110 0000"What happens if stack grows to 1110 0000?!Lec 10.7!2/23! Ion Stoica CS162 ©UCB Spring 2011!stack!Review: Paging"1111 1111"stack!heap!code!data!Virtual memory view"0000 0000"0100 0000"1000 0000"1100 0000"page #!offset"Physical memory view"data!code!heap!stack!11111 11101"11110 11100"11101 10111"11100 10110"11011 null"11010 null"11001 null"11000 null"10111 null"10110 null"10101 null"10100 null"10011 null"10010 10000"10001 01111"10000 01110"01111 null"01110 null"01101 null"01100 null"01011 01101 "01010 01100 "01001 01011"01000 01010"00111 null"00110 null"00101 null "00100 null "00011 00101"00010 00100"00001 00011"00000 00010"Page Table"0000 0000"0001 0000"0101 000"0111 000"1110 0000"Allocate new pages where room!!1110 0000"Lec 10.8!2/23! Ion Stoica CS162 ©UCB Spring 2011!stack!Review: Two-Level Paging"1111 1111"stack!heap!code!data!Virtual memory view"0000 0000"0100 0000"1000 0000"1100 0000"page1 #! offset"Physical memory view"data!code!heap!stack!0000 0000"0001 0000"0101 000"0111 000"1110 0000"page2 #!111 "110 null"101 null"100 "011 null"010 "001 null"000 "11 11101 "10 11100"01 10111"00 10110"11 01101 "10 01100"01 01011"00 01010"11 00101 "10 00100"01 00011"00 00010"11 null "10 10000"01 01111"00 01110"Page Tables"(level 2)"Page Table"(level 1)"1110 0000"Page 3 Lec 10.9!2/23! Ion Stoica CS162 ©UCB Spring 2011!stack!Review: Two-Level Paging"stack!heap!code!data!Virtual memory view"1001 0000"Physical memory view"data!code!heap!stack!0000 0000"0001 0000"1000 0000"1110 0000"111 "110 null"101 null"100 "011 null"010 "001 null"000 "11 11101 "10 11100"01 10111"00 10110"11 01101 "10 01100"01 01011"00 01010"11 00101 "10 00100"01 00011"00 00010"11 null "10 10000"01 01111"00 01110"Page Tables"(level 2)"Page Table"(level 1)"Lec 10.10!2/23! Ion Stoica CS162 ©UCB Spring 2011!stack!Review: Inverted Table"1111 1111"stack!heap!code!data!Virtual memory view"0000 0000"0100 0000"1000 0000"1100 0000"page #!offset"Physical memory view"data!code!heap!stack!11111 11101"11110 11100"11101 10111"11100 10110"10010 10000"10001 01111"10000 01110"01011 01101 "01010 01100 "01001 01011"1000 0 01010 "00011 00101"00010 00100"00001 00011"00000 00010"Inverted Table"hash(virt. page #) = "physical page #"0000 0000"0001 0000"0101 000"0111 000"1110 0000"1110 0000"Lec 10.11!2/23! Ion Stoica CS162 ©UCB Spring 2011!Address Translation Comparison"Advantages"Disadvantages"Segmentation!Fast context switching: Segment mapping maintained by CPU !External fragmentation!Paging (single-level page)!No external fragmentation!• Large size: Table size ~ virtual memory!• Internal fragmentation!Paged segmentation!• No external fragmentation!• Table size ~ memory used by program!• Multiple memory references per page access !• Internal fragmentation!Two-level pages!Inverted Table!Hash function more complex!Lec 10.12!2/23! Ion Stoica CS162 ©UCB Spring 2011!Simple Page Table Example"a"b"c"d"e"f"g"h"i"j"k"l"0x00"0x04"0x08"Virtual"Memory"a"b"c"d"e"f"g"h"i"j"k"l"0x00"0x04"0x0C"0x10"Physical"Memory"4"3"1"Page"Table"Example (4 byte pages)"0000 0000"0001 0000"0000 0100"0000 1100"0000 1000"0000 0100"virtual !page #!offset!Page 4 Lec 10.13!2/23! Ion Stoica CS162 ©UCB Spring 2011!How is the translation accomplished?"• What, exactly happens inside Memory Management Unit (MMU)?!• One possibility: Hardware Tree Traversal!– For each virtual
View Full Document