Virtual Memory Virtual memory is a technique which

  • Slides: 47
Download presentation
Virtual Memory Virtual memory is a technique which gives an application program the impression

Virtual Memory Virtual memory is a technique which gives an application program the impression that it has contiguous working memory, while in fact it may be physically fragmented and may overflow on to disk storage. Course Name: Operating Systems Author(s) : Phani Swathi Chitta Mentor: Aruna Adil Level(UG/PG): UG *The contents in this ppt are licensed under Creative Commons Attribution-Non. Commercial-Share. Alike 2. 5 India license

Learning Objectives After interacting with this Learning Object, the learner will be able to:

Learning Objectives After interacting with this Learning Object, the learner will be able to: • Explain the concept of virtual memory

Definitions of the components/Keywords: 1 2 Glossary: • Virtual Memory: It is a technique

Definitions of the components/Keywords: 1 2 Glossary: • Virtual Memory: It is a technique which gives an application program the impression that it has contiguous address space but physically it is fragmented in the main memory and secondary storage devices. • Physical Memory: It refers to the real storage and describes the total amount of memory installed in the computer. Usually consists of Random Access Memory (RAM) and hard drives. 3 • Page Table: A page table is the data structure used by a virtual memory system in a computer operating system to store the mapping between virtual addresses and physical addresses. It has the ability to mark an entry invalid through valid-invalid bit. 4 • TLB: TLB [Translation Lookaside Buffer] is a table in the processor’s memory that contains information about the pages in memory the processor has accessed recently. The table cross-references a program’s virtual addresses with the corresponding absolute addresses in physical memory that the program has most recently used. 5

Definitions of the components/Keywords: 1 2 3 4 5 Glossary: • Paging: In the

Definitions of the components/Keywords: 1 2 3 4 5 Glossary: • Paging: In the paging memory-management scheme, the operating system retrieves data from secondary storage in same-size blocks called pages. • Memory Management Unit: A memory management unit (MMU), sometimes called paged memory management unit (PMMU), is a computer hardware component responsible for handling accesses to memory requested by the CPU. Its functions include translation of virtual addresses to physical addresses (i. e. , virtual memory management), memory protection, cache control, bus arbitration and in simpler computer architectures (especially 8 -bit systems), bank switching. • Demand Paging: A refinement of paging in which it is not necessary to load in the entire contents of the text and data segments of a program from disk when the process is started. Instead, pages are brought into memory as they are accessed. • Lazy Swapper: A lazy swapper never swaps a page into memory unless that page will be needed.

Definitions of the components/Keywords: 1 2 3 4 5 Glossary: • Virtual Address Space:

Definitions of the components/Keywords: 1 2 3 4 5 Glossary: • Virtual Address Space: The virtual address space of a process refers to the logical view of how a process is stored in memory. • Thrashing: It is a degenerate situation where large amounts of computer resources are used to do a minimal amount of work. • Segmentation: Segmentation is a memory management technique in which memory is divided into variable sized chunks which can be allocated to processes. Each chunk is called a segment.

1 2 Definitions of the components/Keywords: Virtual Memory is a technique which gives an

1 2 Definitions of the components/Keywords: Virtual Memory is a technique which gives an application program the impression that it has contiguous working memory, while in fact it may be physically fragmented and may overflow on to disk storage. Programs use virtual addresses than real addresses to atore data. When the program is actually executed, the virtual addresses are converted into real memory addresses. 3 4 5 When a process requests access to its memory, it is the responsibility of the operating system to map the virtual address to the physical address. A page table is used to store mapping between virtual addresses and physical addresses.

Analogy 1 Person Looks for money 2 House Got enough money? 3 No Goes

Analogy 1 Person Looks for money 2 House Got enough money? 3 No Goes to the Bank 4 Yes Need Fulfilled Here HOUSE acts as the physical memory and BANK acts as the backing store 5

1 2 3 4 5 Analogy • If a person needs money, first he

1 2 3 4 5 Analogy • If a person needs money, first he will check in his house. • If he cannot find out enough money there then he will go to the bank and withdraw the money that he needs. • Here bank is analogous to virtual storage space and house or wallet is analogous to the physical space.

1 Master Layout 1 2 3 4 5 • Give a PLAY button •

1 Master Layout 1 2 3 4 5 • Give a PLAY button • Give PAUSE and RESTART/CLEAR buttons • Give two radio buttons FAST and SLOW

1 Step 1: 2 3 4 Instruction for the animator • When the user

