ITEC 202 Operating Systems

Slides:



Advertisements
Similar presentations
Chapters 7 & 8 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,
Advertisements

Chapter 3.3 : OS Policies for Virtual Memory
Virtual Memory 3 Fred Kuhns
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Virtual Memory II Chapter 8.
Chapter 8 Virtual Memory
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
Virtual Memory Background Demand Paging Performance of Demand Paging
Chapter 8 Virtual Memory Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice.
Day 23 Virtual Memory. Operating system’s role in VM Hardware-support Use VM or not Use paging or segmentation or both Software domain Algorithms for.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Virtual Memory Chapter 8.
Virtual Memory Chapter 8.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Lecture 11: Memory Management
1 Virtual Memory Chapter 9. 2 Characteristics of Paging and Segmentation n Memory references are dynamically translated into physical addresses at run.
Memory Management 2010.
Virtual Memory Chapter 8.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Lecture 9: Virtual Memory Operating System I Spring 2007.
1 Chapter 8 Virtual Memory Virtual memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory.
Virtual Memory (Chapter 8) Memory Management is an intimate and complex interrelationship between processor hardware and operating system software. Paging.
Virtual Memory Chapter 8.
Computer Organization and Architecture
Virtual Memory I Chapter 8.
Chapter 8 Virtual Memory
CSCI2413 Lecture 6 Operating Systems Memory Management 2 phones off (please)
Virtual Memory Management
Maninder Kaur VIRTUAL MEMORY 24-Nov
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Chapter 3 Memory Management: Virtual Memory
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
Virtual Memory Chapter 8. Characteristics of Paging and Segmentation A process may be broken up into pieces (pages or segments) that do not need to be.
Fall 2000M.B. Ibáñez Lecture 17 Paging Hardware Support.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Chapter 8 Virtual Memory Operating Systems: Internals and Design Principles Seventh Edition William Stallings.
1 Virtual Memory Chapter 8. 2 Virtual memory concept Simple paging/ segmentation  pages or segments are loaded into frames that may not necessarily be.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Memory Management. Why memory management? n Processes need to be loaded in memory to execute n Multiprogramming n The task of subdividing the user area.
Informationsteknologi Wednesday, October 3, 2007Computer Systems/Operating Systems - Class 121 Today’s class Memory management Virtual memory.
Lectures 8 & 9 Virtual Memory - Paging & Segmentation System Design.
1 Lecture 8: Virtual Memory Operating System Fall 2006.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
Chapters 7 & 8 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,
Project 4 Awards First Place Group 7 Samuel Bartlett Michael Phillips Norman Chen.
Virtual Memory Chapter 8.
Computer Organization
ITEC 202 Operating Systems
Chapter 2 Memory and process management
Day 22 Virtual Memory.
Chapter 8 Virtual Memory
Operating Systems Virtual Memory Alok Kumar Jagadev.
Virtual Memory Chapter 8.
Lecture 10: Virtual Memory
Module 9: Virtual Memory
Chapter 9 Virtual Memory
Chapter 9: Virtual-Memory Management
5: Virtual Memory Background Demand Paging
Operating Systems.
Contents Memory types & memory hierarchy Virtual memory (VM)
Chapter 8 Virtual Memory
2P13 Week 7.
Operating Systems Concepts
Module 9: Virtual Memory
COMP755 Advanced Operating Systems
Operating Systems: Internals and Design Principles, 6/E
Presentation transcript:

ITEC 202 Operating Systems EASTERN MEDITERRANEAN UNIVERSITY SCHOOL OF COMPUTING AND TECHNOLOGY Virtual Memory ITEC 202 Operating Systems

Virtual Memory Virtual memory is an imaginary memory area supported by some operating systems in conjunction with the hardware. Virtual memory can be toughed of as an alternate set of memory addresses. Programs use these virtual addresses rather than real addresses. When the program is actually executed, the virtual addresses are converted into real memory addresses.

Advantages of Paging and Segmentation More process can be maintained in the main memory. Only some of the pieces of each process are loaded in. With so many processes in main memory, it is very likely a process will be in the Ready state at any particular time. Process size is independent of the main memory present in the system. It is possible for a process to be larger than all the main memory.

Locality and Virtual Memory There are two main types of memory Real memory main memory of a computer system Virtual memory Memory on disk that allows for effective multiprogramming and relieves the user of fixed constraints of main memory.

