How does a memory managemet unit map a virtual address to a physical address
How does a memory managemet unit map a virtual address to a physical address
If a computer system has a main memory of 1mb and virtual address space of 16mb while the disk block size is 1kb. How does the memory management unit map a virtual address to a physical address
I assume you intend to ask how does MMU maps virtual memory to physical memory as in your question description. To start off, virtual memory is managed by operating systems. MMU only provides hardware mechanism to take advantage of it. Operating systems will keep a map of virtual_address - physical_address for each individual process. For example if a program uses virtual page 0, 1, 2, 3, operating systems can map these pages to physical pages as 64, 128, 256, 512. Since the virtual address space is larger than physical address space, not all of the virtual memory will be mapped to physical memory at any moment if physical memory cannot hold all of them. Therefore, some of the data would be swapped out to disk, and thus not present in physical memory. For example, lets simplify your case by assuming that the virtual memory has 8 pages, but the physical memory can only hold 4 pages of data. If the process has data on virtual page 0,1,2,3,4, apparently physical memory cannot hold all 5 pages. Therefore one of the virtual pages will be put in physical memory, and the memory mappings of system will be something like 0-2, 1-1, 2-3, 4-0, and in this case virtual page 3 will be swapped out in disk. Those swapped out pages will only be brought back to main memory by OS if the program needs the data, and one of the pages previously present in main memory needs to be swapped out to make space. Algorithms to determine which page to swap out is another topic for example, LRU, clock algorithm. In reality the memory system is more complicated than this scenario, because modern operating systems allow multiple processes running in the system, and OS itself uses other techniques setting threshold to trigger page swapping, for example to make memory system more efficient.
Комментарии
Отправить комментарий