1 Step 1: 2 3 4 Instruction for the animator • When the user clicks PLAY, show fig in the master layout • The text in DT should appear in parallel to the figure 5 • The process of finding the page is shown in the next slides • Follow the figures and the flow of finding the page should be accordingly Text to be displayed in the working area (DT) • Programs use virtual address to store data • When a program is executed, virtual address is converted to real logical address • A page table is used to store mapping between virtual address and logical address

1 Step 2: Page 0 2 3 4 Instruction for the animator 5 Text

1 Step 2: Page 0 2 3 4 Instruction for the animator 5 Text to be displayed in the working area (DT) • The action showed in the figure must be performed • Memory Access of Page 0 • The text in DT should appear in parallel to the figure • So first the TLB is checked for the virtual address 000 v • Here Application program tries to access page 0

Step 3: 1 2 3 4 Instruction for the animator 5 Text to be

Step 3: 1 2 3 4 Instruction for the animator 5 Text to be displayed in the working area (DT) • The action showed in the figure must be performed • It exists in TLB and it means a TLB Hit which says page 0 exists in physical memory itself • The text in DT should appear in parallel to the figure • SO Page 0 can be accessed directly from physical memory

1 Step 4: 2 3 4 Instruction for the animator • The action showed

1 Step 4: 2 3 4 Instruction for the animator • The action showed in the figure must be performed • The text in DT should appear in parallel to the figure 5 Text to be displayed in the working area (DT) • Page 0 can be accessed directly from physical memory since it is found in physical memory

1 Step 5: Page 1 2 3 4 5 Instruction for the animator Text

1 Step 5: Page 1 2 3 4 5 Instruction for the animator Text to be displayed in the working area (DT) • The action showed in the figure must be performed • Memory Access of Page 1 • The text in DT should appear in parallel to the figure • So first the TLB is checked for the virtual address 111 v • Here Application program tries to access page 1

1 Step 6: 2 3 4 Instruction for the animator • The action showed

1 Step 6: 2 3 4 Instruction for the animator • The action showed in the figure must be performed • The text in DT should appear in parallel to the figure 5 Text to be displayed in the working area (DT) • Page 1 does not exist in TLB and it means a TLB miss • Now page table is to be checked

1 Step 7: 2 3 4 5 Instruction for the animator Text to be

1 Step 7: 2 3 4 5 Instruction for the animator Text to be displayed in the working area (DT) • The action showed in the figure must be performed • Page table is checked for 111 v and is not present which results in a page fault • The text in DT should appear in parallel to the figure • Now secondary memory is to checked for 111 v

1 Step 8: 2 3 4 5 Instruction for the animator Text to be

1 Step 8: 2 3 4 5 Instruction for the animator Text to be displayed in the working area (DT) • The action showed in the figure must be performed • Now secondary memory is checked for 111 v • The text in DT should appear in parallel to the figure • Now page 1 will be shifted from secondary memory to physical memory • It exists there • Appropriate updating is done in TLB and page table

1 Step 9: Page 2 2 3 4 5 Instruction for the animator Text

1 Step 9: Page 2 2 3 4 5 Instruction for the animator Text to be displayed in the working area (DT) • The action showed in the figure must be performed • Memory Access of Page 2 • The text in DT should appear in parallel to the figure • So first the TLB is checked for the virtual address 222 v • Here Application program tries to access page 2

1 Step 10: 2 3 4 5 Instruction for the animator Text to be

1 Step 10: 2 3 4 5 Instruction for the animator Text to be displayed in the working area (DT) • The action showed in the figure must be performed • It exists in TLB and it means a TLB Hit which says page 2 exists in physical memory itself • The text in DT should appear in parallel to the figure • SO Page 2 can be accessed directly from physical memory

1 Step 11: 2 3 4 Instruction for the animator • The action showed

1 Step 11: 2 3 4 Instruction for the animator • The action showed in the figure must be performed • The text in DT should appear in parallel to the figure 5 Text to be displayed in the working area (DT) • Page 2 can be accessed directly from physical memory since it is found in physical memory

1 Step 12: Page 3 2 3 4 5 Instruction for the animator Text

1 Step 12: Page 3 2 3 4 5 Instruction for the animator Text to be displayed in the working area (DT) • The action showed in the figure must be performed • Memory Access of Page 3 • The text in DT should appear in parallel to the figure • So first the TLB is checked for the virtual address 333 v • Here Application program tries to access page 3

1 Step 13: 2 3 4 Instruction for the animator • The action showed

1 Step 13: 2 3 4 Instruction for the animator • The action showed in the figure must be performed • The text in DT should appear in parallel to the figure 5 Text to be displayed in the working area (DT) • Page 3 does not exist in TLB and it means a TLB miss • Now page table is to be checked

