Presentation is loading. Please wait.

Presentation is loading. Please wait.

Paging (continued) & Caching CS-3013 A-term 20081 Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.

Similar presentations


Presentation on theme: "Paging (continued) & Caching CS-3013 A-term 20081 Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern."— Presentation transcript:

1 Paging (continued) & Caching CS-3013 A-term 20081 Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern Operating Systems, 3 rd ed., by Andrew Tanenbaum and from Operating System Concepts, 7 th ed., by Silbershatz, Galvin, & Gagne)

2 Paging (continued) & Caching CS-3013 A-term 20082 Review – Paging Partition virtual memory into small fixed size units called pages Typically 512-8192 bytes Translate every memory address on-the-fly from virtual to physical address Allow process to execute, even if not all pages are in physical memory

3 Paging (continued) & Caching CS-3013 A-term 20083 Definition — Page Fault Trap when process attempts to reference a location in virtual memory whose virtual address cannot be translated I.e., valid bit in PTE set to false I.e., reference violates protection bits in PTE OS takes appropriate action, restarts process at point of fault

4 Paging (continued) & Caching CS-3013 A-term 20084 PTE Structure Valid bit gives state of this PTE –says whether or not a virtual address is valid – in memory and VA range –If not set, page might not be in memory or may not even exist! Reference bit says whether the page has been accessed –it is set by hardware whenever a page has been read or written to Modify bit says whether or not the page is dirty –it is set by hardware during every write to the page Protection bits control which operations are allowed –read, write, execute, etc. Page frame number (PFN) determines the physical page –physical page start address Other bits dependent upon machine architecture page frame numberprotMRV 202111

5 Paging (continued) & Caching CS-3013 A-term 20085 Paging – Advantages Easy to allocate physical memory pick any free frame No external fragmentation All frames are equal Minimal internal fragmentation Bounded by page/frame size Easy to swap out pages (called pageout) Size is usually a multiple of disk blocks PTEs may contain info that help reduce disk traffic Processes can run with not all pages swapped in

6 Paging (continued) & Caching CS-3013 A-term 20086 Definitions & Recurring Themes Temporal Locality – locations referenced recently tend to be referenced again soon Spatial Locality – locations near recent references tend to be referenced soon Working set – the set of pages that a process needs to run without frequent page faults Thrashing – excessive page faulting due to insufficient frames to support working set

7 Paging (continued) & Caching CS-3013 A-term 20087 Paging Issues #1 — Page Tables can consume large amounts of space –If PTE is 4 bytes, and use 4KB pages, and have 32 bit VA space  4MB for each process’s page table Stored in main memory! –What happens for 64-bit logical address spaces? #2 — Performance Impact –Converting virtual to physical address requires multiple operations to access memory Read Page Table Entry from memory! Get page frame number Construct physical address Assorted protection and valid checks –Without fast hardware support, requires multiple memory accesses and a lot of work per logical address

8 Paging (continued) & Caching CS-3013 A-term 20088 Paging Issues #1 — Page Tables can consume large amounts of space –If PTE is 4 bytes, and use 4KB pages, and have 32 bit VA space  4MB for each process’s page table Stored in main memory! –What happens for 64-bit logical address spaces? #2 — Performance Impact –Converting virtual to physical address requires multiple operations to access memory Read Page Table Entry from memory! Get page frame number Construct physical address Assorted protection and valid checks –Without fast hardware support, requires multiple memory accesses and a lot of work per logical address Two-level or inverted page tables Translation Lookaside Buffer (TLB)

9 Paging (continued) & Caching CS-3013 A-term 20089 Paging Tricks Shared Virtual Memory Pages of two or more processes point to same page frames E.g. shared libraries Copy-on-write Processes share virtual memory Writable pages marked read-only On page fault, make separate writable copies

10 Paging (continued) & Caching CS-3013 A-term 200810 Definition — Backing Storage A place on external storage medium where copies of virtual pages are kept Usually a hard disk (locally or on a server) Place from which contents of pages are read after page faults Place where contents of pages are written if page frames need to be re-allocated

11 Paging (continued) & Caching CS-3013 A-term 200811 Backing Storage Executable code and constants:– The loadable image file produced by compiler Working memory (stack, heap, static data) Special swapping file (or partition) on disk Persistent application data Application data files on local or server disks

