CS 147 Virtual Memory Prof. Sin Min Lee Anthony Palladino VIRTUAL MEMORY Why Virtual Memory? When computers were first being developed, memory was very costly and hard to come by. Computers were the size of warehouses, yet often only had memory which amounted to 128 kilobytes. The complication of running out of memory space during run-time began to surface and a solution was needed in order to alleviate this problem. A way to provide nearly limitless cheap memory was sought by programmers. What was developed was virtual memory. Initial Problems Many early programmers thought it too strange a concept to be pursued, and argued against it. Addressing initially was a problem before a stable process was developed. Many thought that virtual memory would simply be to expensive to implement correctly, as well as use too large a portion of the processors power. It was unclear at first how to mass produce the process for home use. Some Terminology Virtual Memory- VRAM- Virtual Random Access Memory Physical Memory – Actually hardware memory MMU – Memory management Unit Real Address – Physical address in memory Virtual address – address of virtual memory Memory address – address of physical memory Virtual Memory Features Virtual memory is much larger than real memory. Today’s Primary job for virtual memory is to avoid software conflicts. Conversions are done on the Page tables. MMU Controls the process. The TLB allows for paging to remain fast. Programs are no longer limited by amount of real memory. (much larger problem when computers were first being developed) Virtual Memory Drawbacks Addressing is more difficult Conflicts can terminate programs Disk drive is much slower than memory (thousands to millions of times) How can programs be separated? At any given time, only a fraction of a program is running (90/10 Rule) Only parts needed for immediate execution, or that are used repeatedly are loaded. Less accessed parts are left on disk and out of memory in order to save space. (programs can be several gigs these days, much too big for the amount of memory most people have in their computers) Virtual Addressing Virtual memory must use a smart memory controller that can convert between the byte and word addressing, between the two memory systems. This was later designed to be done without arithmetic computation, so that the CPU would not lose much processing power. The easiest way to implement this was by keeping everything in powers of two. Virtual Memory is not part of the actual underlying physical memory. Each Program is able to operate in its own virtual address space Virtual Memory Interface Virtual memory is able to use complex memory organization structures, primarily through the use of the MMU previously mentioned. This can be complicated as different types of memory (such as SRAM and DRAM) use different word sizes. Additionally, RISC processors discussed previously in class have access to more than one memory structure. The MMU is at the root of all virtual memory control. MMU The MMU is a processor run controller that handles the memory. It serves as a hardware translator, doing conversions The MMU is able to connect memories with different word sizes, as well as virtual and real. As far as the processor knows, there is one large memory, with one set of addresses. Mapping and Arithmetic Memory addressing is started from zero, and this is expect, so the MMU does proper adjustments to keep this illusion. This helps in simulating one large contiguous memory. In order to keep the MMU from having to do intense mathematical calculations in order maintain memory structure (such as subtraction), it finds boundaries in powers of two, allowing the lower-order bits to easily be used in the addressing scheme. When a computer is created, the virtual memory is determined. When a user adds or removes physical memory, it may create a hole, or a place where virtual memory cannot be mapped to physical. This can create an error due to discontinuity. Dynamic creation of Virtual Memory The processor can determine the mappings before running, determining what is needed and what is not. The processor then switches to real mode, using only the physical memory. Finally, after mapping is done, the MMU is enabled. Paging Paging was developed as a more efficient replacement for segmentation. Memory is broken into blocks with equal sizes, known as pages. Paging’s efficiency relies on page replacement, which moves the least likely need paged out of physical memory. The page system often relies on a power of two system, again to avoid costly arithmetic calculations. The MMU controls the page table. Blocks and Paging Paging is controlled by the Page Map The Virtual address space is separated into portions known as pages. Physical memory is separated into pieces known as page frames. Pieces are all of equal size. The Page Table The page table is a structure controlled by the operating system. It contains the mapping of virtual addresses to their physical location in memory. Every process and program is given its own page table. The page table contains all possible page mappings. Multiprogramming and Virtual Spaces Multiprogramming is designed so that multiple programs can be run at the same time. Early on, this was considered a bad idea, as memory conflicts could arise between the different programs, and both would end in abnormal termination. This could be solved by having programs designed to run intentionally using different memory addresses, but this a great deal more intensive, and requires much programming, while still being risky. To alleviate this problem, memory partitioning was developed. Virtual partitioned greatly increased the functionality of this, making it much more feasible. One limitation of the process is that it limits the total memory available to any given process. END