Presentation is loading. Please wait.

Presentation is loading. Please wait.

Virtual Memory Management G. Anuradha Ref:- Galvin.

Similar presentations


Presentation on theme: "Virtual Memory Management G. Anuradha Ref:- Galvin."— Presentation transcript:

1 Virtual Memory Management G. Anuradha Ref:- Galvin

2 Background Virtual memory – separation of user logical memory from physical memory. – Only part of the program needs to be in memory for execution – Logical address space can therefore be much larger than physical address space – Allows address spaces to be shared by several processes – Allows for more efficient process creation Virtual memory can be implemented via: – Demand paging – Demand segmentation

3

4

5

6

7 Demand Paging Bring a page into memory only when it is needed – Less I/O needed – Less memory needed – Faster response – More users Page is needed  reference to it – invalid reference  abort – not-in-memory  bring to memory Lazy swapper – never swaps a page into memory unless page will be needed – Swapper that deals with pages is a pager

8 Transfer of a Paged Memory to Contiguous Disk Space

9 Valid-Invalid Bit With each page table entry a valid–invalid bit is associated (v  in-memory, i  not-in-memory) Initially valid–invalid bit is set to i on all entries Example of a page table snapshot: During address translation, if valid–invalid bit in page table entry is I  page fault v v v v i i i …. Frame #valid-invalid bit page table

10 Page Table When Some Pages Are Not in Main Memory

11 Page Fault If there is a reference to a page, first reference to that page will trap to operating system: page fault 1.Operating system looks at another table to decide: – Invalid reference  abort – Just not in memory 2.Get empty frame 3.Swap page into frame 4.Reset tables 5.Set validation bit = v 6.Restart the instruction that caused the page fault

12 Steps in Handling a Page Fault

13 Demand Paging Pure Demand Paging:- – Begin a process with no pages in the memory – Bring the pages only as and when required Hardware support for demand paging – Page table – Secondary memory

14 Performance of Demand Paging Page Fault Rate 0  p  1.0 – if p = 0 no page faults – if p = 1, every reference is a fault Effective Access Time (EAT) EAT = (1 – p) x memory access + p (page fault overhead )

15 Sequence of events when a page fault occurs 1.Trap to OS 2.Save the user registers and process states 3.Determine the interrupt that causes a page fault 4.Check that the page referred was legal and determine the location of the page on the disk 5.Issue a read from the disk to free frame 1.Wait in a queue until serviced 2.Wait for device seek/latency time 3.Begin the transfer of page to a free frame

16 6.While waiting, allocate the CPU to some other user 7.Receive an interrupt from the disk I/O subsystem 8.Save the registers and process state for the other user 9.Determine that the interrupt was from disk 10.Correct page table entries 11.Wait for CPU to be allocated to the process again 12.Restore the user registers, process state and then resume the interrupted instruction Sequence of events when a page fault occurs

17 Effective Access Time (EAT) EAT = (1 – p) x memory access + p (page fault overhead + swap page out + swap page in + restart overhead )

18 Demand Paging Example Memory access time = 200 nanoseconds Average page-fault service time = 8 milliseconds Effective Access Time (EAT) = (1 – p) x 200 + p (8 milliseconds) = (1 – p) x 200 + p x 8,000,000 = 200 + p x 7,999,800 If one access out of 1,000 causes a page fault, then EAT = 8.2 microseconds. This is a slowdown by a factor of 40!! (PAGE FAULT SHOULD BE KEPT AT HE MINIMUM POSSIBLE VALUE IN ORDER TO IMPROVE THE ACCESS TIME)

19 Copy-on-write Process creation can be initiated by demand paging However fork command bypasses the need of demand paging Fork() command created a copy of the parent’s address space for the child If many child process uses the exec() system call a copy-on-write method is used

20 Before Process 1 Modifies Page C

21 After Process 1 Modifies Page C A copy of page C is created Child process will modify its copied page and not the page belonging to the parent process If pages are not modified then its shared by parent and child processes.

22 Page Replacement

23 Basic Page Replacement 1.Find the location of the desired page on disk 2.Find a free frame: - If there is a free frame, use it - If there is no free frame, use a page replacement algorithm to select a victim frame 3.Bring the desired page into the (newly) free frame; update the page and frame tables 4.Restart the process

24 Page Replacement Use modify (dirty) bit to reduce overhead of page transfers – only modified pages are written to disk

25 Page Replacement contd… Two major problems must be solved to implement demand paging – Frame allocation algorithm – Page-replacement algorithm Want lowest page-fault rate Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string

26 First-In-First-Out (FIFO) Algorithm Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 3 frames (3 pages can be in memory at a time per process) 4 frames Belady’s Anomaly: more frames  more page faults 1 2 3 1 2 3 4 1 2 5 3 4 9 page faults 1 2 3 1 2 3 5 1 2 4 5 10 page faults 4 43

27 FIFO Page Replacement

28 FIFO Illustrating Belady’s Anomaly

29 Optimal Algorithm Replace page that will not be used for longest period of time 4 frames example 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 How do you know this? Used for measuring how well your algorithm performs 1 2 3 4 6 page faults 4 5

30 Optimal Page Replacement Difficult to implement becos it requires future knowledge of reference string

31 Least Recently Used (LRU) Algorithm Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 Counter implementation – Every page entry has a counter; every time page is referenced through this entry, copy the clock into the counter – When a page needs to be changed, look at the counters to determine which are to change 5 2 4 3 1 2 3 4 1 2 5 4 1 2 5 3 1 2 4 3

32 LRU Page Replacement

33 LRU Algorithm (Cont.) Stack implementation – keep a stack of page numbers in a double link form: – Page referenced: move it to the top Most recently used page is always at the top of the stack and least recently used page is always at the bottom – Can be implemented by a double linked list with a head pointer and a tail pointer – Both LRU and ORU comes under the class of algos called as stack algorithm – Does not suffer from Belady’s Anamoly

34 Important questions 1.What is paging? Explain the structure of page table 2.What is belady’s algorithm? Explain LRU, FIFO, OPR algos. Which algorithm suffers from Belady’s anomaly? 3.Short note on page fault handling 4.Explain virtual memory and demand paging 5.Draw and explain paging hardware with TLB 6.Explain paging in detail. Describe how logical address converted to physical address 7.Explain how memory management takes place in Linux

35 Important questions


Download ppt "Virtual Memory Management G. Anuradha Ref:- Galvin."

Similar presentations


Ads by Google