1 Step 14: 2 3 4 5 Instruction for the animator Text to be

1 Step 14: 2 3 4 5 Instruction for the animator Text to be displayed in the working area (DT) • The action showed in the figure must be performed • Page table is checked for 333 v and is not present which results in a page fault • The text in DT should appear in parallel to the figure • Now secondary memory is to checked for 333 v

1 Step 15: 2 3 4 5 Instruction for the animator Text to be

1 Step 15: 2 3 4 5 Instruction for the animator Text to be displayed in the working area (DT) • The action showed in the figure must be performed • Now secondary memory is checked for 333 v • The text in DT should appear in parallel to the figure • Now page 3 will be shifted from secondary memory to physical memory • It exists there • Appropriate updating is done in TLB and page table

1 Step 16: Page 4 2 3 4 Instruction for the animator 5 Text

1 Step 16: Page 4 2 3 4 Instruction for the animator 5 Text to be displayed in the working area (DT) • The action showed in the figure must be performed • Memory Access of Page 4 • The text in DT should appear in parallel to the figure • So first the TLB is checked for the virtual address 444 v • Here Application program tries to access page 4

1 Step 17: 2 3 4 5 Instruction for the animator Text to be

1 Step 17: 2 3 4 5 Instruction for the animator Text to be displayed in the working area (DT) • The action showed in the figure must be performed • It exists in TLB and it means a TLB Hit which says page 4 exists in physical memory itself • The text in DT should appear in parallel to the figure • SO Page 4 can be accessed directly from physical memory

1 Step 18: 2 3 4 Instruction for the animator • The action showed

1 Step 18: 2 3 4 Instruction for the animator • The action showed in the figure must be performed • The text in DT should appear in parallel to the figure 5 Text to be displayed in the working area (DT) • Page 4 can be accessed directly from physical memory since it is found in physical memory

1 Step 19: Page 5 2 3 4 5 Instruction for the animator Text

1 Step 19: Page 5 2 3 4 5 Instruction for the animator Text to be displayed in the working area (DT) • The action showed in the figure must be performed • Memory Access of Page 5 • The text in DT should appear in parallel to the figure • So first the TLB is checked for the virtual address 555 v • Here Application program tries to access page 5

1 Step 20: 2 3 4 Instruction for the animator • The action showed

1 Step 20: 2 3 4 Instruction for the animator • The action showed in the figure must be performed • The text in DT should appear in parallel to the figure 5 Text to be displayed in the working area (DT) • Page 5 does not exist in TLB and it means a TLB miss • Now page table is to be checked

1 Step 21: 2 3 4 Instruction for the animator • The action showed

1 Step 21: 2 3 4 Instruction for the animator • The action showed in the figure must be performed • The text in DT should appear in parallel to the figure 5 Text to be displayed in the working area (DT) • Page 5 is found in page table

1 Step 22: 2 3 4 5 Instruction for the animator Text to be

1 Step 22: 2 3 4 5 Instruction for the animator Text to be displayed in the working area (DT) • The action showed in the figure must be performed • Now page 5 is present in page table but not in TLB • The text in DT should appear in parallel to the figure • Now TLB is updated • So an entry should be done in TLB

1 Step 23: 2 3 4 Instruction for the animator • The action showed

1 Step 23: 2 3 4 Instruction for the animator • The action showed in the figure must be performed • The text in DT should appear in parallel to the figure 5 Text to be displayed in the working area (DT) • Now page 5 exists in both TLB and page table • The logical address will be got from TLB and can access page 5 from physical memory

1 Step 24: 2 3 4 Instruction for the animator • The action showed

1 Step 24: 2 3 4 Instruction for the animator • The action showed in the figure must be performed • The text in DT should appear in parallel to the figure 5 Text to be displayed in the working area (DT) • Page 5 is found in physical memory

1 Step 25: Page 6 2 3 4 5 Instruction for the animator Text

1 Step 25: Page 6 2 3 4 5 Instruction for the animator Text to be displayed in the working area (DT) • The action showed in the figure must be performed • Memory Access of Page 6 • The text in DT should appear in parallel to the figure • So first the TLB is checked for the virtual address 666 v • Here Application program tries to access page 6

1 Step 26: 2 3 4 Instruction for the animator • The action showed

1 Step 26: 2 3 4 Instruction for the animator • The action showed in the figure must be performed • The text in DT should appear in parallel to the figure 5 Text to be displayed in the working area (DT) • Page 6 does not exist in TLB and it means a TLB miss • Now page table is to be checked

1 Step 27: 2 3 4 Instruction for the animator • The action showed