Thrashing If reference for some data is made and it is not in the main memory (Page Fault), it can be brought in. The swapping strategy is employed by the operating system, that manages which piece to keep and which one to swap. The processor may spend most of its time swapping pieces rather than executing user instructions, that is called thrashing.

Principle of Locality In execution, only a few pieces of a process will be needed over a short period of time. It is possible to make intelligent guesses about which pieces will be needed in the future. So that virtual memory may work efficiently.

Support Needed for Virtual Memory For virtual memory to be practical and effective, some supports are needed. Hardware Support paging and segmentation Software Support Operating system must include a software to manage the movements of pages and/or segments between secondary memory and main memory.

Virtual Memory Paging Each process has its own page table Each page table entry contains the frame number of the corresponding page in main memory A bit (P) is needed to indicate whether the page is in main memory or not Present bit

Virtual Memory Paging Memory Management Format for Paging Page Number Offset Virtual Address Page Table Entry P M Other Control Bits Frame Number Memory Management Format for Paging P: present bit M: modified bit

Modify and Present Bits in Page Table A present bit (P) is needed to indicate whether the page is in main memory or not. A modify bit (M) is needed to indicate if the page has been modified since it was last loaded into main memory. If no change has been made, the page does not have to be written to the disk when it needs to be swapped out.

Page Tables The entire page table may take up too much main memory space. So, page tables are also stored in virtual memory. When a process is running, only part of its page table is in main memory.

Virtual Memory Segmentation Segments may be unequal, dynamic size Advantages Simplifies managing of increasing data structures Allows programs to be modified independently Used for sharing data among processes

Segment Tables Address : (segment number, offset) Each entry contains the starting address of the corresponding segment in main memory Each entry also contains the length of the segment A bit (P) is needed to determine if segment is already in main memory A bit (M) is needed to determine if the segment has been modified since it was loaded in main memory

Segment Table Entries Memory Management Format for Segmentation Segment Number Offset Virtual Address Segment Table Entry P M Other Control Bits Length Segment Base Memory Management Format for Segmentation (P: present bit, M: modified bit)

Combined Paging and Segmentation Paging is transparent to the programmer. Segmentation is visible to the programmer. In this combined scheme each segment is broken into fixed-size pages.

Combined Segmentation and Paging Table Entries Segment Number Page Number Offset Virtual Address Segment Table Entry Other Control Bits Length Segment Base Page Table Entry P M Other Control Bits Frame Number Each segment is broken into fixed-size pages. Each process is associated with a segment table and a number of page tables, one per process segment. The present and modified bits are not needed in segment table because these matters are handled at the page level.

Example pure segmentation Segement NO 1 2 3 Segment no = 1 offset=10500 00000 (1, 10500) 27500 Offset 17000 Calculate offset as an example: Assume that, Starting address of Segment 1 is 17000 So offset = 27500-1700 = 10500 65536 Virtual memory Note: 64K = 65536

example combined paging and segmentation Segement NO 1 2 3 Segment no = 1 Page no= 3 offset=1500 00000 27500 Page 0 Page 1 Page 2 Page 3 Page 4 Page 5 (1, 3, 1500) Calculate offset as an example: Assume that, Starting address of Segment 1 is 17000 And page size is 3000. 65536 Virtual memory Note: 64K = 65536

Operating System Software for Virtual Memory Design of memory-management depends on the following areas of choice: Whether or not to use virtual memory. The use of paging or segmentation or both. The algorithms employed for various aspects of memory management.

Page Fault: This error occurs when the desired page is not in the memory and causes and interrupt signal to be sent to request the loading of the proper page into main memory. An interrupt occurs when a program requests data that is not currently in real memory. The interrupt forces the operating system to fetch the data from the virtual memory and load it into RAM. An invalid page fault or page fault error occurs when the operating system cannot find the data in virtual memory.

Fetch Policy Determines when a page should be brought into memory Demand paging only brings pages into main memory when a reference is made to a location on the page Many page faults occurs when process is started Prepaging brings in more pages than needed More efficient to bring in pages that reside contiguously on the disk

Placement Policy This policy determines where to put the pieces of a process in the main memory. In pure segmentation scheme, this policy can be first fit, best fit and so on. For paging or combined systems, placement policy is irrelevant as the main memory access hardware will perform placement efficiently.

Replacement Policy Deals with the selection of a page in memory to be replaced when a new page is brought in Frame locking used for frames that may not be replaced If frame is locked, it may not be replaced Kernel of the operating system

