Virtual Memory Why? The need of memory more than the available physical memory. Process 3 Physical Memory Process 2 Process 1 Process 4.

Slides:



Advertisements
Similar presentations
9.4 Page Replacement What if there is no free frame?
Advertisements

Page Replacement Algorithms
4.4 Page replacement algorithms
Virtual Memory (Chapter 4.3)
Virtual Memory Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution -
Chapter 101 The LRU Policy Replaces the page that has not been referenced for the longest time in the past By the principle of locality, this would be.
Module 10: Virtual Memory
Chapter 10: Virtual Memory
Page Replacement Algorithms (Virtual Memory)
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Chapter 9: Virtual Memory
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
國立台灣大學 資訊工程學系 Chapter 9: Virtual Memory. 資工系網媒所 NEWS 實驗室 Objectives To describe the benefits of a virtual memory system To explain the concepts of demand.
Virtual Memory Management G. Anuradha Ref:- Galvin.
Virtual Memory. 2 What is virtual memory? Each process has illusion of large address space –2 32 for 32-bit addressing However, physical memory is much.
Virtual Memory.
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory OSC: Chapter 9. Demand Paging Copy-on-Write Page Replacement.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 15: Background Information for the VMWare ESX Memory Management.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Module 9: Virtual Memory
Module 10: Virtual Memory Background Demand Paging Performance of Demand Paging Page Replacement Page-Replacement Algorithms Allocation of Frames Thrashing.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
Virtual-Memory Management
Gordon College Stephen Brinton
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Virtual Memory.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
Chapter 10: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 10: Virtual Memory.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Revisiting Virtual Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
Chapter 9: Virtual Memory. Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
CSS430 Virtual Memory Textbook Ch9
Virtual Memory.
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
Page 19/17/2015 CSE 30341: Operating Systems Principles Optimal Algorithm  Replace page that will not be used for longest period of time  Used for measuring.
Cosc 4740 Chapter 8 Virtual Memory. Background Code needs to be in memory to execute, but entire program rarely used –Error code, unusual routines, large.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Operating Systems CMPSC 473 Virtual Memory Management (3) November – Lecture 20 Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of.
CSC 360, Instructor: Kui Wu Memory Management II: Virtual Memory.
CS307 Operating Systems Virtual Memory Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
Virtual Memory The address used by a programmer will be called a virtual address or logical address. An address in main memory is called a physical address.
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 9: Virtual-Memory Management 9.1 Background.
NETW3005 Virtual Memory. Reading For this lecture, you should have read Chapter 9 (Sections 1-7). NETW3005 (Operating Systems) Lecture 08 - Virtual Memory2.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
Virtual Memory. 2 Last Week Memory Management Increase degree of multiprogramming –Entire process needs to fit into memory Dynamic Linking and Loading.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
Chapter 9: Virtual Memory
Topic 8 (Textbook - Chapter 9) Virtual Memory
Chapter 9: Virtual Memory
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 9: Virtual Memory
Virtual Memory Management
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Virtual Memory.
Chapter 9: Virtual-Memory Management
Lecture 40 Syed Mansoor Sarwar
5: Virtual Memory Background Demand Paging
Chapter 9: Virtual Memory
Chapter 6 Virtual Memory
Operating Systems CMPSC 473
Module 9: Virtual Memory
Chapter 9: Virtual Memory CSS503 Systems Programming
Chapter 9: Virtual Memory
Virtual Memory.
Presentation transcript:

Virtual Memory Why? The need of memory more than the available physical memory. Process 3 Physical Memory Process 2 Process 1 Process 4

Memory Limits for Windows Releases http://msdn. microsoft

Max. memory per a process http://msdn.microsoft.com/en-us/library/windows/desktop/aa366778(v=vs.85).aspx#memory_limits

