Paging. Memory Partitioning Troubles Fragmentation Need for compaction/swapping A process size is limited by the available physical memory Dynamic growth.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: Memory Management
Operating Systems Lecture 10 Issues in Paging and Virtual Memory Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing.
G Robert Grimm New York University Virtual Memory.
OS Fall’02 Virtual Memory Operating Systems Fall 2002.
CS 153 Design of Operating Systems Spring 2015
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
OS Spring ‘04 Paging and Virtual Memory Operating Systems Spring 2004.
CS 333 Introduction to Operating Systems Class 11 – Virtual Memory (1)
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
Memory Management (II)
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management -3 CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent.
CS 333 Introduction to Operating Systems Class 11 – Virtual Memory (1)
Paging and Virtual Memory. Memory management: Review  Fixed partitioning, dynamic partitioning  Problems Internal/external fragmentation A process can.
Chapter 3.2 : Virtual Memory
Translation Buffers (TLB’s)
Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001.
Virtual Memory and Paging J. Nelson Amaral. Large Data Sets Size of address space: – 32-bit machines: 2 32 = 4 GB – 64-bit machines: 2 64 = a huge number.
Memory Management April 28, 2000 Instructor: Gary Kimura.
Chapter 91 Translation Lookaside Buffer (described later with virtual memory) Frame.
Mem. Hier. CSE 471 Aut 011 Evolution in Memory Management Techniques In early days, single program run on the whole machine –Used all the memory available.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
COMPSYS 304 Computer Architecture Memory Management Units Reefed down - heading for Great Barrier Island.
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
CS333 Intro to Operating Systems Jonathan Walpole.
Lecture 21 Last lecture Today’s lecture Cache Memory Virtual memory
Review of Memory Management, Virtual Memory CS448.
Dynamic Partition Allocation Allocate memory depending on requirements Partitions adjust depending on memory size Requires relocatable code –Works best.
Computer Architecture Memory Management Units Iolanthe II - Reefed down, heading for Great Barrier Island.
Cosc 2150: Computer Organization Chapter 6, Part 2 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.
IT253: Computer Organization
Operating Systems COMP 4850/CISG 5550 Page Tables TLBs Inverted Page Tables Dr. James Money.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
8.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Paging Physical address space of a process can be noncontiguous Avoids.
Chapter 4 Memory Management Virtual Memory.
Memory Management Fundamentals Virtual Memory. Outline Introduction Motivation for virtual memory Paging – general concepts –Principle of locality, demand.
CS399 New Beginnings Jonathan Walpole. Virtual Memory (1)
Virtual Memory 1 1.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
4.3 Virtual Memory. Virtual memory  Want to run programs (code+stack+data) larger than available memory.  Overlays programmer divides program into pieces.
1  2004 Morgan Kaufmann Publishers Chapter Seven Memory Hierarchy-3 by Patterson.
CHAPTER 3-3: PAGE MAPPING MEMORY MANAGEMENT. VIRTUAL MEMORY Key Idea Disassociate addresses referenced in a running process from addresses available in.
Lectures 8 & 9 Virtual Memory - Paging & Segmentation System Design.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Translation Lookaside Buffer
Memory Management Virtual Memory.
Paging.
Non Contiguous Memory Allocation
Memory Caches & TLB Virtual Memory
Lecture Topics: 11/19 Paging Page tables Memory protection, validation
Page Table Implementation
CS510 Operating System Foundations
Lecture 28: Virtual Memory-Address Translation
CSCI206 - Computer Organization & Programming
Evolution in Memory Management Techniques
Computer Architecture
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CS703 - Advanced Operating Systems
Translation Buffers (TLBs)
Review What are the advantages/disadvantages of pages versus segments?
4.3 Virtual Memory.
CSE 542: Operating Systems
Virtual Memory 1 1.
Presentation transcript:

Paging

Memory Partitioning Troubles Fragmentation Need for compaction/swapping A process size is limited by the available physical memory Dynamic growth of partition is troublesome No winning policy on allocation/deallocation P2 P3

The Basic Problem A process needs a contiguous partition(s) But Contiguity is difficult to manage Contiguity mandates the use of physical memory addressing (so far)

The Basic Solution Give illusion of a contiguous address space The actual allocation need not be contiguous Use a Memory Management Unit (MMU) to translate from the illusion to reality

A solution: Virtual Addresses Use n-bit to represent virtual or logical addresses A process perceives an address space extending from address 0 to 2 n -1 MMU translates from virtual addresses to real ones Processes no longer see real or physical addresses

Paged Memory Subdivide the address space (both virtual and physical) to “pages” of equal size Use MMU to map from virtual pages to physical ones Physical pages are called frames

Paging: Example 00 Virtual Physical Process 0 Process 1

Key Facts Virtual address spaces of different processes are independent –Two or more may have the same address range –Yet the mappings differentiate between them A virtual page has no storage of its own –It must be backed by a physical frame (real page) that provides the actual storage –A contiguous virtual space need not be physically contiguous

Key Facts Physical address space is independent of virtual address spaces –They can have different sizes –Allows process size to be independent of available physical memory size Page size is always a power of 2, to simplify hardware addressing

Page Tables 0 Virtual Page Table

Page Table Structure Indexed by virtual page number Contains frame number (if any) Contains protection bits Contains reference bit Frame No.vwrxf vwrxf vwrxf v: valid bit w: write bit r: read bit x: execute bit (rare) f: reference bit m: modified bit m m m

Mapping Virtual to Real Addresses Virtual address n bits virtual page numberoffset index into page table frame no.offset Physical address p bits s bits s: log (page size)

Example: PDP-11 Virtual address 16 bits vpnoffset frame no.offset Physical address 22 bits 13 bits Page size: 8K Up to 4M mem 8-entry page table (in hardware)

Weird Stuff: Free Page Management Virtual Physical Process 0Process 1 Key fact: A memory frame cannot be accessed unless mapped Free space

Fun Stuff: Sharing 00 Virtual Physical Process 0 Process 1

Sharing Processes can share pages by mapping their virtual pages to the same memory frame In UNIX and Windows, code segments of processes running the same program to share the pages containing executables –saves a lot of memory –saves loading time for frequently run programs Fine tuning using protection bits (rwx)

Fork Revisited: Copy-on-Write Virtual Physical FatherChild W W W W W W

Copy-on-Write Fork Initially no memory copying –Efficient –If an exec follows, no much harm Page tables set the protection to disallow writes If either father or child attempts to write, a page fault occurs

Copy-on-Write Virtual Physical FatherChild W W W W W W

Requirements for Sharing Page frames must have a reference count –Cannot be deallocated unless unmapped –Adds complexity to memory manager Protection bits must be set properly

Page Table Implementation

Page Table Implementations Key issues: Each instruction requires one or more memory accesses: –Mapping must be done very quickly Where do we store the page table? –It is now part of the context, with implications on context switching Hardware must support auxiliary bits

PDP-11 Example Revisited Page table is small (8 entries) –Can be implemented in hardware –Moderate effect on context switching time Each process will need an 8-entry array in its PCB to store page table when not running Protections works fine But: what if address space is 32-bit

Page Table Size Problems Assume 16K page size and 32-bit address space Then: For each process, there are 2 19 virtual pages Page table size: 2 19 * 4 bytes/entry –Page table requires 2 Mbytes –Cannot be stored in hardware, slowing down the mapping from virtual to physical addressing

Solution1: Multi-Level Page Tables Use two or three levels page tables All entries in the topmost level must be there Entries in lower levels are there only if needed Store page tables in memory Have one CPU register contain address of top-most level table

Example: SPARC Context table (up to 4K registers) 3-level page table offsetindex 1index 2index 3 Context Level 1 Level 2 Page Level 3

SPARC: Cont’d Only level 1 table need be there entirely –256 entries * 4 bytes/entry = 1K /process Context switching is not affected –Just save and restore the context register/process Second and third level tables are there only if necessary

Translation Lookaside Buffer A small associative memory in processor Contains recent mapping results Typically 8 to 32 entries If access is localized, works very well Must be flushed on context switching If TLB misses, then must resolve through page tables in main memory (slow)

Other Varieties 2-level page table in VAX systems 4-level page table in the 68030/68040 Organize the cache memory by virtual addresses (instead of physical addresses) –Remove the TLB from critical path –Combine cache misses with address translations –e.g. MIPS 3000/4000

Solution 2: Inverted Page Tables Rationale: Conventional per-process page tables depend on virtual memory size Virtual address space is getting larger (e.g. 64 bits) Size of physical memory projected is less than virtual memory in foreseeable future

Inverted Page Table Main Idea: Global page table indexed by frame number Each entry contains virtual address & pid Use TLB to reduce the need to access PT On a TLB miss: –Search page table for the –Physical address is obtained from the index of the entry (frame number)

Inverted Page Table Structure Indexed by frame number Entry contains virtual address and pid using the frame number (if any) Contains protection & reference Virtual addrvwrxf vwrxf vwrxf v: valid bit w: write bit r: read bit x: execute bit (rare) f: reference bit m: modified bit m m m Virtual addr pid

Mapping Virtual to Real Addresses Virtual address n bits virtual page numberoffset + pid: search key into inverted page table frame no.offset Physical address p bits s bits

Properties & Problems Table size is independent of virtual address size, only function of physical memory size TLB misses are expensive –We don’t know where to look –May require searching entire table (very bad) Virtual memory more expensive Sharing becomes very difficult

A Solution Organize Inverted Page Table as a hash table –Search key –Search in hardware or software Examples: IBM 38, RS/6000, HP PA-RISC systems

Sharing & Inverted Page Tables Conceivably possible with a general hashing function Requires an additional field in page table entry Virtual addrvwrxf vwrxf vwrxf m m m pid Frame no. Size no longer limited, so no system implements it