CS-3013 & CS-502 Summer 2006 Paging1 CS-3013 & CS-502 Summer 2006.

Slides:



Advertisements
Similar presentations
Paging 1 CS502 Spring 2006 Paging CS-502 Operating Systems.
Advertisements

OS Fall’02 Virtual Memory Operating Systems Fall 2002.
Segmentation and Paging Considerations
CS 153 Design of Operating Systems Spring 2015
CS 153 Design of Operating Systems Spring 2015
PagingCS-3013 A-term Paging CS-3013, Operating Systems A-term 2009 (Slides include materials from Modern Operating Systems, 3 rd ed., by Andrew Tanenbaum.
OS Spring ‘04 Paging and Virtual Memory Operating Systems Spring 2004.
Memory Management (II)
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management -3 CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent.
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Paging and Virtual Memory. Memory management: Review  Fixed partitioning, dynamic partitioning  Problems Internal/external fragmentation A process can.
Memory Management 2010.
Chapter 3.2 : Virtual Memory
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
1 Chapter 8 Virtual Memory Virtual memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Computer Organization and Architecture
PagingCS-3013 C-term Paging CS-3013 Operating Systems C-term 2008 (Slides include materials from Operating System Concepts, 7 th ed., by Silbershatz,
Silberschatz, Galvin and Gagne  Operating System Concepts Segmentation Memory-management scheme that supports user view of memory. A program.
Main Memory. Background Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
Review of Memory Management, Virtual Memory CS448.
Chapter 8 Memory Management Dr. Yingwu Zhu. Outline Background Basic Concepts Memory Allocation.
Computer Architecture Lecture 28 Fasih ur Rehman.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
Lecture 19: Virtual Memory
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
Lecture Topics: 11/17 Page tables TLBs Virtual memory flat page tables
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
© 2004, D. J. Foreman 1 Virtual Memory. © 2004, D. J. Foreman 2 Objectives  Avoid copy/restore entire address space  Avoid unusable holes in memory.
PagingCS-502 Fall Paging CS-502 Operating Systems Fall 2006 (Slides include materials from Operating System Concepts, 7 th ed., by Silbershatz, Galvin,
8.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Paging Physical address space of a process can be noncontiguous Avoids.
CS 149: Operating Systems March 3 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
IT 344: Operating Systems Winter 2008 Module 12 Page Table Management, TLBs, and Other Pragmatics Chia-Chi Teng CTB 265.
Memory Management Fundamentals Virtual Memory. Outline Introduction Motivation for virtual memory Paging – general concepts –Principle of locality, demand.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
1 Memory Management. 2 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k Internal fragmentation (cannot be reallocated) Divide memory into n (possible.
Caching Principles & Paging Performance CS-502 (EMC) Fall Caching Principles and Paging Performance CS-502, Operating Systems Fall 2009 (EMC) (Slides.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
Paging (continued) & Caching CS-3013 A-term Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
4.3 Virtual Memory. Virtual memory  Want to run programs (code+stack+data) larger than available memory.  Overlays programmer divides program into pieces.
PagingCS-502 (EMC) Fall Paging CS-502, Operating Systems Fall 2009 (EMC) (Slides include materials from Modern Operating Systems, 3 rd ed., by Andrew.
Page Table Implementation. Readings r Silbershatz et al:
Lectures 8 & 9 Virtual Memory - Paging & Segmentation System Design.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Virtual Memory Chapter 8.
Translation Lookaside Buffer
CS161 – Design and Architecture of Computer
CSE 120 Principles of Operating
CS703 - Advanced Operating Systems
EECE.4810/EECE.5730 Operating Systems
Computer Architecture
Translation Lookaside Buffer
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
CSE 451: Operating Systems Autumn 2005 Memory Management
CS-3013 Operating Systems Hugh C. Lauer
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Contents Memory types & memory hierarchy Virtual memory (VM)
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2004 Page Tables, TLBs, and Other Pragmatics Hank Levy 1.
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CS703 - Advanced Operating Systems
CSE 451: Operating Systems Winter 2005 Page Tables, TLBs, and Other Pragmatics Steve Gribble 1.
4.3 Virtual Memory.
CSE 542: Operating Systems
CS-3013 Operating Systems A-term 2008
Presentation transcript:

CS-3013 & CS-502 Summer 2006 Paging1 CS-3013 & CS-502 Summer 2006

Paging2 A different approach Addresses all of the issues of previous topic Introduces new issues of its own

CS-3013 & CS-502 Summer 2006 Paging3 Memory Management – Review Virtual (or logical) address vs. Physical addresses Memory Management Unit (MMU) –Set of registers and mechanisms to translate virtual addresses to physical addresses Processes (and CPU) see virtual addresses –Virtual address space is same for all processes, usually 0 based –Virtual spaces are protected from other processes MMU and devices see physical addresses CPU MMU MemoryI/O Devices Logical Addresses Physical Addresses

CS-3013 & CS-502 Summer 2006 Paging4 Solve fragmentation problems, internal and external Use fixed size units in both physical and virtual memory Provide sufficient MMU hardware to allow units to be scattered across memory Make it possible to leave infrequently used parts of virtual address space out of physical memory page X frame 0 frame 1 frame 2 frame Y physical memory … page 0 page 1 page 2 Logical Address Space (virtual memory) … page 3 MMU

CS-3013 & CS-502 Summer 2006 Paging5 Processes see a contiguous virtual address space Memory Manager divides the virtual address space into equal sized pieces called pages Memory Manager divides the physical address space into equal sized pieces called frames –Frame size usually a power of 2 between 512 and 8192 bytes –Frame table One entry per frame of physical memory State –Free –Allocated – process(es) sizeof(page) = sizeof(frame)

CS-3013 & CS-502 Summer 2006 Paging6 Paging – Address Translation Translating virtual addresses –a virtual address has two parts: virtual page number & offset –virtual page number (VPN) is index into a page table –page table entry contains page frame number (PFN) –physical address is: startof(PFN) + offset Page tables –Supported by MMU hardware –Managed by the Memory Manager –Map virtual page numbers to page frame numbers one page table entry (PTE) per page in virtual address space i.e., one PTE per VPN

CS-3013 & CS-502 Summer 2006 Paging7 Paging Translation page frame 0 page frame 1 page frame 2 page frame Y … page frame 3 physical memory offset physical address F(PFN)page frame # page table offset logical address virtual page #

CS-3013 & CS-502 Summer 2006 Paging8 Page Translation Example Assume a 32-bit address space –Assume page size 4KB (log 2 (4096) = 12 bits) –For a process to address the full logical address space Need 2 20 PTEs – VPN is 20 bits Offset is 12 bits Translation of virtual address 0x –Offset is 0x678 –Assume PTE(12345) contains 0x01000 –Physical address is 0x

CS-3013 & CS-502 Summer 2006 Paging9 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 when 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, etc. Page frame number (PFN) determines the physical page –physical page start address Other bits dependent upon machine architecture page frame numberprotMRV

CS-3013 & CS-502 Summer 2006 Paging10 Paging – Advantages Easy to allocate physical memory pick any free frame No external fragmentation All frames are equal Limited internal fragmentation Bounded by page/frame size Easy to swap out pages (called pageout) Size is usually a multiple of disk blocks PTE contains info that helps reduce disk traffic Processes can run with not all pages swapped in

CS-3013 & CS-502 Summer 2006 Paging11 Definition — Page Fault A trap when a process attempts to reference a virtual address of a page not in physical memory Valid bit in PTE is set to false If page exists on disk:– Suspend process If necessary, throw out some other page (update its PTE) Swap in desired page, resume execution If page does not exist on disk:– Return program error or Conjure up a new page and resume execution –E.g., for growing the stack!

CS-3013 & CS-502 Summer 2006 Paging12 Paging Observations Recurring themes in paging –Temporal Locality – locations referenced recently tend to be referenced again soon –Spatial Locality – locations near recent references tend to be referenced soon Definitions –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

CS-3013 & CS-502 Summer 2006 Paging13 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 –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

CS-3013 & CS-502 Summer 2006 Paging14 Issue #1: Page Table Size Process Virtual Address spaces –Not usually full – don’t need every PTE –Processes do exhibit locality – only need a subset of the PTEs Two-level page tables Virtual Addresses have 3 parts –Master page number – points to secondary page table –Secondary page number – points to PTE containing page frame # –Offset Physical Address = offset + startof (PFN) Note: Master page number can be used as Segment # –previous topic n-level page tables are possible, but rare in 32-bit systems

CS-3013 & CS-502 Summer 2006 Paging15 Two-level page tables page frame 0 page frame 1 page frame 2 page frame Y … page frame 3 physical memory offset physical address page frame # master page table secondary page# virtual address master page #offset secondary page table # secondary page table # addr page frame number

CS-3013 & CS-502 Summer 2006 Paging16 Two-level page tables page frame 0 page frame 1 page frame 2 page frame Y … page frame 3 physical memory offset physical address page frame # master page table secondary page# virtual address master page #offset secondary page table # secondary page table # addr page frame number 12 bits 8 bits

CS-3013 & CS-502 Summer 2006 Paging17 Multilevel Page Tables Sparse Virtual Address space – very few secondary PTs ever needed Process Locality – only a few secondary PTs needed at one time Can page out secondary PTs that are not needed now –Don’t page Master Page Table –Save physical memory However Performance is worse –Now have 3 memory access per virtual memory reference or instruction fetch How do we get back to about 1 memory access per VA reference? –Problem #2 of “Paging Issues” slide

CS-3013 & CS-502 Summer 2006 Paging18 Paging Issues Minor issue – internal fragmentation –Memory allocation in units of pages (also file allocation!) #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 –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, requires multiple memory accesses and a lot of work per logical address

CS-3013 & CS-502 Summer 2006 Paging19 Associative Memory (aka Dynamic Address Translation) Do fast hardware search of all entries in parallel for VPN If present, use page frame number (PFN) directly If not, a)Look up in page table (multiple accesses) b)Load VPN and PFN into Associative Memory (throwing out another entry as needed) VPN #Frame #

CS-3013 & CS-502 Summer 2006 Paging20 Translation Lookaside Buffer (TLB) Associative memory implementation in hardware –Translates VPN to PTE (containing PFN) –Done in single machine cycle TLB is hardware assist –Fully associative – all entries searched in parallel with VPN as index –Returns PFN –MMU use PFN and offset to get Physical Address Locality makes TLBs work –Usually have 8–1024 TLB entries –Sufficient to deliver 99%+ hit rate (in most cases) Works well with multi-level page tables

CS-3013 & CS-502 Summer 2006 Paging21 MMU with TLB

CS-3013 & CS-502 Summer 2006 Paging22 Typical Machine Architecture CPU Bridge Memory Graphics I/O device MMU and TLB live here

CS-3013 & CS-502 Summer 2006 Paging23 TLB-related Policies OS must ensure that TLB and page tables are consistent –When OS changes bits (e.g. protection) in PTE, it must invalidate TLB copy –If dirty bit is set in TLB, write back to page table entry TLB replacement policies –Random –Least Recently Used (LRU) – with hardware help What happens on context switch? –Each process has own page tables (multi-level) –Must invalidate all TLB entries –Then TLB fills as new process executes –Expensive context switches just got more expensive! Note benefit of Threads

CS-3013 & CS-502 Summer 2006 Paging24 Alternative Page Table format – Hashed Common in address spaces > 32 bits. The virtual page number is hashed into a page table. This page table contains a chain of VPNs hashing to the same value. Virtual page numbers are compared in this chain searching for a match. If a match is found, the corresponding physical frame is extracted Still uses TLB for execution

CS-3013 & CS-502 Summer 2006 Paging25 Hashed Page Tables

CS-3013 & CS-502 Summer 2006 Paging26 Alternative Page Table format – Inverted One entry for each real page of memory. Entry consists of virtual address of page stored at that real memory location, with information about the process that owns that page. Decreases memory needed to store each page table, but increases time needed to search the table when a page reference occurs. Use hash table to limit the search to one or a few page-table entries. Still uses TLB to speed up execution

CS-3013 & CS-502 Summer 2006 Paging27 Inverted Page Table Architecture

CS-3013 & CS-502 Summer 2006 Paging28 Paging – Some Tricks Shared Memory –Part of virtual memory of two or more processes map to same frames Finer grained sharing than segments Data sharing with Read/Write Shared libraries with eXecute –Each process has own PTEs – different privileges Copy-on-write (COW) – e.g. on fork() –Don’t copy all pages – create shared mapping of parent pages in child Make shared pages read-only in child When child does write, a protection fault occurs OS copies the page and resumes client

CS-3013 & CS-502 Summer 2006 Paging29 Paging – More Tricks Memory-mapped files –Instead of standard system calls ( read(), write(), etc.) map file starting at virtual address X I.e., use the file for swap space for that part of VM –Access to “X + n” refers to file at offset n –All mapped file PTEs marked at start as invalid –OS reads from file on first access –OS writes to file when page is dirty and page is evicted

CS-3013 & CS-502 Summer 2006 Paging30 Paging – Summary Partition virtual memory into equal size units called pages Any page can fit into any frame in physical memory No relocation needed by loader Only active pages in memory at any time Supports very large virtual memories and segmentation Hardware assistance is essential An instance of the fundamental principle of caching

CS-3013 & CS-502 Summer 2006 Paging31 Caching The act of keeping a small subset of active items 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

CS-3013 & CS-502 Summer 2006 Paging32 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 …

CS-3013 & CS-502 Summer 2006 Paging33 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 …

CS-3013 & CS-502 Summer 2006 Paging34 Summary OS Organization Linking and Loading Memory Management issues Paging

CS-3013 & CS-502 Summer 2006 Paging35 Homework Assignment Read (for next week) –Dijkstra, E. W., “The Structure of the ‘THE’- Multiprogramming System,” Communications of ACM, vol.11, pp , May (.pdf).pdf –Tanenbaum, §§4.1 – 4.3 Programming Project #2 (two weeks)