Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITEC 202 Operating Systems

Similar presentations


Presentation on theme: "ITEC 202 Operating Systems"— Presentation transcript:

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

2 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.

3 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.

4 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.

5 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.

6 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.

7 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.

8 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

9 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

10 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.

11 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.

12 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

13 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

14 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)

15 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.

16 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.

17 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 = = 10500 65536 Virtual memory Note: 64K = 65536

18 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

19 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.

20 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.

21 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

22 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.

23 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

24 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

25 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

26 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: That means the first page referenced is 2, second is 3 and so on.

27 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

28 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

29 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.

30 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

31 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.

32 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

33 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

34 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

35 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.

36 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.

37 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:

38 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).

39 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.

40 Virtual Memory Ahmet Rizaner 20 April 2008


Download ppt "ITEC 202 Operating Systems"

Similar presentations


Ads by Google