Top Banner
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 9: Virtual Memory
24

Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

Jan 01, 2021

Download

Documents

dariahiddleston
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: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.1 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Chapter 9: Virtual Memory

Page 2: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.4 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Background

Virtual memory – separation of user logical memory from physical memory.

Only part of the program needs to be in memory for executionLogical address space can therefore be much larger than physicaladdress spaceAllows for more efficient process creation

Virtual memory can be implemented via:Demand paging Demand segmentation

Page 3: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.5 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Virtual Memory That is Larger ThanPhysical Memory

Page 4: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.8 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Demand Paging

Bring a page into memory only when it is neededLess I/O neededLess memory needed Faster responseMore users

Lazy swapper – never swaps a page into memory unless page will be needed

Swapper that deals with pages is a pager

Page 5: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.9 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Transfer of a Paged Memory toContiguous Disk Space

Page 6: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.11 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Page Table When Some Pages AreNot in Main Memory

Page 7: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.12 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Page Fault

Page 8: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.14 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Steps in Handling a Page Fault

Page 9: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.21 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

What happens if there is no free frame?

Page replacement – find some page in memory, but not really in use, swap it out

algorithmperformance – want an algorithm which will result in minimum number of page faults

Page 10: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.24 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Basic Page Replacement

1. Find the location of the desired page on disk

2. Find a free frame:- If there is a free frame, use it- If there is no free frame, use a page replacement

algorithm to select a victim frame

3. Bring the desired page into the (newly) free frame; update the page and frame tables

4. Restart the process

Page 11: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.25 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Page Replacement

Page 12: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.27 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Graph of Page Faults Versus The Number of Frames

Page 13: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.29 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

FIFO Page Replacement

Page 14: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.31 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Optimal Algorithm

Replace page that will not be used for longest period of time

How do you know this?

Used for measuring how well your algorithm performs

Page 15: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.32 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Optimal Page Replacement

Page 16: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.33 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Least Recently Used (LRU) Algorithm

Page 17: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.34 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

LRU Page Replacement

Page 18: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.65 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Program structureInt[128,128] data;

Each row is stored in one page Program 1

for (j = 0; j <128; j++)for (i = 0; i < 128; i++)

data[i,j] = 0;

128 x 128 = 16,384 page faults

Program 2 for (i = 0; i < 128; i++)

for (j = 0; j < 128; j++)data[i,j] = 0;

128 page faults

Tips for Avoiding Page Faults

Page 19: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.44 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Thrashing

If a process does not have “enough” pages, the page-fault rate is very high. This leads to:

low CPU utilization

Thrashing ≡ a process is busy swapping pages in and out

Page 20: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.45 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Thrashing (Cont.)

Page 21: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.53 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Memory-Mapped Files

Memory-mapped file I/O allows file I/O to be treated as routine memory access by mapping a disk block to a page in memory.

Simplifies file access by treating file I/O through memory rather than read() write() system calls.

Also allows several processes to map the same file allowing the pages in memory to be shared.

Page 22: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.54 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Memory Mapped Files

Page 23: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

9.55 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Memory-Mapped Shared Memoryin Windows

Page 24: Chapter 9: Virtual MemoryVirtual memory can be implemented via: zDemand paging zDemand segmentation Operating System Concepts with Java – 8 th Edition 9.5 Silberschatz, Galvin and

8.1 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Page Replacement Example

Example: