1 / 54

Operating Systems

Operating Systems. Dr. Jerry Shiao, Silicon Valley University. Virtual Memory. Overview Memory Management Algorithms: Process in Physical Memory. Virtual Memory: Process Memory Larger than Physical Memory. . More programs run concurrently – multiprogramming.

Download Presentation

Operating Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operating Systems Dr. Jerry Shiao, Silicon Valley University SILICON VALLEY UNIVERSITY CONFIDENTIAL

  2. Virtual Memory • Overview • Memory Management Algorithms: Process in Physical Memory. • Virtual Memory: Process Memory Larger than Physical Memory. . • More programs run concurrently – multiprogramming. • More programs in memory – Increase CPU usage, less I/O for load or swap. • Demand Paging • Pager swaps In/Out Individual pages of a process. • Copy-on-Write • Page Sharing: Minimize Demand Paging • Page Replacement and Frame Allocation Algorithms • FIFO, Optimal, LRU, LRU-Approximation (Reference Bit), Second-Chance, Counting-Based (LFU, MFU), Page-Buffering Page Replacement Algorithms. • Equal, Proportional, Global vs Local Frame Allocation Algorithms. • Thrashing • Not enough free frames for processes for executing press. • Limit effects of Thrashing using Locality window and Working Set Model. • Memory-Mapped Files • Memory Mapped File I/O. • Allocating Kernel Memory • Slabs: Nonpaged contiguous frames. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  3. Virtual Memory • Memory Management Algorithms: • Support requirement of instructions residing in physical memory limits the size of physical memory. • Entire Process Image Not Needed in Memory • Code for Error Conditions. • Arrays, Lists, and Tables are over subscribed. • Functions to handle options or features of process that is rarely used. • Ability to Have Partial Process in Memory has benefits: • Process not constrainted by Physical Memory. • Large virtual address space. • More processes can be loaded in Physical Memory. • Increase CPU Utilization and Throughput. • Less overhead with Swapping processes in/out of memory. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  4. Virtual Memory • Virtual Memory • Separation of Logical Memory ( as seen by users ) from Physical Memory. • Large Virtual Memory maps into smaller physical memory. Logical Memory Larger than Physical Memory. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  5. Virtual Memory • Virtual Memory • Virtual Address Space of Process is the logical ( or virtual ) view of a process in physical memory. • Virtual Address Space used for: • Heap or Stack growth. • Dynamically linked libraries. • Memory shared between processes. Stack grows downward in memory though successive function calls. Heap grows upward for dynamic memory allocation. Virtual Address Space SILICON VALLEY UNIVERSITY CONFIDENTIAL

  6. Virtual Memory [student1@HWLAB ~]$ ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 16232 max locked memory (kbytes, -l) 32 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 16232 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited [student1@HWLAB ~]$ [student1@HWLAB ~]$ ulimit –s unlimited core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 16232 max locked memory (kbytes, -l) 32 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) unlimited cpu time (seconds, -t) unlimited max user processes (-u) 16232 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited [student1@HWLAB ~]$ • Virtual Memory SILICON VALLEY UNIVERSITY CONFIDENTIAL

  7. Virtual Memory • Mapping shared object into a Virtual Address Space of multiple processes. • System Libraries shared: • Actual physical pages of the library shared through the virtual address space of processes. • Library mapped read-only into space of each process. • Processes share memory: • One process creates region of memory shared with other processes. • Virtual Memory • Shared Library Using Virtual Memory SILICON VALLEY UNIVERSITY CONFIDENTIAL

  8. Virtual Memory • Demand Paging • Without Virtual Memory ( Limitation ): • All pages or segments pages of a process must be in Main Memory. • Demand Paging • Entire Program Not Needed in Memory, only load pages as needed. • Decreases swap time. • Decreases amount of memory needed (more processes in memory). • Faster response time. • Pager: Swaps In/Out individual pages of a process. • Lazy Swapper: Swaps page into memory when needed. • Start NO page in memory, load each page on demand (Page Fault). • Many page faults ( during) initialization. • Locality Of Reference: Reasonable performance from demand paging. • Knuth estimated that 90% of a program spends time in 10% of the code • Hardware Support • Page Table Valid-Invalid Bit. • Valid: Page is in memory. • In-Valid: Page currently on swap device. Page Fault. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  9. Virtual Memory • Demand Paging • Transfer Paged Memory In/Out SILICON VALLEY UNIVERSITY CONFIDENTIAL

  10. Frame # valid-invalid bit v v v v i i i page table Virtual Memory • Demand Paging • Each Page Table entry has a valid–invalid bit (v in-memory,i  not-in-memory) • Initially valid–invalid bit is set to i on all entries • During address translation, if valid–invalid bit in Page Table entry is I  Page Fault • During address translation, if valid–invalid bit in page table entry is I  page fault SILICON VALLEY UNIVERSITY CONFIDENTIAL

  11. Virtual Memory • Demand Paging SILICON VALLEY UNIVERSITY CONFIDENTIAL

  12. Virtual Memory • Demand Paging • Handling Page Fault: • Check Page Table in PCB, “invalid” bit. • Reference swap in page. • Operating System Frame Table has free frame entry. • Schedule disk operation to swap in desired page into frame entry. • Modify Page Table in PCB, “valid” bit. • Restart instruction interrupted by the Page Fault trap. Process access the page. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  13. Virtual Memory • Demand Paging • Restart Instruction After Page Fault • State of the Process ( Registers, Condition Code, Instruction Counter ) Saved. • Restart at Exactly Same Place and State. • Worst Case Scenerios: • A + B = C; • memcpy( dest, src, n ); • Effective Access Time: • EAT = ( 1 – p ) x ma + p x page fault time. • No Faults ( p = 0 ): Equal to memory access time (10 – 200 Nanoseconds ). • p = Page Fault Rate, ma = 200 ns, page fault service time = 8 ms • EAT = ( 1 – p ) x 200 + p x 8,000,000 • EAT directly proportional to the Page Fault Rate. • 1 out of 100,000, system slowed down by 40 times. • 1 out of 400,000, system slow down to 10%. • Alternative Use of Swap Space • File Disk I/O use swap space ( larger blocks, no file system overhead ). • Only used for binary files ( no writes ). SILICON VALLEY UNIVERSITY CONFIDENTIAL

  14. Virtual Memory • Copy-on-Write • fork( ) creates copy of the parent’s address space • Child process calls exec( ), address space copy time wasted. • Copy-on-Write ( Page Sharing ) minimize new pages allocated to child process and rapid process creation. • Parent and child process Page Table entry points to same physical page. • Page Table entry marked as Copy-on-Write. • Either parent or child writes to the page, a copy of shared page is created. • Copied page taken from pool of free pages: Heap, Stack, or Copy-on-Write. • vfork( ), Virtual Memory Fork, suspends parent process and child uses parent process address space. • Child process calls exec( ) immediately when created. • Fast, efficient method of process creation. • UNIX command-line shell interfaces. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  15. Virtual Memory 1) Parent and Child Process share same pages. 2) Shared Pages marked as Copy-On-Write in processes Page Table. • Copy on Write 3) Process1 writes to Page C, copy of Page C created. 4) Process 1 and Process 2 does not modify each other’s data. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  16. Virtual Memory • Page Replacement • Increase Multiprogramming by Over-Allocating Memory. • Over-allocated Memory: Running processes with more pages than physical frames. • How to recover from “No Free Frames”? • Swap out process: Reduces level of multiprogramming. • Page Replacement: Find frame not currently used and free it. • Write frame contents to swap space. • Change Page Table and Frame Table. • Use free frame for process with Page Fault. • Read desired page into free frame. • Change Page Table and Frame Table. • Requires two page transfers, doubles Page-Fault Service Time. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  17. Virtual Memory 0 User 1 executing “load M” requires Page 3 to be loaded. There is no free frames. • Page Replacement Detection User 2 executing at Page 1. Page 1 is “Invalid” and needs to be loaded. There is no free frames. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  18. Virtual Memory • Page Replacement • Demand Paging Require Page-Replacement Algorithm and Frame-Allocation Algorithm • Completes separation of Logical Memory and Physical Memory. • Large Virtual Memory on a Smaller Physical Memory. • Page-Replacement Algorithm • When Page Replacement is required, decide on which frame has to be replaced. • Frame-Allocation Algorithm • Multiple processes in memory, decide on how many frames to allocate to each process. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  19. Virtual Memory • Page Replacement • Use Page Replacement Algorithm to find a “victim” frame. • Update the Page Table and Frame Table to “Invalid”. Create a free frame. • Swap in the desired page to the free frame. • Update the Page Table and Frame Table for the swapped in page. Select the “victim” frame: 1) Modify bit (dirty bit) set by hardware when page written. Need Swap Out / Swap In. 2) Modify bit NOT set, page NOT written. Need Swap In. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  20. Virtual Memory • Page Replacement Algorithm • Disk I/O Expensive. • Page Reference String: Sequence of Page Requests. • More Page Frames (increase Physical Memory), Page Faults decreases. • FiFO Page Replacement • When a Page is replaced, the oldest Page is chosen. • Belady’s Anomaly: On certain Page Reference String, Page-Fault rate may increase as the number of allocated Page Frames increase. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  21. Virtual Memory FIFO Page-Replacement Algorithm 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 • Page Replacement Algorithm 4 7 7 7 0 7 0 2 0 0 2 4 0 2 7 4 2 0 7 0 0 1 1 0 0 0 0 0 3 1 3 2 3 2 1 2 1 2 2 3 Frames FIFO Queue 0 3 2 3 2 3 0 2 0 1 2 1 2 1 1 1 3 3 F F F F F F F F F F F F F F F Fault occurs when page referenced. Page Reference String. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  22. Virtual Memory • Optimal Page Replacement Algorithm • Of the frames in memory, replace page that will not be used for the longest period of time. • Pages not referenced will be removed from the frames. • Lowest possible Page-Fault Rate for fixed number of frames. • Difficult to implement because future knowledge of Reference String required. • Mainly used for comparision studies. Optimal Page-Replacement Algorithm 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 Out 7 7 7 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 7 7 0 0 0 0 0 0 4 4 4 0 0 0 0 0 0 0 0 0 0 1 1 1 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 F F F F F F F F F SILICON VALLEY UNIVERSITY CONFIDENTIAL

  23. Virtual Memory • LRU Replacement Algorithm • Use recent past as an approximation of the future use. • Of the frames in memory, replace the page that has not been used for the longest period of time. • Time-of-Use field and counter for each Page Table entry. • Stack with most recently used on top and least recently used on the bottom. LRU Page-Replacement Algorithm 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 7 7 7 2 2 2 2 4 4 4 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 3 3 3 3 3 3 0 0 0 0 0 1 1 1 3 3 3 2 2 2 2 2 2 2 2 2 7 7 7 F F F F F F F F F F F F SILICON VALLEY UNIVERSITY CONFIDENTIAL

  24. Virtual Memory Move 7 from its position in the stack to the top of the stack. • LRU Replacement Algorithm • Stack Implementation SILICON VALLEY UNIVERSITY CONFIDENTIAL

  25. Virtual Memory • LRU-Approximation Page Replacement Algorithm • LRU Difficult Without Hardware Support • Update Every Memory Reference. • System Support for LRU: • Reference Bit in Page Table: Set to 1 when read/write. • Scan the Page Table to find Page Entry with Reference Bit 0. • Order of use is not known. • Reference Bit recorded at regular intervals. • Table of Reference Byte for each Page in Page Table. • When Page is referenced, the Reference Byte has LSB set. • Timer interrupt at fixed interval shifts each Reference Byte. • The Reference Byte contains the history of page use for the last eight time periods ( 8 bit Byte ). • The Reference Byte with the lowest value is the LRU page. • Second Chance Reference Bit Algorithm • Reference Bit set when the page is referenced. • Timer interrupt at fixed interval points to next Page Table entry to check. • If Reference Bit set, clear bit and proceed to next entry ( second chance). • If Reference Bit not set, replace the page. • Worst case, Ptr cycles through Page Table, each has page second chance. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  26. Virtual Memory • LRU-Approximation Page Replacement Algorithm • Second-Chance Page Replacement Algorithm • Algorithm clears the Reference Bit after inspection. • If all Reference Bits were set, algorithm becomes a FIFO algorithm to select the page for replacement. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  27. Virtual Memory • LRU-Approximation Page Replacement Algorithm • Enhanced Second-Chance Algorithm • Reference Bit and Modified Bit Ordered Pair • ( 0, 0 ): Neither recently used or modified. Replace • ( 0, 1 ): Not recently used, modified. If replace, has to write the page first. • ( 1, 0 ): Recently used, Not modified. Likely used again soon. • ( 1, 1 ): Recently used, modified: Likely used again soon, has to write the page first. • Circular queue scanned several times before select page. • Gives preference to page that has been modified, try to avoid replacing page that needs to be written. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  28. Virtual Memory • LRU-Approximation Page Replacement Algorithm • Counting-Based Page Replacement Algorithm • Reference count for each page. • LFU Algorithm: Least Frequently Used. • Replace page with smallest count. • Use timer interrupt to right shift count. • MFU Algorithm: Most Frequently Used. • Replace page with largest count. • Small Reference count indicates page has just been loaded and will be used. • Page-Buffering Algorithm • Pool of free frames. • Page is reloaded from the free frame pool, if frame has not been modified. I/O is NOT necessary. • VAX/VMS uses in combination with FIFO Replace Algorithm. • Some versions of UNIX system uses in conjunction with Second-Chance Replacement Algorithm. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  29. Virtual Memory • Allocation of Frames • How to allocate fixed free memory to user/kernel processes? • Process Frame Allocation Schemes • Minimum Number of Frames Per Process • Computer Architecture Define Number of Pages Needed • Instruction: IBM 370 MOVE instruction Require 6 Pages: • Instruction is 6 Bytes, span 2 Pages. • Source block can span 2 Pages. • Destination block can span 2 Pages • Indirection: Indirect Addressing Can Require a Page for each Level. • Limit on the number of indirections. • Allocation Algorithms • Equal Allocation (equally divide frames between processes). • Waste frames for small processes • Proportional Allocation • Allocate according to size of the process. • Allocate = (process size) / (summation all process sizes) X (Total Frames) • Use ( priority adjustment + process size) to favor high priority processes. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  30. Virtual Memory • Allocation of Frames • Equal Allocation – For example, if there are 100 frames and 5 processes, give each process 20 frames. • Proportional Allocation – Allocate according to the virtual memory requirement of the process Using Priority Adjustment: Process Pi has higher priority and has adjustment = 10. a1 = (10 + 10) / 137 X 64 = 9 Frames SILICON VALLEY UNIVERSITY CONFIDENTIAL

  31. Virtual Memory • Allocation of Frames • Global Versus Local Frame Allocation • Global Page Replacement Selection • Process select from the set of ALL frames, including other processes. • Allocation scheme allow high-priority process to select frames from low-priority processes. • Local Page Replacement Selection • Process select ONLY from its own set of allocated frames. • Tend to hinder throughput, since other processes cannot use any unused frames of processes. • Memory Locality Issue: • Non-Uniform Memory Access • Memory access times vary because memory subsystem located on different boards. • Multi-processor Systems with several system boards and memory on different system boards. • Operating System tries to allocate frames close the the CPU where the process is scheduled (improves cache hits and memory access times). SILICON VALLEY UNIVERSITY CONFIDENTIAL

  32. Virtual Memory • Thrashing • Excessive Paging Activity in a Process, causing by the Operating System continually swapping the Process’ pages out and in. • As degree of multiprogramming increases, the CPU utilization increases. • At some point, the thrashing sets in, CPU utilization drops sharply. There are not enough physical frames to satisfy all processes paging request. The Operating System starts to swap pages out from running systems to allow processes to swap pages in to continue to execute. • Operating System scheduler attempts to increase the degree of multiprogramming, by scheduling more processes, which causes more page faults and longer queue for the paging device. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  33. Virtual Memory • Thrashing • Limit effects of thrashing: • Use Local Replacement Algorithm or Priority Replacement Algorithm. • Process can only access pages from its own set of allocated frames. • Use process execution Locality model. • Locality is the set of pages process actively use together. • Memory reference structure made of instructions of function calls, its local data structure, local variables, and subset of global variables. • This patterned data access is principle behind caching. • Process composed of several different localities. • Allocate enough frames to a process to accommodate its current Locality. • Process Working-Set Window • The set of pages (delta) in the most recent page reference is the working set. • Delta is the approximation of the program’s locality. • Delta is too small, it will not encompass the entire locality. • Delta is too large, it may overlap several localities. • Once Delta is selected, process is allocated enough frames for its WS. • Approximate Working-Set model: Use fixed-interval timer and Page Table Reference Bit. • Suspend process: • Thrashing Occurs when:  size of locality > total memory size SILICON VALLEY UNIVERSITY CONFIDENTIAL

  34. Virtual Memory • Thrashing • Working Set Model  = 10 Memory References WSSi (working set of Process Pi) = total number of pages referenced in the most recent  (varies in time) D =  WSSi  total demand frames M = total number of available frames If D > M  Thrashing Policy: If D > M, then suspend process. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  35. Virtual Memory 1) Peak in Page Fault Rate begin Demand-Paging in new Locality. 2) Once Working Set of new Locality is in memory, Page Fault Rate falls. • Working Set Model • Working Set of a Process changes over time as references to data and code section moves from one locality to another. 3) Pages for new Locality placed in physical frames. 4) Demand Paging in next Locality. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  36. Virtual Memory • Thrashing • Page-Fault Frequency ( PFF ) • Control Page-Fault Rate: • If Process Page-Fault Rate High, allocate more frames to process. • If Process Page-Fault Rate Low, remove allocated frames. • Suspend process when Page-Fault Rate increases and no frames are available. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  37. Virtual Memory • Memory-Mapped Files • File I/O Treated as Routine Memory Access. • Virtual address space logically associated with the file. • Map disk block to a page in memory. • Page sized portion of file is read from file system into physical page, using ordinary memory access to access file. • Multiple processes can map the same file concurrently, allowing sharing of data. • Memory Mapping UNIX and Linux: • mmap ( ): System call. • shmget ( ): System call. • shmat ( ): System call. • Memory Mapping Win32 API: • CreateFile( ): Opens file to be mapped. • CreateFileMapping ( ): Shared-memory object. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  38. Virtual Memory • Memory-Mapped Files SILICON VALLEY UNIVERSITY CONFIDENTIAL

  39. Virtual Memory • Memory-Mapped Files • Memory-Mapped I/O • I/O Controller contains registers to hold commands and data being transferred. • Special I/O instructions transfers data between registers and system memory. • Range of memory addresses reserved and mapped to the device registers. • Serial and Parallel Ports • CPU transfers data by read/write device data/control registers ( I/O ports ). • Device Ready: • Programmed I/O: CPU poll control register for device Ready. • Interrupt driven: Interrupt handler receive interrupt when device is Ready. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  40. Virtual Memory • Allocating Kernel Memory • User mode requests for free page frames allocated by list maintained by Kernel ( FIFO, Optimal, LRU, LRU-Approximation Page Replacement ). • Kernel memory allocated from different list: • Minimize internal fragmentation. Data structures less than page. • Hardware devices interact directly with physical memory, require memory residing in contiguous physical pages. • Buddy System • Allocates memory from fixed-size segment of physically contiguous pages. • Power-of-2 Allocator: Segments allocated in units sized as power of 2 ( 4 KB, 8 KB, 16 KB, 32 KB, … ). • Each segment split into two “buddies” of equal sizes, until segment size ( round up to next highest power of 2 ) can hold the memory request. • Coalescing: When segment released, coalesced with adjacent “buddy” ( if also free ) into larger segment. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  41. Virtual Memory • Allocating Kernel Memory • Buddy System • Current chunk split into two buddies of next-lower power of 2. • Continues until appropriate size chunk available. • Internal Fragmentation cannot guarantee less than 50% unused memory. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  42. Virtual Memory • Allocating Kernel Memory • Slab Allocator System • Slab is one or more physically contiguous pages. • Cache is assigned to one or more slabs. • Single cache for each unique kernel data structure. • Cache is filled with instantiations of the kernel data structure. • A cache can be filled with process descriptor data structures or semaphore data structures or file object data structures. • Cache objects does not have to be contiguous, but taken from assigned slab. • Cache objects marked as FREE when cache is created and object released. • Cache object marked as USED when cache object allocated from the slab for the requested data structure. • If slab full of USED objects, object allocated from empty slab. • If no empty slabs are available, new slab is allocated from continguous physical pages and the slab is assigned to the cache. The Object is allocated from the slab. • Slab States • Full: All objects in the slab marked as USED. • Empty: All objects in the slab marked as FREE. • Partial: Both USED and FREE objects in the slab. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  43. Virtual Memory • Allocating Kernel Memory • Slab Allocator System • Benefits: • No memory wasted due to fragmentation. Cache assigned to slab that is divided up into chunks the size of the cache object. • Memory request satisfied quickly. Efficient when objects frequently allocated and deallocated. Since objects created in advance, objects can be quickly allocated. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  44. Virtual Memory • Other Paging System Issues • Prepaging • Large number of page faults occur during process initialization and when process swapped-in. • Using the Working Set model ( Locality ), list of pages in the Working Set can be saved and when process swapped-in, the Working Set pages are preloaded. • Risk of preloaded pages not used (I/O and memory wasted). • Page Size • Page Table increases with smaller Page size. • Internal Fragmentation greater with larger Page size. • On average, half of the process final page is unused. • I/O Overhead ( Seek, Latency, and Transfer times ). • Seek and Latency overhead dwarfs Transfer time. • Large Page size needs less I/O. • Locality best matched with smaller Page size. • Smaller Page size will match program locality more accurately, resulting in less total allocated memory. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  45. Virtual Memory • Other Paging System Issues • TLB Reach: Amount of memory accessible from the TLB. • Hit Ratio: Virtual address translation in the TLB. • TLB Reach = (Number of entries X Page size). • Ideal Condition: Working Set for Process Stored in TLB. • Otherwise access Page Table in memory. • Increase TLB Reach by increasing size of Page. • Cause Internal Fragmentation. • Increase TLB Reach by using multiple Page sizes. • Require Operating System ( instead of hardware ) to manage TLB. • Managing TLB in Operating System affects performance. • Increased Hit Ratio and TLB Reach offsets the performance costs. • Manages TLB in hardware: PowerPC, Pentium architectures. • Manages TLB in software: UltraSparc, MIPS, and Alpha architectures. • Inverted Page Table • One entry per page of physical memory: • Indexed by < process-id, page-number >. • Need External Page Table per process with virtual page is located. • Delay to page in the External Page Table with location of virtual page in backing store, but only needed when Page Fault. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  46. Virtual Memory • Other Paging System Issues • Program Structure • Selection of data structures and programming structures can increase Locality and reduce Page-Fault Rate and reduce number of pages needed in the Working Set. • Stack has good Locality since access made at the top. • Hash Table has bad Locality since references are scattered. • Compensate with search speed, and less memory references. • C and C++ uses pointers and randomize memory references, causing bad Locality. • C++ or object-oriented programs tend to have bad Locality. • Compiler and Loader can have affect on paging. • Separating code and data can have code in read-only pages. • Clean pages ( not modified ) does not have to be written before paged out. • Routines with interactions can be placed in one page. • Loader avoid placing routines across page boundaries. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  47. Virtual Memory • Other Paging System Issues • Program Structure • Array data[128,128] • Each row (data[0,n], data[1,n] is stored in one page • Program 1 for (j = 0; j <128; j++) for (i = 0; i < 128; i++) data[i,j] = 0; 128 x 128 = 16,384 page faults • Program 2 for (i = 0; i < 128; i++) for (j = 0; j < 128; j++) data[i,j] = 0; 128 page faults Each iteration access new row and causes a page fault. Each iteration access new column and same row. Does NOT causes a page fault. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  48. Virtual Memory • Other Paging System Issues • I/O Interlock • Problem: User memory I/O must not swap out page with buffer. • Impose restriction: • I/O only takes place between system memory and I/O device. • Data always copied from system memory to user memory, • Undesirable because of high overhead caused by extra copy between system and user memory. • More desirable restriction: Frame Table entry contains lock bit, preventing frame from being selected for replacement. • Lock page containing user buffer until I/O completes. • Lock Bit Situations: • Operating System Kernel locked into memory. • Lock newly paged-in frame until it is used at least once. • Prevents process that has completed a page request from having its newly paged-in frame from being paged out by a higher priority process. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  49. Virtual Memory • Operating System Examples • Windows XP • Virtual Memory • Demand Paging with Clustering • Clustering loads pages surrounding the faulting page. • Process assigned Working Set Minimum and Working Set Maximum. • Working Set Minimum: Guaranteed minimum number of pages. • Working Set Maximum: Max assigned pages. • Virtual Memory Manager maintains list of free page frames. • Processes are allocated page frames from the list, until the process has reached its Working Set Maximum. • The process will select a page for replacement using Local Page Replacement Algorithm. • Virtual Memory Manager manages free memory threshold: Uses Automatic Working Set Trimming to removes pages from processes until the process is at its Working Set Minimum. SILICON VALLEY UNIVERSITY CONFIDENTIAL

  50. Virtual Memory • Operating System Examples • Solaris • Maintains list of free pages to assign faulting processes. • Kernel checks 4 times per second for lotsfree threshold. • Lotsfree: Threshold parameter (1/64 physical memory) to begin paging. • Pageout process starts: Second-chance Page Replacement algorithm. • Pageout process scans at “slowscan”, 100 pages per second, and scan rate increases as amount of free memory decreases. • Cache list of pages that have been paged out, but can be reclaimed. • Destfree: Threshold parameter • Pageout process runs 100 times per second. • Kernel swapping processes, freeing all pages allocated to swapped processes. • Minfree: Threshold parameter • Pageout process called for every request for a new page. • Pageout process scans max at “fastscan” or 8192 pages per second. SILICON VALLEY UNIVERSITY CONFIDENTIAL

More Related