Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 153 Design of Operating Systems Spring 2015 Lecture 19: Page Replacement and Memory War.

Similar presentations


Presentation on theme: "CS 153 Design of Operating Systems Spring 2015 Lecture 19: Page Replacement and Memory War."— Presentation transcript:

1 CS 153 Design of Operating Systems Spring 2015 Lecture 19: Page Replacement and Memory War

2 2 Working Set Model l A working set of a process is used to model the dynamic locality of its memory usage u Defined by Peter Denning in 60s l Definition u WS(t,w) = {set of pages P, such that every page in P was referenced in the time interval (t, t-w)} u t – time, w – working set window (measured in page refs) l A page is in the working set (WS) only if it was referenced in the last w references

3 3 Working Set Size l The working set size is the number of pages in the working set u The number of pages referenced in the interval (t, t-w) l The working set size changes with program locality u During periods of poor locality, you reference more pages u Within that period of time, the working set size is larger l Intuitively, want the working set to be the set of pages a process needs in memory to prevent heavy faulting u Each process has a parameter w that determines a working set with few faults u Denning: Don’t run a process unless working set is in memory

4 Example: gcc Working Set 4

5 5 Working Set Problems l Problems u How do we determine w? u How do we know when the working set changes? l Too hard to answer u So, working set is not used in practice as a page replacement algorithm l However, it is still used as an abstraction u The intuition is still valid u When people ask, “How much memory does Firefox need?”, they are in effect asking for the size of Firefox’s working set

6 6 Page Fault Frequency (PFF) l Page Fault Frequency (PFF) is a variable space algorithm that uses a more ad-hoc approach u Monitor the fault rate for each process u If the fault rate is above a high threshold, give it more memory »So that it faults less »But not always (FIFO, Belady’s Anomaly) u If the fault rate is below a low threshold, take away memory »Should fault more »But not always l Hard to use PFF to distinguish between changes in locality and changes in size of working set

7 7 Thrashing l Page replacement algorithms avoid thrashing u When most of the time is spent by the OS in paging data back and forth from disk u No time spent doing useful work (making progress) u In this situation, the system is overcommitted »No idea which pages should be in memory to reduce faults »Could just be that there isn’t enough physical memory for all of the processes in the system »Ex: Running Windows95 with 4 MB of memory… u Possible solutions »Swapping – write out all pages of a process »Buy more memory

8 Avoiding Thrashing with Minimum Memory l W: minimum amount of memory needed 8

9 Memory-related Security Problems 9 Stack 0x00000000 0xFFFFFFFF Code (Text Segment) Static Data (Data Segment) Heap (Dynamic Memory Alloc) Address Space SP PC Static Dynamic

10 Stack Buffer Overflow l Example from Wikipedia

11 Common Defenses 1/3 Stack canaries l Canary = random value inserted at each stack frame. It is checked at every call return l Effects: Attacks cannot easily guess the value and have to overwrite it

12 Memory War - Buffer Overflow 12 Stack 0x00000000 0xFFFFFFFF Code (Text Segment) Static Data (Data Segment) Heap (Dynamic Memory Alloc) Address Space Page Protection bits?

13 Commonly deployed defenses 2/3 Non-executable stack l Stack memory pages cannot be executed with this protection mechanism --- stack was designed as read/write memory only anyways l Effects: Attacks can only change return address to code pages (that are executable): u Return-to-libc u ROP (Return-Oriented Programming)

14 Commonly defenses 3/3 Address Space Layout Randomization (ASLR) l Base address of stacks, heaps, and binaries/libraries/kernel- modules are randomized l Effects: Attackers do not know what address to use, even for the state-of-the art ROP attack method

15 15 Summary l Page replacement algorithms u Belady’s – optimal replacement (minimum # of faults) u FIFO – replace page loaded furthest in past u LRU – replace page referenced furthest in past »Approximate using PTE reference bit u LRU Clock – replace page that is “old enough” u Working Set – keep the set of pages in memory that has minimal fault rate (the “working set”) u Page Fault Frequency – grow/shrink page set as a function of fault rate l Multiprogramming u Should a process replace its own page, or that of another?

16 16 Next time… l File systems u Chapters 11, 12, and 13

17 17

18 18 Example: Comparison

19 19 Example: Belady's Anomaly

20 20 Working Set: Example


Download ppt "CS 153 Design of Operating Systems Spring 2015 Lecture 19: Page Replacement and Memory War."

Similar presentations


Ads by Google