Top Banner
COMPUTER SCIENCE AND DATA PROCESSING DEPARTMENT OF MATHEMATICS IIT KHARAGPUR Virtual Memory Abir Naskar 13MA60R21
17
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The life and times

COMPUTER SCIENCE AND DATA PROCESSINGDEPARTMENT OF MATHEMATICSIIT KHARAGPUR

Virtual Memory

Abir Naskar13MA60R21

Page 2: The life and times

• Why virtual memory?

• Motivations.

• Memory hierarchy.

• Cache and Virtual memory.

• Paging.

• References.

OUTLINE

1

Page 3: The life and times

• Extension of main memory.

• Secondary storage is used.

• Combination of hardware and software.

• Usually very large.

• Working set of pages resides in main memory, others are in secondary memory.

VIRTUAL MEMORY

2

Page 4: The life and times

• Main memory is expensive.

• Main memory size is less.

• All program are not active.

• Multiprogramming environment.

• Time sharing.

• Allow OS to share memory.

• Protect program from each other.

WHY VIRTUAL MEMORY

3

Page 5: The life and times

• We use main memory as a cache of disk memory.- address space of process can exceed physical memory size.

• Simplify memory management.- only active code and data is actually in memory.

• Provide protection.- one process can’t interfere with another.

MOTIVATION

4

Page 6: The life and times

LEVELS IN MEMORY HIERARCHY

Size 32B 32KB-4MB 128MB 30GB

Speed 3ns 6ns 60ns 8ms

5

Page 7: The life and times

SYSTEM WITH PYHSICAL MEMORY ONLY

Address generated by CPU point directly to byte in physical memory.

Example: Cray machines, early PCs, embedded systems etc.

6

Page 8: The life and times

SYSTEM WITH VIRTUAL MEMORY

o Hardware converts virtual address to physical addresses via an OS-managed look-up table (page table).

o Example : modern PCs, workstations, servers etc.

7

Page 9: The life and times

CACHE MEMORY VIRTUAL MEMORY

Is a hardware or processor Is simulated on hard drive maintained by OS

Data reads in unit called “block” Data reads in unit called “pages”

Stores memory access by CPU Storage swapping between active storage and hard disk

Reduces the frequency that the CPU must wait for data from the main memory

Reduces the amount of physical storage access that is required

Performance-wise faster Performance-wise slower

CACHE MEMORY VS VIRTUAL MEMORY

8

Page 10: The life and times

• It is a Memory Management Technique in which the memory is divided into fixed size pages.

• Paging is used for faster access of data.

• Paging allows the physical address space of a process to be noncontiguous.

• A page is a sequence of N bytes where N is a power of 2.

• Page size should be high enough to amortize the high access time, and page fault rate is small.

• These days, page sizes are at least 4KB.

• If 1Mb RAM, then 1MB/4KB=256 pages.

PAGING

9

Page 11: The life and times

• Virtual address contains virtual page number and page offset.

• The number of pages addressable with virtual address is virtually unlimited where number of pages addressable with physical address is limited.

• Mapping from virtual to a physical address.

ADDRESS MAPPING

10

Page 12: The life and times

• A data may be or may not be present in main memory- if not present then page fault occur.

• OS takes control when the valid bit is 0.* OS creates pages for all the process in the disk.* It also creates a data structure to record where each virtual page is stored in the disk.* Another data structure to track which process and virtual address use physical page.

PAGE FAULT

11

Page 13: The life and times

• Find a free frame to store a desire page.* If there is free frame use it.* Otherwise use a page replacement algorithm to find a victim page.* Write the victim page on disk and change the page and page table accordingly.

• Read the desired page into free frame and change the page and page table.

• Restart the user process.

• Some page replacement algorithm: FIFO replacement, Least Recently Used replacement, Least Frequently Used replacement etc.

PAGE REPLACEMENT

12

Page 14: The life and times

13

• Page table is a data structure to store the mapping between virtual address and physical address.

• Used to translate logical to physical addresses.

• Page table entries: Address: pointer to the location of page in memory.Valid bit: where page is pointed.Dirty bit: set if at least one word of the page is modified.Referenced bit: set if page has been referenced with either read or write.protection bit: used to restrict access, like read only, system only access.

PAGE TABLE

Page 15: The life and times

• Applications run slower.

• It takes more time to switch between applications.

• Less hard drive space for your use.

DISADVANTAGES

14

Page 16: The life and times

• Stallings W. (2006): “Operating Systems: Internals and Design Principles (7th Edition)”. prentice hall.

• Tanenbaum A. S. (2013): “Modern Operating System (3rd edition)”,Pearson Education, pp.175-247.

• Cragon, Harvey G. (1996). Memory Systems and Pipelined Processors. Jones and Bartlett Publishers.ISBN 0-86720-474-5.

• URL: http://windows.microsoft.com/en-us/windows/what-is-virtual-memory#1TC=windows-7

• URL: http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Memory/virtual.html

REFERENCES

15

Page 17: The life and times

Thank you…