Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating Systems Unit 8: – Virtual Memory management Operating Systems.

Similar presentations


Presentation on theme: "Operating Systems Unit 8: – Virtual Memory management Operating Systems."— Presentation transcript:

1 Operating Systems Unit 8: – Virtual Memory management Operating Systems

2 COP 5994 - Operating Systems2 Introduction: virtual memory management page management strategies: –fetch –placement –replacement

3 COP 5994 - Operating Systems3 Basic concept: Locality Process tends to reference memory in highly localized patterns –referenced pages tend to be adjacent to one another in process’s virtual address space

4 COP 5994 - Operating Systems4 Fetch Strategy: Demand Paging when process starts page with first instruction is loaded after that, only page that are being referenced is loaded process accumulates pages one at a time

5 COP 5994 - Operating Systems5 Demand Paging waiting process occupies memory

6 COP 5994 - Operating Systems6 Fetch Strategy: Anticipatory Paging attempt to predict the pages a process will need and preloads these pages when memory space is available must be carefully designed so that overhead incurred by the strategy does not reduce system performance

7 COP 5994 - Operating Systems7 Page Replacement on page fault: –find referenced page in secondary storage –load page into page frame –update page table entry what about page being replaced ? –modified (dirty) bit indication –page must be written back to secondary storage optimal strategy: –replaces the page that will not be referenced again until furthest into the future

8 COP 5994 - Operating Systems8 Page Replacement Strategies characterized by –heuristic it uses to select a page for replacement –overhead it incurs overview of strategies: –Random –FIFO –LRU –LFU –NUR –Second chance & clock page –Far page

9 COP 5994 - Operating Systems9 Random Page Replacement low-overhead no discrimination against particular processes each page has an equal likelihood but: –could easily select as the next page to replace the page that will be referenced next –rarely used

10 COP 5994 - Operating Systems10 First-In-First-Out (FIFO) Page Replacement Replace oldest page –Likely to replace heavily used pages –relatively low overhead: simple queue –Impractical for most systems

11 COP 5994 - Operating Systems11 Belady’s Anomaly page fault increases when number of page frames allocated to a process is increased

12 COP 5994 - Operating Systems12 Least-Recently-Used (LRU) Page Replacement Heuristic –temporal locality –replace page that has not been used recently but: –increased system overhead list of pages used, update for every page use –poor performance in certain situations: large loop

13 COP 5994 - Operating Systems13 Least-Frequently-Used (LFU) Page Replacement Heuristic: –keep pages that are being used –replaces page that is least intensively referenced but: –implementation overhead counter for each page ? –page with highest counter stays in memory, even if it is never used again

14 COP 5994 - Operating Systems14 Not-Used-Recently (NUR) Page Replacement Heuristic: –goal: approximate LRU with less overhead –uses 2 indicator bits per page: referenced bit modified bit –bits are reset periodically –order for page replacement un-referenced page un-modified page supported in hardware on modern systems

15 COP 5994 - Operating Systems15 FIFO Variation: Second-Chance Replacement Examines referenced bit of the oldest page If off: page is replaced If on: –turns off the bit –moves the page to tail of FIFO queue –keeps active pages in memory

16 COP 5994 - Operating Systems16 FIFO Variation: Clock Page Replacement Heuristic: –uses circular list instead of FIFO queue –marker for oldest page Examines referenced bit of the oldest page If off: page is replaced If on: –turns off the bit –advances marker in circular list

17 COP 5994 - Operating Systems17 Far Page Replacement Heuristic: –based on page access pattern of process –track page references –replace page that is far away from referenced pages

18 COP 5994 - Operating Systems18 Far Page Replacement: access graph

19 COP 5994 - Operating Systems19 Far Page Replacement Performs at near-optimal levels but: –access graph needs to be computed –access graph is complex to search and manage without hardware support

20 COP 5994 - Operating Systems20 Working Set Model For a program to run efficiently –The system must maintain that program’s favored subset of pages in main memory Heuristic: –consider locality of page references –keep “local” pages of process in memory

21 COP 5994 - Operating Systems21 Example of page reference pattern

22 COP 5994 - Operating Systems22 Effect of memory allocation to page fault

23 COP 5994 - Operating Systems23 Concept: Working Set of process

24 COP 5994 - Operating Systems24 Working Set Window size vs. program size

25 COP 5994 - Operating Systems25 Working-Set-based page replacement strategy keep pages of working set in main memory But: –working set size changes –working set changes transition period yields ineffective memory use –overhead for working set management

