Understanding Virtual Memory and Memory Management
Virtual memory allows programs to exceed physical memory limits by utilizing disk space, managed by the operating system. By using techniques like paging and page tables, virtual addresses are mapped to physical memory addresses. This article explores the concepts of virtual memory, paging, page tables, and memory management in computer systems.
Download Presentation
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
E N D
Presentation Transcript
Memory Management: Memory Management: Virtual Memory Virtual Memory
What is Virtual Memory? What is Virtual Memory? The combined size of the program, data, and stack may exceed the amount of physical memory available for it. The operating system keeps those parts of the program currently in use in main memory, and the rest on the disk. Ali Akbar Mohammadi 2
Paging Paging On any computer, there exists a set of memory addresses that programs can produce. When a program uses an instruction like MOV REG,1000 It does this to copy the contents of memory address 1000 to REG (or vice versa, depending on the computer). Addresses can be generated using indexing, base registers, segment registers, and other ways. Ali Akbar Mohammadi 3
Virtual Addresses Virtual Addresses Program-generated addresses are called virtual addresses and form the virtual address space. On computers without virtual memory, the virtual address is put directly onto the memory bus and causes the physical memory word with the same address to be read or written. When virtual memory is used, the virtual addresses do not go directly to the memory bus. Instead, they go to an MMU (Memory Management Unit) that maps the virtual addresses onto the physical memory addresses Ali Akbar Mohammadi 4
The The Position Position and and Function Function of the MMU of the MMU Ali Akbar Mohammadi 5
The relation between virtual The relation between virtual addresses and addresses and physical memory memory addresses is given by addresses is given by the page table. the page table. physical Ali Akbar Mohammadi 6
Page & Page Frames Page & Page Frames The virtual address space is divided up into units called pages. The corresponding units in the physical memory are called page frames. The pages and page frames are always the same size. Ali Akbar Mohammadi 7
Page Tables Page Tables In the simplest case, the mapping of virtual addresses onto physical addresses is as we have just described it. The virtual address is split into a virtual page number (high-order bits) and an offset (low-order bits). The virtual page number is used as an index into the page table to find the entry for that virtual page. From the page table entry, the page frame number (if any) is found. The page frame number is attached to the high-order end of the offset, replacing the virtual page number, to form a physical address that can be sent to the memory. Ali Akbar Mohammadi 8
The The Internal Operation Internal Operation of the MMU with 16 4 MMU with 16 4- -KB of the KB Pages Pages Ali Akbar Mohammadi 9
The Purpose of The Purpose of the the Page Table Page Table The purpose of the page table is to map virtual pages onto page frames. Mathematically speaking, the page table is a function, with the virtual page number as argument and the physical frame number as result. Using the result of this function, the virtual page field in a virtual address can be replaced by a page frame field, thus forming a physical memory address. Two major issues must be faced: 1. The page table can be extremely large. 2. The mapping must be fast. Ali Akbar Mohammadi 10
Multilevel Page Tables Multilevel Page Tables To get around the problem of having to store huge page tables in memory all the time, many computers use a multilevel page table. Ali Akbar Mohammadi 11
(a) A 32 (a) A 32- -bit address bit address with two page table with two page table fields. fields. ( (b) b) Two Two- -level page level page tables. tables. Ali Akbar Mohammadi 12
Structure of a Page Table Entry Structure of a Page Table Entry The exact layout of an entry is highly machine dependent, but the kind of information present is roughly the same from machine to machine. The size varies from computer to computer, but 32 bits is a common size. The most important field is the page frame number. After all, the goal of the page mapping is to locate this value. Next to it we have the present/absent bit. The protection bits tell what kinds of access are permitted. The modified and referenced bits keep track of page usage. The referenced bit is set whenever a page is referenced, either for reading or writing. the last bit allows caching to be disabled for the page. Ali Akbar Mohammadi 13
Structure of a Page Table Entry Structure of a Page Table Entry Ali Akbar Mohammadi 14
TLBs( TLBs(Translation Lookaside Translation Lookaside Buffer) Buffer) In most paging schemes, the page tables are kept in memory, due to their large size. Potentially, this design has an enormous impact on performance. Most programs tend to make a large number of references to a small number of pages, and not the other way around. Thus only a small fraction of the page table entries are heavily read; the rest are barely used at all. The solution that has been devised is to equip computers with a small hardware device for rapidly mapping virtual addresses to physical addresses without going through the page table. The device, called a TLB (Translation Lookaside Buffer) or sometimes an associative memory. Ali Akbar Mohammadi 15
A TLB to speed up paging A TLB to speed up paging Ali Akbar Mohammadi 16
Inverted Page Tables Inverted Page Tables In this design, there is one entry per page frame in real memory, rather than one entry per page of virtual address space. For example, with 64-bit virtual addresses, a 4-KB page, and 256 MB of RAM, an inverted page table only requires 65,536 entries. The entry keeps track of which (process, virtual page) is located in the page frame. Ali Akbar Mohammadi 17
Comparison of a Comparison of a Traditional Page Table Traditional Page Table with an Inverted Page Table Inverted Page Table with an Ali Akbar Mohammadi 18