12 Paging (continued) & Caching CS-3013 A-term 200812 Definition — Mapping Mapping (a part of) virtual memory to a file = Connecting blocks of the file to the virtual memory pages so that –Page faults in (that part of) virtual memory resolve to the blocks of the file –Dirty pages in (that part of) virtual memory are written back to the blocks of the file

13 Paging (continued) & Caching CS-3013 A-term 200813 Warning — Memory-mapped Files Tempting idea:– –Instead of standard I/O calls ( read(), write(), etc.) map file starting at virtual address X –Access to “X + n” refers to file at offset n –Use paging mechanism to read file blocks into physical memory on demand … –… and write them out as needed Has been tried many times Rarely works very well in practice

14 Paging (continued) & Caching CS-3013 A-term 200814 Warning — Memory-mapped Files Tempting idea:– –Instead of standard I/O calls ( read(), write(), etc.) map file starting at virtual address X –Access to “X + n” refers to file at offset n –Use paging mechanism to read file blocks into physical memory on demand … –… and write them out as needed Has been tried many times Rarely works well in practice Hard to program; even Harder to manage performance

15 Paging (continued) & Caching CS-3013 A-term 200815 Virtual Memory Organization 0x00000000 0xFFFFFFFF Virtual address space program code (text) static data heap (dynamically allocated) stack (dynamically allocated) PC SP From an earlier topic

16 Paging (continued) & Caching CS-3013 A-term 200816 Virtual Memory Organization program code & constants static data heap (dynamically allocated) stack (dynamically allocated) PC SP Mapped to read-only executable file Map to writable swap file Unmapped, may be dynamically mapped guard page (never mapped)

17 Paging (continued) & Caching CS-3013 A-term 200817 thread 3 stack Virtual Memory Organization (continued) program code & constants static data heap thread 1 stack PC (T2) SP (T2) thread 2 stack SP (T1) SP (T3) PC (T3) guard page (never mapped) guard page Mapped to read-only executable file Map to writable swap file Unmapped, may be dynamically mapped Map to writable swap file

18 Paging (continued) & Caching CS-3013 A-term 200818 Virtual Memory Organization (continued) Each area of process VM is its own segment (or sequence of segments) Executable code & constants – fixed size Shared libraries Static data – fixed size Heap – open-ended Stacks – each open-ended Other segments as needed –E.g., symbol tables, loader information, etc.

19 Paging (continued) & Caching CS-3013 A-term 200819 Virtual Memory – a Major OS Abstraction Processes execute in virtual memory, not physical memory Virtual memory may be very large Much larger than physical memory Virtual memory may be organized in interesting & useful ways Open-ended segments Virtual memory is where the action is! Physical memory is just a cache of virtual memory

20 Paging (continued) & Caching CS-3013 A-term 200820 Reading Assignment Tanenbaum –§§ 3.1-3.2 (previous topic – Memory Management) –§ 3.3 (this topic on Paging)

21 Paging (continued) & Caching CS-3013 A-term 200821 Related topic – Caching

22 Paging (continued) & Caching CS-3013 A-term 200822 Definition — Cache A small subset of active items held in fast storage while most of the items are in much larger, slower storage –Virtual Memory Very large, mostly stored on (slow) disk Small working set in (fast) RAM during execution –Page tables Very large, mostly stored in (slow) RAM Small working set stored in (fast) TLB registers

23 Paging (continued) & Caching CS-3013 A-term 200823 Caching is Ubiquitous in Computing Transaction processing Keep records of today’s departures in RAM while records of future flights are on disk Program execution Keep the bytes near the current program counter in on-chip memory while rest of program is in RAM File management Keep disk maps of open files in RAM while retaining maps of all files on disk Game design Keep nearby environment in cache of each character …

24 Paging (continued) & Caching CS-3013 A-term 200824 Caching issues When to put something in the cache What to throw out to create cache space for new items How to keep cached item and stored item in sync after one or the other is updated How to keep multiple caches in sync across processors or machines Size of cache needed to be effective Size of cache items for efficiency …

25 Paging (continued) & Caching CS-3013 A-term 200825 Caching issues When to put something in the cache What to throw out to create cache space for new items How to keep cached item and stored item in sync after one or the other is updated How to keep multiple caches in sync across processors or machines Size of cache needed to be effective Size of cache items for efficiency … This is a very important list!

26 Paging (continued) & Caching CS-3013 A-term 200826 Questions?


Download ppt "Paging (continued) & Caching CS-3013 A-term 20081 Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern."

Similar presentations


Ads by Google