Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Hardware Support Clock Algorithm Thrashing Cause Working Set.

Similar presentations


Presentation on theme: "1 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Hardware Support Clock Algorithm Thrashing Cause Working Set."— Presentation transcript:

1 1 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Hardware Support Clock Algorithm Thrashing Cause Working Set

2 2 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A, B, C, B, C, C, D

3 3 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A1A1 A, B, C, B, C, C, D

4 4 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A1A1 B2B2 A, B, C, B, C, C, D

5 5 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A1A1 B2B2 C3C3 A, B, C, B, C, C, D

6 6 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A1A1 B4B4 C3C3 A, B, C, B, C, C, D

7 7 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A1A1 B4B4 C5C5 A, B, C, B, C, C, D

8 8 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A1A1 B4B4 C6C6 A, B, C, B, C, C, D

9 9 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A1A1 B4B4 C6C6 A, B, C, B, C, C, D D7D7 LRU page How should we implement this?

10 10 Implementing Exact LRU: Data Structures Hash table: optimize the common case (memory hit) Location of a page in memory: apply hash function to a page number update: O(1), eviction: O(n) (n: # of pages to process) Expensive: on every reference, compute hash of page address; update time stamp doubly-linked list Move items to front when referenced LRU items at end of list Still too expensive: Linear lookup time to find a page 4-6 pointer updates per reference

11 11 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Reference-bit algorithm Clock Algorithm Thrashing Cause Working Set

12 12 Reference-bit algorithm Hardware support: reference bit Maintain reference bit for every page On each access, set reference bit to 1 Periodically resets reference bits Evict page with reference bit = 0

13 13 Reference-bit algorithm: example Maintain reference bit for every page On each access, set reference bit to 1 Periodically resets reference bits Evict page with reference bit = 0 A1A1 B1B1 C1C1 A, B, C, B, C, C, D

14 14 Reference-bit algorithm: example Maintain reference bit for every page On each access, set reference bit to 1 Periodically resets reference bits Evict page with reference bit = 0 A0A0 B0B0 C0C0 A, B, C, B, C, C, D reset reference bits

15 15 Reference-bit algorithm: example Maintain reference bit for every page On each access, set reference bit to 1 Periodically resets reference bits Evict page with reference bit = 0 A0A0 B1B1 C0C0 A, B, C, B, C, C, D

16 16 Reference-bit algorithm: example Maintain reference bit for every page On each access, set reference bit to 1 Periodically resets reference bits Evict page with reference bit = 0 A0A0 B1B1 C1C1 A, B, C, B, C, C, D

17 17 Reference-bit algorithm: example Maintain reference bit for every page On each access, set reference bit to 1 Periodically resets reference bits Evict page with reference bit = 0 A0A0 B1B1 C1C1 A, B, C, B, C, C, D

18 18 Reference-bit algorithm: example Maintain reference bit for every page On each access, set reference bit to 1 Periodically resets reference bits Evict page with reference bit = 0 A0A0 B1B1 C1C1 A, B, C, B, C, C, D D1D1

19 19 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Reference-bit algorithm Clock Algorithm Thrashing Cause Working Set

20 20 The Clock Algorithm Set reference bit to 1 for an access Consider frames in circle Pointer: 0: initially Only advance pointer when page fault happens On page fault, OS: Repeat Checks reference bit of the current pointer If reference bit = 0, replace page, set bit to 1; advance pointer to next frame; break; If reference bit = 1, set bit to 0, advance pointer to next frame

21 21 The Clock Algorithm: example A, B, C, D, B, C, E, F, C, G

22 22 The Clock Algorithm: Summary Variant of FIFO & LRU LRU: ? FIFO: ? No need to reset reference bit periodically

23 23 Enhancing Clock Idea: favor eviction of unmodified pages We don’t write back unmodified pages Extend hardware to keep another bit: modified bit Total order of tuples: (ref bit, mod bit) (0,0), (0,1), (1,0), (1,1) Evict page from lowest nonempty class

24 24 Page Replacement in Enhanced Clock OS may scan multiple times: Page (0,0) – replace that page Page (0,1) – replace and write out page Page (1,0) – replace that page Page (1,1) – replace and write out page Fast, but still coarse approximation of LRU

25 25 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Reference-bit algorithm Clock Thrashing Cause Working Set

26 26 Thrashing A process is busy swapping pages in and out; no useful work is done low CPU utilization OS adds processes → even more page swapping & lower CPU utilization

27 27 Cause of Thrashing Locality A set of pages that are actively used together Process migrates from one locality to another Total locality of processes > total memory size Process cannot keep in memory all pages that it is currently using

28 28 Working Set Strategy Working set = pages referred in last  references (approximate of locality) OS monitors working set of each process; allocate enough frames to process Another process can be started if there are enough extra frames Suspend process(es) if the sum of working-set sizes exceeds RAM

29 29 Working Set Problems Algorithm relies on key parameter,  How do we set  ? Is there one correct  ? Different processes have different timescales over which they refer pages Not acceptable (or necessarily possible) to suspend processes altogether Not really used Very rough variant used in Windows


Download ppt "1 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Hardware Support Clock Algorithm Thrashing Cause Working Set."

Similar presentations


Ads by Google