Virtual memory-how does it work? Step 1. When CPU wants to fetch an instruction, thevirtual address is sent to MMU and is translatedintoaphysicaladdress(intel)OXAAAAAA000XAAAAAAOOCore"i7PCOXABCDEFOOmov0x12345678%EAXOXABCDEFOOEAX0x000000000x0000000A11
Virtual memory – how does it work? • Step 1. When CPU wants to fetch an instruction, the virtual address is sent to MMU and is translated into a physical address. 11 PC 0xABCDEF00 mov 0x12345678 %EAX EAX 0x00000000 0x0000000A MMU 0xABCDEF00 0xAAAAAA00 0xAAAAAA00
Virtual memory -how does it work? Step 2. The memory returns the instructionaddressed in physical address.(intel)0XAAAAAA0OCore"i7PhysicalAddressPCOXABCDEF000XAAAAAA00moV0x12345678%EAXOXABCDEF00EAX0x000000000X0000000A12
Virtual memory – how does it work? • Step 2. The memory returns the instruction addressed in physical address. 12 PC 0xABCDEF00 mov 0x12345678 %EAX EAX 0x00000000 0x0000000A MMU 0xABCDEF00 0xAAAAAA00 Physical Address 0xAAAAAA00
Virtual memory -how does it work? Step 3. The CPU decodes the instruction-An instruction always stores virtual addresses, but notphysicaladdresses.(intel)0x13579A00Core"i7PhysicalAddressPCOXABCDEF000XAAAAAA00mOV0x12345678%EAX0x12345678EAX0x000000000X0000000Amov0x12345678%EAX13
Virtual memory – how does it work? • Step 3. The CPU decodes the instruction. – An instruction always stores virtual addresses, but not physical addresses. 13 PC 0xABCDEF00 mov 0x12345678 %EAX EAX 0x00000000 0x0000000A MMU 0x12345678 0x13579A00 mov 0x12345678 %EAX Physical Address 0xAAAAAA00
Virtual memory-how does it work? Step 4. With the help of the MMU, the targetmemory is retrieved.(intel)0x13579A00Core"i7PhysicalAddressPCOXABCDEFOO0XAAAAAA00012345678%EAXmov0x12345678EAX0X0000000A0x13579A000x0000000Amov0x12345678%EAX14
Virtual memory – how does it work? • Step 4. With the help of the MMU, the target memory is retrieved. 14 PC 0xABCDEF00 mov 0x12345678 %EAX EAX 0x00000000 0x0000000A MMU 0x12345678 0x13579A00 mov 0x12345678 %EAX 0x0000000A Physical Address 0xAAAAAA00 0x13579A00
Virtual memory - What is the good?Merit 1. Different processes use the same virtual addresses,theymaybetranslatedto differentphysical addresses- Recall the"pid"variable in theexampleusing fork()-The addresstranslationhelps theCPUto retrieve datainanoncontiguouslayout (the process address spaceis contiguous).VirtualAddressPhysicalAddressProcessX0x123456780x2468CD00Pr0cX:0x00000000AProcY: 0x00000000BProcessY0x123456780x13579A0015
Process X Process Y Physical Address Virtual memory – What is the good? • Merit 1. Different processes use the same virtual addresses, they may be translated to different physical addresses. – Recall the “pid” variable in the example using fork(). – The address translation helps the CPU to retrieve data in a noncontiguous layout (the process address space is contiguous ). 15 Proc Y: 0x00000000B 0x13579A00 0x12345678 Proc X: 0x00000000A 0x12345678 0x2468CD00 Virtual Address