Competing For MemoryMechanicsThe Big PictureLessons From Enhanced FIFOx86 Page Table EntryProgram BehaviorsObservations re Working SetWorking SetWSClock Paging AlgorithmSimulating Modify Bit with Access BitsImplementing LRU without Reference BitDemand PagingSpeed and SluggishnessMemory PressureDisk AddressImagine a Global LRUSource of Disk AccessPartitioning MemoryFile Access EfficiencyResult: Memory-Mapped FilesLazy Versus EagerSemantics: How Things BehaveBeing Too Smart…Amdahl’s LawNT x86 Virtual Address Space LayoutsVirtual Address Space in Win95 and Win98Details with VM ManagementPage States (NT)Dynamics in NT VMShared MemoryCopy-On-WriteIssues of Copy-On-WriteCompeting For MemoryVivek Pai / Kai LiPrinceton University2MechanicsFeedback optionally anonymousNo real retribution anywayDo it to make me happyQuiz 1 Question 2 answer(s)#regs != #bitsRegisters at top of memory hierarchyLots of acceptable answersLast Quiz, Feedback still being digested3The Big PictureWe’ve talked about single evictionsMost computers are multiprogrammedSingle eviction decision still neededNew concern – allocating resourcesHow to be “fair enough” and achieve good overall throughputThis is a competitive world – local and global resource allocation decisions4Lessons From Enhanced FIFOObservationsit’s easier to evict a clean page than a dirty pagesometimes the disk and CPU are idleOptimization: when system’s “free”, write dirty pages back to disk, but don’t evictCalled flushing – often falls to pager daemon5x86 Page Table EntryValidWritableOwner (user/kernel)Write-throughCache disabledAccessed (referenced)DirtyPDE maps 4MBGlobalPage frame number DLGlCwPU A Cd Wt O W VReserved31126Program Behaviors80/20 rule> 80% memory references are made by < 20% of codeLocalitySpatial and temporalWorking setKeep a set of pages in memory would avoid a lot of page faults # pages in memory# page faultsWorking set7Observations re Working SetWorking set isn’t staticThere often isn’t a single “working set”Multiple plateaus in previous curveProgram coding style affects working setWorking set is hard to gaugeWhat’s the working set of an interactive program?8Working SetMain ideaKeep the working set in memory An algorithmOn a page fault, scan through all pages of the processIf the reference bit is 1, record the current time for the pageIf the reference bit is 0, check the “last use time”If the page has not been used within , replace the pageOtherwise, go to the nextAdd the faulting page to the working set9WSClock Paging AlgorithmFollow the clock handIf the reference bit is 1, set reference bit to 0, set the current time for the page and go to the nextIf the reference bit is 0, check “last use time”If page has been used within , go to the nextIf page hasn’t been used within and modify bit is 1Schedule the page for page out and go to the nextIf page hasn’t been used within and modified bit is 0Replace this page10Simulating Modify Bit with Access BitsSet pages read-only if they are read-writeUse a reserved bit to remember if the page is really read-onlyOn a read faultIf it is not really read-only, then record a modify in the data structure and change it to read-writeRestart the instruction11Implementing LRU without Reference BitSome machines have no reference bitVAX, for exampleUse the valid bit or access bit to simulateInvalidate all valid bits (even they are valid)Use a reserved bit to remember if a page is really validOn a page faultIf it is a valid reference, set the valid bit and place the page in the LRU listIf it is a invalid reference, do the page replacementRestart the faulting instruction12Demand PagingPure demand paging relies only on faults to bring in pagesProblems?Possibly lots of faults at startupIgnores spatial localityRemediesLoading groups of pages per faultPrefetching/preloadingSo why use it?13Speed and SluggishnessSlow is > .1 seconds (100 ms)Speedy is << .1 secondsMonitors tend to be 60+ Hz =<16.7ms between screen paintsDisks have seek + rotational delaySeek is somewhere between 7-16 msAt 7200rpm, one rotation = 1/120 sec = 8ms. Half-rotation is 4msConclusion? One disk access OK, six are bad14Memory Pressure“Swap” spaceRegion of disk used to hold “overflow”Contains only data pages (stack/heap/globals). Why?Swap may exist as “regular file,” but dedicated region of disk more common15Disk AddressUse physical memory as a cache for diskWhere to find a page on a page fault?PPage# field is a disk addressObservation: OS knows that pages are real but not in memoryVirtualaddressspaceinvalidPhysicalmemory16Imagine a Global LRUGlobal – across all processesIdea – when a page is needed, pick the oldest page in the systemProblems? Process mixes?Interactive processesActive large-memory sweep processesMitigating damage?17Source of Disk AccessVM SystemMain memory caches - full image on diskFilesystemEven here, caching very usefulNew competitive pressure/decisionsHow do we allocate memory to these two?How do we know we’re right?18Partitioning MemoryOriginally, specified by administrator20% used as filesystem cache by defaultOn fileservers, admin would set to 80%Each subsystem owned pages, replaced themObservation: they’re all basically pagesWhy not let them compete?Result: unified memory systems – file/VM19File Access Efficiencyread(fd, buf, size)Buffer in process’s memoryData exists in two places – filesystem cache & process’s memoryKnown as “double buffering”Various scenariosMany processes read same fileProcess wants only parts of a file, but doesn’t know which parts in advance20Result: Memory-Mapped FilesFileProcess AFileProcess BFileProcess CMapProcess AMapProcess BMapProcess CFile21Lazy Versus EagerEager: do things right awayread(fd, buf, size) – returns # bytes readBytes must be read before read completesWhat happens if size is big?Lazy: do them as they’re neededmmap(…) – returns pointer to mappingMapping must exist before mmap completesWhen/how are bytes read?What happens if size is big?22Semantics: How Things BehaveWhat happens whenTwo process obtain data (read
View Full Document