1 / 43

Operating Systems { week 13/14}

Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D. Operating Systems { week 13/14}. Noncontiguous allocation (i). A noncontiguous memory allocation scheme avoids the external fragmentation problem

denise
Download Presentation

Operating Systems { week 13/14}

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. Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D. Operating Systems{week 13/14}

  2. Noncontiguous allocation (i) • A noncontiguous memory allocation scheme avoids the external fragmentation problem • Slice up physical memory intofixed-sized blocks called frames • Sizes typically range from 216 and up! • Slice up logical memory intofixed-sized blocks called pages • Allocate pages into frames • Note that frame size equals page size

  3. process Pi == in use main memory == free Noncontiguous allocation (ii) • When a process of size n pages is ready to run, operating system finds n free frames • The OS keepstrack of pagesvia a page table

  4. Paging via a page table • Page tables map logical memoryaddresses to physical memoryaddresses

  5. page offset page number p d Address translation • Covers a logical addressspace of size 2m withpage size 2n (m – n) (n)

  6. Address translation

  7. Translation look-aside buffer • Use page tablecaching at thehardware levelto speed addresstranslation • Hardware-leveltranslation look-aside buffer(TLB)

  8. Segmentation (i) • Segmentation is a memory-management scheme that correspondsto logical segments of auser program • A segment resides in acontiguous block of memory • Segments are numberedand referred to by a<segment-number, offset> pair

  9. Segmentation (ii) • Logical segments map to physical memory 4 3 3 0 4 2 0 1 2 1

  10. Segment table (i) • A segment table maps a <segment-number, offset> pair to a physical address • Each table entry has: • A segment base containingthe starting physical address where the segment resides • A segment limit specifyingthe length of the segment

  11. Segment table (ii)

  12. Segment table (iii)

  13. Virtual memory (i) • Only part of a process needs to be loaded into memory for it to start its execution • Virtual memory further separates logical memory and physical memory • Logical (or virtual) address space can be larger than physical address space • Allows physical address space to be sharedby several processes • Enables quicker process creation

  14. Virtual memory (ii) • Unused pages are stored on disk

  15. Shared libraries • Multiple processes can share common libraries or data by mapping virtual pages to shared physicalpages • More efficientuse of physicalmemory space

  16. Demand paging • When a page of memory is requested, if it’s not in physical memory,load page from disk • i.e. on demand • Less I/O required • Less physical memory • Faster user responsetimes (usually) • More user processes

  17. Virtual memory policies • Virtual memory policies include: • The fetch policy governs when a pageshould be loaded into memory • The placement policy specifies where apage is loaded into physical memory • The replacement policy determines whichexisting page in memory should be replaced

  18. Page-to-process allocation • Page allocation: • In a static allocation scheme,the number of frames per process is fixed • In a dynamic allocation scheme,the number of frames per process varies • In an equal allocation scheme, all processeshave an equal number of frames • In a proportional allocation scheme, processesare allocated frames in proportion to size, priority, etc.

  19. Virtual memory page table • Associate a valid/invalid bit witheach page table entry • Initially set all entries to i • During address translation,if valid/invalid bit is v, pageis already in memory • Otherwise, if bit is i,a page fault occurs valid/invalid bit frame # v v v v i …. i i page table

  20. Page faults (i) • Page faults are trapped by the OS: • When an invalid reference occurs in the page table • When a page is not yet in the page table • Page fault recovery: • Get free frame from physical memory • Swap desired page into free frame • Reset page table entry • Set validation bit to v • Restart instruction that caused the page fault

  21. Page faults (ii) • Page faultsare costly!

  22. Page faults (iii)

  23. Demand paging performance (i) • The page fault rate p is in the range [0.0, 1.0]: • If p is 0.0, no page faults occur • If p is 1.0, every page request is a page fault • Typically p is very low.... • The effective memory-access time is • (1 – p) xphysical-memory-access +px ( page-fault-overhead +swap-page-out + swap-page-in +restart-overhead )

  24. Demand paging performance (ii) • Given: • Memory access time is 200 nanoseconds • Average page-fault service time is 8 milliseconds • The effective memory access time is • (1 – p) x 200ns + px 8ms = • 200ns – 200ns p + px 8,000,000ns = • 200ns + 7,999,800 p

  25. Thrashing (i) • If a process does not have enough pages, the page-fault rate is high, leading to thrashing • Process is busy swapping pagesin and out of memory • Low CPU utilization • Operating system might thinkit needs to increase the degreeof multiprogramming! • More processes added, further degrading performance

  26. Thrashing (ii) • Remember the Principle of Locality

  27. Principle of locality (i) • Future memory references in a given process will likely be local to previous memory references • This phenomenon is calledthe principle of locality • A process executes ina series of phases, spendinga finite amount of time performingmemory references in each phase

  28. Principle of locality (ii) • Example graph of page faults versus total number of allocated frames

  29. Principle of locality (iii) • Operating system should allocate enough frames for the current locality of a process: • What happens when too fewframes are allocated? • What happens whentoo many frames are allocated?

  30. Principle of locality (iv) • Example of asingle process:

  31. Principle of locality (v) • Dynamic page fault frequency scheme

  32. Page replacement • How do weidentify the victim?

  33. Page replacement algorithms • Page replacement algorithms include: • First-in-first-out (FIFO) • Optimal (OPT) • Least recently used (LRU) • Least frequently used (LFU) • Page fault frequency scheme (introduced earlier) • Working set apply these algorithms to apage reference stream

  34. First-in-first-out (FIFO) algorithm • The above is a 3-frame memory • How many page faults occur if we usea 4-frame memory instead?

  35. Belady’s anomaly (i) • Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 • How many page faults occur with a 3-frame memory? • How many page faults occur with a 4-frame memory?

  36. Belady’s anomaly (ii) • Belady’s Anomaly: • More frames may lead to more page faults!

  37. Optimal (OPT) algorithm • Replace pages that will not be used forthe longest amount of time FIFO: OPT:

  38. Least recently used (LRU) algorithm • Replace pages that have not been used forthe longest amount of time

  39. Least frequently used (LFU) algorithm • Similar to LRU, but replaceleast frequently used pages • Requires usage counts • Initial page replacements areswapped out quickly becausetheir usage counts are 1

  40. Working set algorithm • For each process, maintain a working set of pages referenced by the process during the most recent w page references • How do we choose w?

  41. Total demand of frames • Let d be the sum of the sizes of the working sets of all active processes • Let F be the total number of frames • If d < F, then the operating system can allow additional processes to enter the system • If d > F, then the operating system must suspend one or more active processes • Otherwise thrashing will occur!

  42. Windows XP example (i) • Windows XP uses demand paging with clustering (which loads pages surrounding the page fault) • Processes are assigned a working set minimum and a working set maximum • The working set minimum is the minimum number of pages a process is guaranteed to have in physical memory • Likewise, a process may be assigned pages up to its working set maximum

  43. Windows XP example (ii) • When the amount of free memory in the system falls below a threshold, automatic working set trimming is performed • Increases the amountof free memory • Removes pages fromprocesses that have pagesin excess of their workingset minimum

More Related