operating systems { week 13/14}

Download Operating Systems { week  13/14}

Post on 05-Jan-2016




6 download

Embed Size (px)


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 - PowerPoint PPT Presentation


Chapter 1: Information Technology

Operating Systems{week 13/14}Rensselaer Polytechnic InstituteCSCI-4210 Operating SystemsDavid Goldschmidt, Ph.D.Noncontiguous allocation (i)A noncontiguous memory allocation scheme avoids the external fragmentation problemSlice 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 framesNote that frame size equals page size

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 main memoryprocess Pi== in use== freePaging via a page table

Page tables map logical memoryaddresses to physical memoryaddressesAddress translationCovers a logical addressspace of size 2m withpage size 2n

page numberpage offsetpd(m n)(n)Address translation

Translation look-aside buffer

Use page tablecaching at thehardware levelto speed addresstranslation

Hardware-leveltranslation look-aside buffer(TLB)

Segmentation (i)Segmentation is a memory-management scheme that correspondsto logical segments of auser programA segment resides in acontiguous block of memorySegments are numberedand referred to by a pairSegmentation (ii)Logical segments map to physical memory


Segment table (i)A segment table maps a pair to a physical address

Each table entry has:A segment base containingthe starting physical address where the segment residesA segment limit specifyingthe length of the segmentSegment table (ii)

Segment table (iii)

Virtual memory (i)Only part of a process needs to be loaded into memory for it to start its executionVirtual memory further separates logical memory and physical memoryLogical (or virtual) address space can be larger than physical address spaceAllows physical address space to be sharedby several processesEnables quicker process creationVirtual memory (ii)Unused pages are stored on disk

Shared librariesMultiple processes can share common libraries or data by mapping virtual pages to shared physicalpagesMore efficientuse of physicalmemory space

Demand pagingWhen a page of memory is requested, if its not in physical memory,load page from diski.e. on demand Less I/O requiredLess physical memoryFaster user responsetimes (usually)More user processesVirtual memory policiesVirtual memory policies include:The fetch policy governs when a pageshould be loaded into memoryThe placement policy specifies where apage is loaded into physical memoryThe replacement policy determines whichexisting page in memory should be replacedPage-to-process allocationPage allocation:In a static allocation scheme,the number of frames per process is fixedIn a dynamic allocation scheme,the number of frames per process variesIn an equal allocation scheme, all processeshave an equal number of framesIn a proportional allocation scheme, processesare allocated frames in proportion to size, priority, etc.Virtual memory page tableAssociate a valid/invalid bit witheach page table entryInitially set all entries to i During address translation,if valid/invalid bit is v, pageis already in memoryOtherwise, if bit is i,a page fault occursvvvviii.frame #valid/invalid bitpage tablePage faults (i)Page faults are trapped by the OS:When an invalid reference occurs in the page tableWhen a page is not yet in the page table

Page fault recovery:Get free frame from physical memorySwap desired page into free frame Reset page table entrySet validation bit to v Restart instruction that caused the page faultPage faults (ii)Page faultsare costly!

Page faults (iii)

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 occurIf p is 1.0, every page request is a page faultTypically p is very low....

The effective memory-access time is(1 p) x physical-memory-access + p x ( page-fault-overhead + swap-page-out + swap-page-in + restart-overhead )Demand paging performance (ii)Given:Memory access time is 200 nanosecondsAverage page-fault service time is 8 milliseconds

The effective memory access time is(1 p) x 200ns + p x 8ms =200ns 200ns p + p x 8,000,000ns =200ns + 7,999,800 p 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 memoryLow CPU utilizationOperating system might thinkit needs to increase the degreeof multiprogramming!More processes added, further degrading performance

Thrashing (ii)Remember the Principle of Locality

Principle of locality (i)Future memory references in a given process will likely be local to previous memory referencesThis phenomenon is calledthe principle of locality A process executes ina series of phases, spendinga finite amount of time performingmemory references in each phasePrinciple of locality (ii)Example graph of page faults versus total number of allocated frames

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?Principle of locality (iv)Example of asingle process:

Principle of locality (v)Dynamic page fault frequency scheme

Page replacementHow do weidentify the victim?Page replacement algorithmsPage 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 streamFirst-in-first-out (FIFO) algorithmThe above is a 3-frame memoryHow many page faults occur if we usea 4-frame memory instead?

Beladys anomaly (i)Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5How many page faults occur with a 3-frame memory?

How many page faults occur with a 4-frame memory?Beladys anomaly (ii)Beladys Anomaly:More frames may lead to more page faults!

Optimal (OPT) algorithmReplace pages that will not be used forthe longest amount of timeFIFO:OPT:

Least recently used (LRU) algorithmReplace pages that have not been used forthe longest amount of time

Least frequently used (LFU) algorithmSimilar to LRU, but replaceleast frequently used pagesRequires usage countsInitial page replacements areswapped out quickly becausetheir usage counts are 1

Working set algorithmFor each process, maintain a working set of pages referenced by the process during the most recent w page references

How do we choose w?

Total demand of framesLet d be the sum of the sizes of the working sets of all active processes

Let F be the total number of framesIf d < F, then the operating system can allow additional processes to enter the systemIf d > F, then the operating system must suspend one or more active processesOtherwise thrashing will occur!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 memoryLikewise, a process may be assigned pages up to its working set maximumWindows XP example (ii)When the amount of free memory in the system falls below a threshold, automatic working set trimming is performedIncreases the amountof free memoryRemoves pages fromprocesses that have pagesin excess of their workingset minimum