virtual memory virtual address space. in computing, virtual address space (abbreviated vas) is a...

28
VIRTUAL MEMORY Virtual Address Space

Upload: stephen-rodgers

Post on 19-Jan-2018

231 views

Category:

Documents


0 download

DESCRIPTION

Page translation in books You write a manuscript that is 325 lines long. You give it to a publisher and they publish it in a book that has pages with 32 lines each. Example) If you wanted to find line 135 in your manuscript and you have a copy of your book, where would the line be (assuming the first page is page 0 and the first line on each page is line 0)? Answer) use page translation Page = RoundUp(135/32) - 1 = page 4 (the 5 th page) Offset into the page = 135 mod 32 = 7 (the 8 th line) So it is on page 4, then go to line 7.

TRANSCRIPT

Page 1: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

VIRTUAL MEMORYVirtual Address Space

Page 2: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Virtual Address Space• In computing, virtual address space (abbreviated VAS)

is a memory mapping mechanism available in modern operating systems such as OpenVMS, UNIX, Linux, and Windows NT.

• This is beneficial for different purposes, one is security through process isolation. An address generated by the process is called logical address (virtual address) and it is mapped to the virtual address space.

Source: Wikipedia

Page 3: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Page translation in books• You write a manuscript that is 325 lines long.• You give it to a publisher and they publish it in a book that has

pages with 32 lines each.

• Example) If you wanted to find line 135 in your manuscript and you have a copy of your book, where would the line be (assuming the first page is page 0 and the first line on each page is line 0)?

Answer) use page translationPage = RoundUp(135/32) - 1 = page 4 (the 5th page)Offset into the page = 135 mod 32 = 7 (the 8th line)

So it is on page 4, then go to line 7.

Page 4: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Section Table for a Process

Page 5: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating
Page 6: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Page table for a process

Page 7: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Memory picture

Page 8: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Paging/Segmented System

Page 9: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating
Page 10: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

FragmentationIn computer storage, fragmentation is a phenomenon in which storage space is used inefficiently, reducing capacity and often performance. Fragmentation leads to storage space being "wasted", and the term also refers to the wasted space itself.

Source: wikipedia

Page 11: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Minimizing Fragmentation

Page 12: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Minimizing FragmentationExample) choose a segment size and page size that will minimize the amount of fragmentation. s = segment size p = page size e = page entry size in the page table F = percent of fragmentation F = ( (page entries)(entry size) + ( Expected waste in last page)) / (segment size)

F = speps )2/()/(

= pe

+ sp

2

dpdf

= 0 means s2

1 -

2pe

= 0 therefore p 2 = 2s or p = s2

Example) Part A) if S is 128K, what is the optimal P as far a minimizing fragmentation. S = 128K 1K=1024

P = 1024*128*2 = 512 Part B) What percent of storage is fragmentation waste?

F = 5121

+ 1024*128*2

512 = 0.5

Page 13: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Address TranslationIn a segmentated paging system, if the virtual address has: A bits for the segment number B bits for the page number C bits for the offset The segment table had D bits for the page table address The page tables have E bits for the real page number Sketch the picture for the translation of virtual addresses to real addresses.

Virtual Address 2 D Real Address

A B C

C E

Page Table

Segment table

Page 14: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Questions on address translationHow many bytes are in a page?  

How many bits are in a real address? C+E What is the maximum number of page tables allowed in the system?  What is the maximum number of pages allowed in a segment?  How many pages of main memory can be dedicated to some processes segment?  

What is the range of starting addresses for page tables? 0 -1 What is the virtual address space of a process? 0 -1

Page 15: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Storage selection for segments/pagesBest Fit • Find the open block of consecutive page frames in MM that best fits the storage incoming

storage location. Advantages: • Finds tightly fitted locations which will allow large open consecutive blocks for larger processes that may

come in later• Disadvantages:• - Must check all open blocks of page frames which will take processing timeFirst Fit• Find the open block of consecutive page frames in MM that first fits (starting from the

beginning of memory to the end) • Advantages:

• Does not need to check all available spaces, since as soon as the first on is found.

Worst fit• Find the open block of consecutive page frames in MM that worst fits (biggest block of

available free page frames) storage the incoming storage location. Advantages: • Finds tightly fitted locations which will allow large open consecutive blocks for larger processes that may

