1 / 31

Virtual Memory

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.com/en-us/library/windows/desktop/aa366778(v=vs.85).aspx. Max. memory per a process.

maris
Download Presentation

Virtual Memory

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Memory Limits for Windows Releaseshttp://msdn.microsoft.com/en-us/library/windows/desktop/aa366778(v=vs.85).aspx

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

  4. Max. memory per a VM (.NET or Java)Max. memory per a single objectmax 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

  5. Virtual Memory stack No correspondingphysical 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

  6. Virtual Memory 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)

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

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

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

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

  11. 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 ไม่เกิด

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

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

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

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

  16. 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 offree frames HD

  17. Belady’s anomaly(undesired characteristics)

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

  19. Additional-reference-bits algorithm Counting is more expensive then shifting Example 1000 0000 100ms 0100 0000 100ms 0010 0000 access 1010 0000 100ms 0101 0000 Shift right (less registers than counter) 0 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 B access A Page A is older but as time passed no difference between A and B.เพราะ access A กับ access B มันเกิดใกล้กันมาก การประมาณค่าทำให้แยกไม่ได้ แต่ผิดไม่เกิน 100ms

  20. 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 Step1. ใช้หลัก 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

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

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

  23. Global vs. Local allocation • 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.

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

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

  26. Page-Fault Frequency

  27. Working sets and page fault rates 1 1 2 1 3 1 2 3 1 2 3 2 1 2 3 2 14 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 จะเป็นแบบนี้

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

More Related