1 Step 27: 2 3 4 Instruction for the animator • The action showed in the figure must be performed • The text in DT should appear in parallel to the figure 5 Text to be displayed in the working area (DT) • Page 6 is not present in page table which results in a page fault. Now secondary memory is to be checked for 666 v

1 Step 28: 2 3 4 5 Instruction for the animator Text to be

1 Step 28: 2 3 4 5 Instruction for the animator Text to be displayed in the working area (DT) • The action showed in the figure must be performed • 666 v is present in secondary memory. Now it has to be moved to physical memory • The text in DT should appear in parallel to the figure • But physical memory is full. So we have to make use of some replacement algorithm to make room available for page 6

1 Step 29: 2 3 4 Instruction for the animator • The action showed

1 Step 29: 2 3 4 Instruction for the animator • The action showed in the figure must be performed • The text in DT should appear in parallel to the figure 5 Text to be displayed in the working area (DT) • Here LRU [Least Recently Used] algorithm is used • Then page 0 which is least recently used, is moved to secondary memory and page 6 is now present in physical memory • Appropriate updates are done in TLB, page table and secondary memory

1 Step 30: Page 7 2 3 4 5 Instruction for the animator Text

1 Step 30: Page 7 2 3 4 5 Instruction for the animator Text to be displayed in the working area (DT) • The action showed in the figure must be performed • Memory Access of Page 7 • The text in DT should appear in parallel to the figure • So first the TLB is checked for the virtual address 777 v • Here Application program tries to access page 7

1 Step 31: 2 3 4 Instruction for the animator • The action showed

1 Step 31: 2 3 4 Instruction for the animator • The action showed in the figure must be performed • The text in DT should appear in parallel to the figure 5 Text to be displayed in the working area (DT) • Page 7 does not exist there and it means a TLB miss • So page table is to be checked

1 Step 32: 2 3 4 Instruction for the animator • The action showed

1 Step 32: 2 3 4 Instruction for the animator • The action showed in the figure must be performed • The text in DT should appear in parallel to the figure 5 Text to be displayed in the working area (DT) • Page 7 is not present in page table also and which results in a page fault • Now secondary memory is to be checked for 777 v

1 Step 33: 2 3 4 Instruction for the animator • The action showed

1 Step 33: 2 3 4 Instruction for the animator • The action showed in the figure must be performed 5 • The text in DT should appear in parallel to the figure Text to be displayed in the working area (DT) • Page 7 is not present in secondary memory too. • Now 777 v exists in neither page table nor in secondary memory • It means no translation is available for 777 v – that is page 7 is not present anywhere • It may be due to some program error. So either system will provide some error message or OS will use some techniques to handle the ____

Electrical Engineering Slide 1 Introduction Slide 3 Definitions Slide 44 -46 Analogy Slide 47

Electrical Engineering Slide 1 Introduction Slide 3 Definitions Slide 44 -46 Analogy Slide 47 Want to know more… Test your understanding Lets Sum up (summary) (Further Reading) (questionnaire) Interactivity: • The same algorithm as in demo is followed • When a page is selected, show the process how the page is found • The layout must be the same as in slide 10 Try it yourself • Give page numbers in the application program as radio buttons • Give two radio buttons as FAST and SLOW 43 Credits

Questionnaire 1 1. Which is bigger, virtual memory or physical memory? 2 Answers: a)

Questionnaire 1 1. Which is bigger, virtual memory or physical memory? 2 Answers: a) Virtual Memory 3 4 5 b) Physical Memory c) Any of them

Questionnaire 1 2 2. How are the pages actually kept in the physical memory

Questionnaire 1 2 2. How are the pages actually kept in the physical memory which are referenced in the virtual memory? Answers: a) Contiguously 3 4 5 Pages are kept non-contiguously in physical memory b) Non-contiguously c) Can’t say Pages are kept non-contiguously in physical memory

1 Questionnaire 3. The advantages of virtual memory are: i) Programmer don’t need to

1 Questionnaire 3. The advantages of virtual memory are: i) Programmer don’t need to bother about the size of the program 2 ii) Number of processes that can reside in main memory is less iii) Less I/O would be needed to load or swap a program 3 Answers: a) i & ii 4 comment - Number of processes that can reside in main memory is more b) i & iii c) ii & iii 5 d) None

Links for further reading Reference websites: http: //en. wikipedia. org/wiki/Virtual_memory http: //en. wikipedia. org/wiki/Page_table

Links for further reading Reference websites: http: //en. wikipedia. org/wiki/Virtual_memory http: //en. wikipedia. org/wiki/Page_table Books: