Computer architecture virtual memory

14,020 views 30 slides Sep 27, 2017
Slide 1
Slide 1 of 30
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30

About This Presentation

Computer architecture virtual memory seminar
Mustansiriya University
Department of Education
Computer Science


Slide Content

Virtual Memory Lecture Slides By Israa

Virtual Memory

History virtual memory was developed in approximately 1959 – 1962, at the University of Manchester for the Atlas Computer, completed in 1962. In 1961, Burroughs released the B5000, the first commercial computer with virtual memory.

Virtual Memory OS and hardware produce illusion of a disk as fast as main memory Virtual memory as an alternate set of memory addresses. Programs use these virtual addresses rather than real addresses to store instructions and data. When the program is actually executed, the virtual addresses are converted into real memory addresses . Process runs when not all pages are loaded in memory Only keep referenced pages in main memory Keep unreferenced pages on slower, cheaper backing store (disk) Bring pages from disk to memory when necessary. Virtual memory is imaginary memory: it gives you the illusion of a memory arrangement that’s not physically there. The simple tactic of breaking a process up into pages led to the development of important concept : Virtual memory

Virtual Memory …… (cont ’ d) The basic idea of Virtual Memory is to keep only those parts of the program currently in use in the memory and the rest on the disk drive. For example: a 16 M program can run on a 4 M machine by carefully choosing which 4 M to keep in memory at each instant, with pieces of the program being swapped between disk and memory as needed. It can work in a Multiprogramming system, with bits and pieces of many programs brought to the memory at once by the Operating System. While a program is waiting for part of itself to be brought in, it is waiting for I/O and cannot run, so the CPU can be given to another process, the same way as for any other multiprogramming system.

Advantages You can run more applications at once. Allows you to fit many large programs into a relatively small RAM. You don't have to buy more memory RAM VM supports Swapping. Common data or code may be shared to save memory. Process need not be in memory as a whole , Only part of a program needs to be loaded into memory. Process may even be larger than all of physical memory. Data / code can be read from disk as needed. Code can be placed anywhere in physical memory without relocation. More processes can be maintained in Main Memory which increases effective use of CPU. Don't need to break program into fragments to accommodate memory limitations

Why is it needed…. Before the development of the virtual memory technique, programmers in the 1940s and 1950s had to manage directly two-level storage such as main memory or ram and secondary memory in the form of hard disks or earlier, magnetic drums. Enlarge the address space, the set of addresses a program can utilize. Virtual memory might contain twice as many addresses as main memory.

How does it work… To facilitate copying virtual memory into real memory, the operating system divides virtual memory into pages, each of which contains a fixed number of addresses. Each page is stored on a disk until it is needed. When the page is needed, the operating system copies it from disk to main memory, translating the virtual addresses into real addresses.

Paging Extends partition idea by dividing up both memory and processes into equal size pieces Split memory into equal sized, small chunks – called page frames Split programs (processes) into equal sized small chunks -called pages Allocate the required number page frames to a process Operating System maintains list of free frames A process does not require contiguous page frames Each process has a list of frames that it is using, called a page table, stored in the PCB Paging Use page table to keep track

Allocation of Free Frames

Logical and Physical Addresses -Paging

Demand paging Fetch Policy Determines when a page should be brought into main memory. One of common policies is Demand paging Refines paging by demand paging - each page of a process is brought in only when needed, that is, on demand Demand paging Do not require all pages of a process in memory Bring in pages as required Less I/O needed Less memory needed Faster response More users „

Page fault If a page is needed which is not in memory, a page fault is triggered, which requires an I/O operation Page fault Required page is not in memory Operating System must swap in required page May need to swap out a page to make space

Page fault …… ( cont ’ d) An interrupt to the software raised by the hardware when a program accesses a page that is not mapped in physical memory. when a program accesses a memory location in its memory and the page corresponding to that memory is not loaded when a program accesses a memory location in its memory and the program does not have privileges to access the page corresponding to that memory.

Problems faced with Virtual Memory implementation : Thrashing Possibly large page table Solution: Use multilevel page tables. Use TLB (Translation Lookaside Buffer) or some times called ‘Associative Memory’. Page fault rates can be reduced by using a Working Set Model’ approach or a ‘ Prepaging ’ approach. Increase RAM!

Thrashing Pages currently in memory may have to be replaced. In some situations this can lead to thrashing , where the processor spends too much time swapping the same pages in a nd out Thrashing Swapping out a piece of a process just before that piece is needed The processor spends most of its time swapping pieces rather than executing user instructions Too many processes in too little memory Operating System spends all its time swapping Little or no real work is done Disk light is on all the time Solutions Good page replacement algorithms Reduce number of processes running Fit more memory

Page Table Structure Each process has a list of frames that it is using, called a page table, stored in the PCB Page Table Structure is a Basic mechanism for reading a word from memory involves using a page table to translate : a virtual address - page number and offset into a physical address - frame number and offset Page tables may be very large they cannot be stored in registers they are often stored in virtual memory (so are subject to paging!) sometimes a page directory is used to organize many pages of page tables ,Pentium uses such a two-level structure sometimes an inverted page table structure is used to map a virtual address to a real address using a hash on the page number of the virtual address AS/400 and PowerPC use this idea.              

18 Page Table Structure Page tables are variable in length (depends on process size) then must be in main memory instead of registers A single register holds the starting physical address of the page table of the currently running process

Page Tables Memory-resident page table (physical page or disk address) Physical Memory Disk Storage (swap file or regular file system file) Valid 1 1 1 1 1 1 1 Virtual Page Number

Inverted Page Table Structure

Translation Lookaside Buffer ) TLB) Each virtual memory reference can causes two physical memory access One to fetch the appropriate page table entry One to fetch the desired data To overcome this problem a high-speed cache is set up for page table entries Called a Translation Lookaside Buffer (TLB) TLB is a special cache, just for page table entries Contains page table entries that have been most recently used

Translation Lookaside Buffer Given a virtual address, processor examines the TLB If page table entry is present (TLB hit), the frame number is retrieved and the real address is formed If page table entry is not found in the TLB (TLB miss), the page number is used to index the process page table

Translation Lookaside Buffer First checks if page is already in main memory If not in main memory a page fault is issued The TLB is updated to include the new page entry

TLB Operation

TLB and Cache Operation

Segmentation Another way in which addressable memory can be subdivided, known as Segmentation May be unequal, dynamic size Paging is not (usually) visible to the programmer Segmentation is visible to the programmer Usually different segments allocated to program and data May be a number of program and data segments

Advantages of Segmentation Simplifies handling of growing data structures Allows programs to be altered and recompiled independently, without re-linking and re-loading Lends itself to sharing data among processes Lends itself to protection Some systems combine segmentation with paging

Combined Paging and Segmentation Paging is transparent to the programmer Segmentation is visible to the programmer Each segment is broken into fixed-size pages.

Thank you for listening