งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

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

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "Virtual Memory Why? The need of memory more than the available physical memory. Process 3 Physical Memory Process 2 Process 1 Process 4."— ใบสำเนางานนำเสนอ:

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

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

3 Max. memory per a process

4 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

5 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

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

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

8 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

9 Page Fault pp. 363 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 of free frames HD

17

18 Belady’s anomaly (undesired characteristics)

19

20

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

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

23 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

24 Enhanced second-chance algorithm (modify bit)
modify bit = not modified = 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.

25 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

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

27 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

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

29 Page-Fault Frequency

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

31 อัตราการเกิด page fault เพิ่มขึ้นอย่างรวดเร็ว
Quiz 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


ดาวน์โหลด ppt Virtual Memory Why? The need of memory more than the available physical memory. Process 3 Physical Memory Process 2 Process 1 Process 4.

งานนำเสนอที่คล้ายกัน


Ads by Google