come in later• Disadvantages:• - Must check all open blocks of page frames, which will take processing time.

Page 16: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Example: contiguous storageConsider a system that has 10 pages of MM available for 10 processes. The following sequence of events occurs:

1. Process A, 2 pages arrives 2. Process B, 3 pages arrives 3. Process C, 1 page arrives 4. Process B completes and the operating systems frees up it page frames in MM. 5. Process D, 1 page arrives 6. Process E, 3 pages arrives 7. Process F, 3 pages arrives

Where do the pages get places in MM when each process arrives:

Storage after all 6 processes attempt to get into main memory

Operating

System

Process A

Process D

Process C

Process E

Operating

System

Process A

Process D

Process C

Process E

Operating

System

Process A

Process D

Process C

Process E

Process F

Page 17: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Page ReplacementSuppose the OS allocates a fixed number of page frames to a process. If a page from a process is referenced by the process, and it is not currently in memory (this is called a page fault) then a page frame from that process must be selected for removal so the newly referenced page can be put in memory. Which page frame should be selected?

Local Replacement• When a process needs to bring in a page to memory, the page selected

for removal is chosen from the set of pages currently in memory for that same process.

Global Replacement• When a process needs to bring in a page to memory, the page selected

for removal is chosen from the set of all pages currently in memory for any process.

Page 18: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

First or Last in First OutFIFO (First In First Out)• Method: Select the frame that has been in MM the longest

and remove it to make room.• Implementation: maintain a linked list of all pages currently in

MM and remove the page that is pointed to by the head of the linked list

LIFO (Last In First Out) • Method: Select the frame that has been in MM the shortest

and remove it to make room.• Implementation: maintain a linked list of all pages currently in

MM and remove the page that is pointed to by the tail of the linked list.

Page 19: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Statistics based (Least Recently used)

LRU (Least Recently Used)• Method: Select the frame that has been referenced the

least recently of all frames in MM.• Implementation: Maintain a linked list of all pages

currently in MM and each time a page is referenced, move the page to the front of the linked list.

Page 20: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Not Used RecentlyNUR (Not Used Recently)• Method: Select the frame that has been referenced the

somewhat least recently of all frames in MM. This method is that same idea as LRU but the implementation is much simpler.

• Implementation: Maintain an array of bits for each page, when a page is referenced, set the bit to 1. At the time when a page reference will set all bits to 1 (meaning every page in MM has a bit of 1) then set all reference bits to zero to start the whole reference recording over. At the time of removal selection, pages that have not been referenced recently will have the reference bit set to 0.

Page 21: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Second ChanceSecond Chance• Method: Same as NUR but with 2 bits. At the time when

a page is selected, it is given a second chance, the second chance bit is turned on and it not selected for removal.

• Implementation: Maintain 2 arrays of bits for each page, just like the NUR but when a page is selected, check if the second chance bit is set, if not, set it, and skip over this process an continue the selections process.

Page 22: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Optimal Page ReplacementOptimal • Method: Look into the future at the pages that will be

referenced, and of all the pages currently in memory, select the page that’s next reference will be the furthest in the future.

• Implementation: Predict the future. The OS must know the exact sequence of referenced that the process will make. Not feasible if the program has if…then…else statements. Possible if the process is a straight process without decisions.

• Comment: Although this is not realistic to implement, it is the benchmark to check other algorithms against. That is, if the optimal algorithm produces x page faults, you would compare other algorithms against x.

Page 23: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Example: page reference string• Consider a process in MM where the OS has given the

process 3 page frames of MM to process out of but the process has a total of four pages.

• When a process is running, the list of pages referenced in order is called the reference string for the process.

• Suppose the reference for this process is

1,2,3,4,3,4,2,1,3,4 and the following page replacements are used.

Page 24: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Example using FIFO

Page 25: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Example using LIFO

Page 26: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Example using LRU

Page 27: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Example using Optimal

Page 28: VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating

Working Set (see queuing theory)The working set principle take into account that whichever page replacement algorithm used, to maximize overall throughput, the goal is to have the processor(s) running as close to 100% of the time.

A state where all processes are waiting for the disk drives for a page and none are “ready to run” should be avoided.