26 COP 5994 - Operating Systems26 Page-Fault-Frequency (PFF) Page Replacement Goal: improve working set approach Adjusts a process’s resident page set –Based on frequency at which the process is faulting –Based on time between page faults, called the process’s interfault time

27 COP 5994 - Operating Systems27 Program Behavior under Paging

28 COP 5994 - Operating Systems28 PFF Advantage Lower overhead –PFF adjusts resident page set only after each page fault –Working set management must run after each memory reference

29 COP 5994 - Operating Systems29 Page Release Problem: inactive pages may remain in main memory Solution: explicit voluntary page release need compiler and operating system support

30 COP 5994 - Operating Systems30 Page Size Small page sizes –Reduce internal fragmentation –Can reduce the amount of memory required to contain a process’s working set –More memory available to other processes Large page size –Reduce wasted memory from table fragmentation –Enable each TLB entry to map larger region of memory, improving performance –Reduce number of I/O operations the system performs to load a process’s working set into memory

31 COP 5994 - Operating Systems31 Page Size: internal fragmentation

32 COP 5994 - Operating Systems32 Page Size examples Multiple page size Possibility of external fragmentation

33 COP 5994 - Operating Systems33 Global vs. Local Page Replacement Global: applied to all processes as a unit –ignore characteristics of individual process behavior –Global LRU (gLRU) page-replacement strategy Replaces the least-recently-used page in entire system Especially bad if used with RR scheduler –SEQ (sequence) global page-replacement strategy Uses LRU strategy to replace pages until sequence of page faults to contiguous pages is detected, at which point it uses most-recently-used (MRU) page-replacement strategy Local: Consider each process individually –adjusts memory allocation according to relative importance of each process to improve performance

34 COP 5994 - Operating Systems34 Example: Linux Memory Management supports 32- and 64-bit addresses, and Non-Uniform Memory Access pure page paging approach –single page size –Three levels of page tables Page global directory Page middle directory Page tables uses “virtual memory area” concept for protection management

35 COP 5994 - Operating Systems35 Linux Page Table Organization

36 COP 5994 - Operating Systems36 Memory Zones

37 COP 5994 - Operating Systems37 Physical Memory Allocation binary buddy algorithm for zone

38 COP 5994 - Operating Systems38 Linux Page Replacement only user pages can be replaced uses page cache modified FIFO page replacement: –Two linked lists per zone Active list contains pages that have been referenced recently Inactive list contains pages that have been used less recently

39 COP 5994 - Operating Systems39 Linux Page Replacement

40 COP 5994 - Operating Systems40 Linux kernel swap daemon Periodically frees page frames by flushing dirty pages to disk Swaps out pages from the tail of the inactive list –considers: page sharing page locking

41 COP 5994 - Operating Systems41 Windows Memory Management Virtual memory manager (VMM) –Executive component responsible for managing memory Lazy allocation –Avoid allocating memory until necessary Prefetching –Move pages from disk to main memory before they are needed

42 COP 5994 - Operating Systems42 Memory Organization Paged pool –VMM can move pages to pagefile Nonpaged pool, limited size –VMM never moves pages to pagefile –Used for Device driver code VMM code Interrupt handler code –Code in nonpaged pool may not access paged pool

43 COP 5994 - Operating Systems43 Windows Memory Organization 2-level hierarchical memory map –Page directory table Page directory entries (PDEs) point to page table One page directory table per process Location in page directory register –Page table Page table entries (PTEs) point to page frames also: “Large Page” is several pages

44 COP 5994 - Operating Systems44 Windows Memory Organization

45 COP 5994 - Operating Systems45 Windows Memory Organization PTE can point to data in pagefile –4 bits determine which pagefile –20 bits indicate offset in pagefile PTE has protection bits –Read, Write, Execute –Copy-on-write processes can share page frames transparently –Raise exception on access

46 COP 5994 - Operating Systems46 Windows Page Prefetching Logical Prefetcher –Responsible for prefetching Records all memory access during –Windows boot time –Application start up Next time prefetch needed pages Usually done during device initialization Faster start up

47 COP 5994 - Operating Systems47 Windows Page Replacement Working set –Pages a process currently has in main memory Balance set manager –Responsible for trimming working sets Localized Least Recently Used –Similar to LRU –Localized by process

48 COP 5994 - Operating Systems48 Agenda for next week: –Chapter 12: Disk Performance Optimization –Read ahead !


Download ppt "Operating Systems Unit 8: – Virtual Memory management Operating Systems."

Similar presentations


Ads by Google