Basic Replacement Algorithms Page removed from memory should be the page least likely to be referenced in the near future Most policies predict the future behavior on the basis of past behavior Basic Algorithms: Optimal Least recently used (LRU) First-in-first-out (FIFO) Clock

Optimal policy Selects a page for replacement for which the time to the next reference is the longest This policy results in the fewest number of page faults But, it is impossible to have perfect knowledge of future events

Example: Process with three frames in the memory Example assumes a fixed frame allocation for the process of three frames. The execution of the process requires reference to five distinct pages. (1, 2, 3, 4, 5) The page address stream produced by execution of the program is: 2 3 2 1 5 2 4 5 3 2 5 2 That means the first page referenced is 2, second is 3 and so on.

Example: Frames are initially empty. 1 2 3 Only three frames are allocated to this process in the main memory. 1 2 3 4 5 Frames are initially empty. Process with five Pages in the Virtual memory

Optimal policy example 2 x 2 3 x 2 3 2 3 1 x 2 3 5 x 2 3 5 4 3 5 x 4 3 5 4 3 5 2 3 5 x 2 3 5 2 3 5 Optimal policy selects a page for replacement for which the time to the next reference is the longest The optimal policy produces six page faults

Least Recently Used (LRU) Replaces the page that has not been referenced for the longest time. It almost does nearly as well as the optimal replacement policy. The problem with this approach is the difficulty in implementation.

The LRU policy produces seven page faults LRU policy example 2 x 2 3 x 2 3 2 3 1 x 2 5 1 x 2 5 1 2 5 4 x 2 5 4 3 5 4 x 3 5 2 x 3 5 2 3 5 2 LRU policy replaces the page that has not been referenced for the longest time The LRU policy produces seven page faults

First-in, first-out (FIFO) It is the simplest replacement policy to implement. The page that has been in memory the longest is replaced. These pages may be needed again very soon.

FIFO policy example The FIFO policy produces nine page faults 2 x 2 3 x 2 3 2 3 1 x 5 3 1 x 5 2 1 x 5 2 4 x 5 2 4 3 2 4 x 3 2 4 3 5 4 x 3 5 2 x The page that has been in memory the longest is replaced. The FIFO policy produces nine page faults

Clock Policy Additional bit called a use bit is used. When a page is first loaded in memory, the use bit is set to 1 When the page is referenced, the use bit is set to 1 When it is time to replace a page, the first frame encountered with the use bit (R) set to 0 is replaced. During the search for replacement, each use bit set to 1 is changed to 0

The Clock policy produces eight page faults Clock policy example 2* x  2* 3* x  2* 3*  2* 3* 1* x  5* 3 1 x  5* 2* 1 x   5* 2* 4* x  5* 2* 4*  3* 2 4 x  3* 2* 4  3* 2 5* x   3* 2* 5* The Clock policy produces eight page faults

Windows Memory Management The Windows virtual memory manager control shows how memory is allocated and how paging is performed. The memory manager is designed to operate a variety of platforms and use page sizes ranging form 4 Kbytes to 64 Kbytes.

Windows Virtual Address Map Each windows user process sees a separate 32-bit address space, allowing 4 Gbytes of memory per process. Each user process can have 4 G Byte of memory, but by default it is divided and each user has 2 GByte and the remaining 2 GByte is reserved for operating system. All the processes share the same 2 Gbytes of system space.

Windows Paging When a process is created it can make use of the whole space (2 Gbytes). This space is divided into fixed-sizes pages any of which can be brought into main memory. In practice, a page can be in any of the following states: Available: Pages not currently used by any process. Reserved Committed:

Example: A process has four page frames allocated to it. (All the following numbers are decimal, and everything is numbered starting form zero). The time of the last loading of a page into each page frame, the time of last access to the page in each page frame, the virtual page number in each page frame, and the modified (M) bits for each page frame are as shown in the following table (the times are in clock ticks from the process start time 0 to the event – not the number of ticks since the event to the present).

Clock: Page frame 2 should be replaced Example: Clock: Page frame 2 should be replaced FIFO: Page frame 3 should be replaced LRU: Page frame 1 should be replaced Virtual page number Page frame Time loaded Time last referenced M bit 2 130 161 1 60 160 26 162 3 20 163 A page fault to virtual page 4 has occurred. Which page frame will have its contents replaced for each of the following memory management policies? FIFO (first-in-first-out). LRU (least recently used). Clock.

Virtual Memory Ahmet Rizaner 20 April 2008