Max. memory per a VM (. NET or Java) Max. memory per a single object Max. memory per a VM (.NET or Java) Max. memory per a single object max 2GB (.NET) ไม่ว่าจะเป็น 32-bit หรือ 64-bit version สร้าง object Array เกิน 2GB ไม่ได้ With .NET 4.5, 10 years memory limit of 2 GB is over ส่วนใหญ่การเขียนโปรแกรมด้วย Java หรือ .NET จะติด memory limit ที่ virtual machine ก่อน ถ้าจะทะลุ limit นี้ไปก็ต้องเขียน C/C++ หรือเรียก system call

No corresponding physical memory Virtual Memory stack No corresponding physical memory As stack and heap grow, more pages will be allocated and mapped to physical memory. heap data code Virtual memory (a process) pp. 359

Virtual memory (a process) kernel page 2 page 1 Physical memory มีจำกัด RAM แพง page 5 page 4 page 3 page 5 page 2 page 4 page 1 page 3 Virtual memory (a process) Storage (HD)

มี logical กับ physical Summary มี logical กับ physical แบ่งเป็น page ไม่ใช่ contiguous swap กับดิสก์ Virtual memory = mapping + paging + swapping valid/invalid bit ในรูปนี้ ใช้บอกว่า page นั้น อยู่บน memory หรือไม่ pp. 362

Demand Paging Demand paging = lazy swapping pp. 361 Swap-in algorithm The OS only swaps a page into memory when it is required by a process ถ้า swap-in ไม่ได้ (memory เต็ม) ก็ต้องทำ swap-out ก่อน แบบ lazy จะตรงข้ามกับแบบ intelligent หรือ speculative pp. 361

Page Fault pp. 363 Locality of Reference เพราะธรรมชาติของ memory access ไม่ random ถึงใช้ page และ virtual memory ได้ pp. 363

Copy-on-Write After forking. Parent and child share the same copy. Make another copy of page C when a process writes. pp. 368

Demand paging requires 1) frame-allocation algorithm 2) page-replacement algorithm จะให้กี่ max. frame per process page ไหนจะเป็น victim Reference string To know the number of page faults, you need to know the number of max frames. จะเกิด page fault กี่ครั้ง มี maximum frame เท่าใด max = 2 เกิด page fault, max = 3 ไม่เกิด

ช่อง load M คือ executable code 2 frame แรกสำหรับจอภาพ เต็มหมดทุก frame ไม่มีที่ว่างสำหรับ M

ช่องนี้ก่อน หน้าคงเป็น f

Frequency ของ การเกิด page fault Max. frame per process

Page Replacement Algo. (summary) 1) FIFO page replacement - Belady’s anomaly 2) Optimal page replacement Replace the page that will not be used for the longest period of time. - Similar to SJF, requiring future knowledge. 3) Least-recently-used (LRU) page replacement Counter, equip a counter for each entry in page table Stack, move the referenced page to TOS LRU-approximation page replacement Additional-reference-bits algorithm Second-chance algorithm Enhanced second-chance algorithm

Page Replacement (cont.) not recently as the previous 5) Counting-based page replacement Least frequently used (LFU) page-replacement algorithm Most frequently used (MFU) page-replacement algorithm Page-buffering algorithms (เป็นเทคนิคเสริม) Page fault, not choose a victim, borrow a frame Step 1 frame frame frame Delay writing out or do it when CPU is idle. Increase response time. frame frame frame frame frame Step 2 A process Max. #frames = 3 Pool of free frames HD

Belady’s anomaly (undesired characteristics)

Using frame number “n” if n is in stack move n to TOS else push n

Shift right (less registers than counter) Additional-reference-bits algorithm Counting is more expensive then shifting Example 1000 0000 100ms 0100 0000 0010 0000 access 1010 0000 0101 0000 Shift right (less registers than counter) MSB LSB Each page has a corresponding 8-bit register. If the page is accessed, MSB is set to 1. Every 100 ms, shift-right (÷2) all registers. The page with the lowest number is the LRU page. มองไปในอดีตได้ไกลมาก เท่าไรก็ได้ (ปรับ 100ms ให้มากขึ้น) แต่ใช้ที่ 8 บิทเสมอ เหมือนการใช้ counter แต่เป็นการประมาณค่า เช่น page A 10000000 → 10000000 …. → 01000000 page B 00000000 → 10000000 …. → 01000000 access A access B Page A is older but as time passed no difference between A and B. เพราะ access A กับ access B มันเกิดใกล้กันมาก การประมาณค่าทำให้แยกไม่ได้ แต่ผิดไม่เกิน 100ms

