Download Sharing Memory - Lecture Slides - Operating Systems | CMSC 412 and more Study notes Operating Systems in PDF only on Docsity! 1CMSC 412 โ S04 (lect 11) Announcements Reading: โ Today: Chapter 9.4-9.6 Midterm: โ Tuesday 2CMSC 412 โ S04 (lect 11) Sharing Memory Pages can be shared โ several processes may share the same code or data โ several pages can be associated with the same page frame โ given read-only data, sharing is always safe when writes occur, decide if processes share data โ operating systems often implement โcopy on writeโ - pages are shared until a process carries out a write โข when a shared page is written, a new page frame is allocated โข writing process owns the modified page โข all other sharing processes own the original page โ page could be shared โข processes use semaphores or other means to coordinate access 5CMSC 412 โ S04 (lect 11) โ NOACCESS: attempts to read, write or execute will cause an access violation โ READONLY: attempts to write or execute memory in this region cause an access violation โ READWRITE: attempts to execute memory in this region cause an access violation โ EXECUTE: Attempts to read or write memory in this region cause an access violation โ EXECUTE_READ: Attempts to write to memory in this region cause an access violation โ EXECUTE_READ_WRITE: Do anything to this page โ WRITE_COPY: Attempts to write will cause the system to give a process its own copy of the page. Attempts to execute cause access violation โ EXECUTE_WRITE_COPY: Attempts to write will cause the system to give a process its own copy of a page. Canโt cause an access violation OS Protection attributes (Win32) 6CMSC 412 โ S04 (lect 11) Handling a page fault 1) Check if the reference is valid โ if not, terminate the process 2) Find a page frame to allocate for the new process โ for now we assume there is a free page frame. 3) Schedule a read operation to load the page from disk โ we can run other processes while waiting for this to complete 4) Modify the page table entry to the page 5) Restart the faulting instruction โ hardware normally will abort the instruction so we just return from the trap to the correct location. 7CMSC 412 โ S04 (lect 11) Page Fault โ Page is Paged out Page Directory Page Table Page Frames P1 Reference To this page 1) Fault 2) Read from Disk 3) Make Entry 4) Continue 10CMSC 412 โ S04 (lect 11) Page Replacement Algorithms FIFO โ Replace the page that was brought in longest ago โ However โข old pages may be great pages (frequently used) โข number of page faults may increase when one increases number of page frames (discouraging!) โ called beladyโs anomaly โ 1,2,3,4,1,2,5,1,2,3,4,5 (consider 3 vs. 4 frames) Optimal โ Replace the page that will be used furthest in the future โ Good algorithm(!) but requires knowledge of the future โ With good compiler assistance, knowledge of the future is sometimes possible 11CMSC 412 โ S04 (lect 11) Page Replacement Algorithms FIFO โ Replace the page that was brought in longest ago โ However โข old pages may be great pages (frequently used) โข number of page faults may increase when one increases number of page frames (discouraging!) โ called beladyโs anomaly โ 1,2,3,4,1,2,5,1,2,3,4,5 (consider 3 vs. 4 frames) Optimal โ Replace the page that will be used furthest in the future โ Good algorithm(!) but requires knowledge of the future โ With good compiler assistance, knowledge of the future is sometimes possible 12CMSC 412 โ S04 (lect 11) Page Replacement Algorithms LRU โ Replace the page that was actually used longest ago โ Implementation of LRU can be a bit expensive โข e.g. maintain a stack of nodes representing pages and put page on top of stack when the page is accessed โข maintain a time stamp associated with each page Approximate LRU algorithms โ maintain reference bit(s) which are set whenever a page is used โ at the end of a given time period, reference bits are cleared