"You've been living in a dream world, Neo'int main(void)($./same_addrint pid;PID 1234:0xbfe85e0c.pid=fork();PID1235:0xbfe85e0cprintf("pID%d:%p.ln"getpid(),&pid)$if(pid)Wait(NULL);return e;Can you guess the result?- Two different processes, the same variable name,carry different values-Usethesameaddress!(What? How COME?!)Well, what is the meaning of a memory address?!-Logical address:virtual memory-Address translationneeded (logical/virtual->physical)-Why we use virtual memory??6
“You’ve been living in a dream world, Neo” • Can you guess the result? – Two different processes, the same variable name, carry different values – Use the same address! (What? How COME?!) • Well, what is the meaning of a memory address?! – Logical address: virtual memory – Address translation needed (logical/virtual->physical) – Why we use virtual memory?? 6 int main(void) { int pid; pid = fork(); printf("PID %d: %p.\n", getpid(), &pid); if(pid) wait(NULL); return 0; } $ ./same_addr PID 1234: 0xbfe85e0c. PID 1235: 0xbfe85e0c. $ _
CPU working ... contiguous allocation? Each process is contained in a single section of memProcessCHoleProcessBHoleProcessA
CPU working . contiguous allocation? • Each process is contained in a single section of mem 7 Process A Process B Process C Hole Hole
CPU working ... contiguous allocation?. Problem #1..We also know that a process' memoryProcessCcan grow.HoleSo, does a process always have aProcessBchance to grow to reach its need?Holememory growthe.g., because of brk() callsProcessA8
CPU working . contiguous allocation? • Problem #1. 8 Process A Process B Process C Hole Hole memory growth e.g., because of brk() calls We also know that a process’ memory can grow. So, does a process always have a chance to grow to reach its need?
CPU working ... contiguous allocation?Problem #2..We are not talking about theprogram's size, but the process' size!What theCPU (or OS)can do is toWhatif wehaveaprocessgive up running ...that is larger that thephysical memory?So, we need to have the CPU designthat can understand processes so that:(1)theaddressspace isnolongerrequiredtobecontiguous.(2)itallowsaprocesstohaveasizebeyond the physical memory9
CPU working . contiguous allocation? • Problem #2. 9 Process A Process B Process C Hole Hole We are not talking about the program’s size, but the process’ size! What if we have a process that is larger that the physical memory? What the CPU (or OS) can do is to give up running . (1) the address space is no longer required to be contiguous. So, we need to have the CPU design that can understand processes so that: (2) it allows a process to have a size beyond the physical memory
Virtual memorysupportinmodernCPUs. The new design of the CPU includes a new module:the memory management unit (MMU)- MMU is designed to perform address translation.-TheMMUisanon-CPUdevicePhysical(inte)MemoryCore2ExrtrenMMUProgramMemoryMemoryBusANeWCPUAprocess'memoryisnolongercontiguousProgramCode10
Virtual memory support in modern CPUs • The new design of the CPU includes a new module: the memory management unit (MMU). – MMU is designed to perform address translation. – The MMU is an on-CPU device. 10