FIFO + Second Chance Referenced Set ref. bit to 1 Give the second chance, clear 0 Replace Advance pointer and clear reference bits Current pointer Clear Clear Step 1. ใช้หลัก FIFO เริ่มจากหัวคิว 2. ถ้า ref bit = 0, ได้ victim แล้ว ถ้า ref bit = 1, clear ไปตัวถัดไป 3. อาจจะต้องวนมาเริ่มใหม่ (ได้ second chance กันหมด) 4. ถ้าได้ victim แล้ว ให้โหลด new page มาทับ victim และให้ไป ต่อท้ายคิว ตามหลักการ FIFO If a page is used often enough to keep its reference bit set, it will never been replaced. Victim Load new page, set ref bit to 1 move to the end of Q

Enhanced second-chance algorithm (modify bit) modify bit 0 = not modified 1 = modified first choice (0, 0) neither recently used nor modified – best page to replace (0, 1) not recently used but modified – not quite as good and need writing disk (1, 0) recently used but clean – probably will be used again soon (1, 1) recently used and modified – used again soon and need writing disk last choice We may have to scan the circular queue several times. The major diff. with second chance algo. is the preference to reduce I/O traffic.

Allocation of Frames 1) Minimum number of frames Instruction set architecture: add a1 a2 a3 min = 3 ld r1 a4 min = 1 2) Allocation algorithms Equal allocation ให้ทุก process เท่า ๆ กัน Proportional allocation เกลี่ยให้ตามความต้องการใช้ memory ของแต่ละ process

Global vs. Local allocation - a process uses max frames. - when requesting a free frame, choose a victim from its own set of allocated frame. 2) Global allocation - choose a victim from the set of all frames, even if that frame is currently allocated to some other process.

Thrashing Definition: high paging activity. OS ต้อง predict ได้ว่าจะเกิด thrashing ให้ลด degree of multiprogramming การ predict ต้องใช้ working set model มีหลาย process เกินไป แย่ง frame กัน มี 1 process CPU จะ idle เพราะรอ I/O และไม่มี process อื่น ให้ execute #process ใน ready queue

Working-Set Model Working set = set of pages in the most recent ∆ page references. เช่น P1 ใช้ WSS = 8, P2 ใช้ WSS = 6 Demand = 8 + 6 =14 ถ้า demand > supply (allocated frames) ก็เพิ่ม frame ให้แต่ละ process (equal or proportional) แต่ถ้าไม่มี frame เหลือแล้ว ให้ลด degree of multiprogramming หรือลดจำนวน process ใน ready queue

Page-Fault Frequency

พฟืtransition จาก working set นึงไปยังอีก working นึง Working sets and page fault rates 1 1 2 1 3 1 2 3 1 2 3 2 1 2 3 2 1 4 5 4 6 5 5 6 6 4 5 4 4 4 ถ้าวัดในช่วงเวลานี้ จะได้ working set นี้เสมอ หรือ เกือบๆ page fault ตก โหลด working set เข้ามาทุก frame แล้ว เริ่มเกิด page fault เนื่องจาก process ย้ายไป working set ใหม่ พฟืtransition จาก working set นึงไปยังอีก working นึง ธรรมชาติของ process จะเป็นแบบนี้

อัตราการเกิด page fault เพิ่มขึ้นอย่างรวดเร็ว Homework Page faults / sec อัตราการเกิด page fault เพิ่มขึ้นอย่างรวดเร็ว time t1 t2 Thrashing or Moving from a working set to another working set ? Hint: ต้องดูข้อมูลอะไรเพิ่มบ้าง? assume ว่าเราไม่รู้ page fault rate ที่เวลา < t1 และ > t2