VIRTUAL MEMORY. Operating Systems 2015 Spring by Euiseong Seo

Similar documents
Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Virtual Memory I. Jo, Heeseung

Memory Management. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Recap: Memory Management

Memory Management Topics. CS 537 Lecture 11 Memory. Virtualizing Resources

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS 153 Design of Operating Systems Winter 2016

CS153: Memory Management 1

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

CSE 120 Principles of Operating Systems Spring 2017

CS 153 Design of Operating Systems Winter 2016

CSE 120 Principles of Operating Systems

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Goals of memory management

Page Tables. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS 318 Principles of Operating Systems

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

Virtual Memory 1. To do. q Segmentation q Paging q A hybrid system

Lecture 8: Memory Management

Virtual Memory. Today. Segmentation Paging A good, if common example

VIRTUAL MEMORY II. Jo, Heeseung

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management

CS 153 Design of Operating Systems Spring 18

Lecture 12: Demand Paging

Memory Management. Goals of Memory Management. Mechanism. Policies

Reminder: Mechanics of address translation. Paged virtual memory. Reminder: Page Table Entries (PTEs) Demand paging. Page faults

Chapter 8. Virtual Memory

Goals of Memory Management

CS162 - Operating Systems and Systems Programming. Address Translation => Paging"

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

CS5460: Operating Systems Lecture 14: Memory Management (Chapter 8)

Virtual Memory. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

MEMORY: SWAPPING. Shivaram Venkataraman CS 537, Spring 2019

Multi-Process Systems: Memory (2) Memory & paging structures: free frames. Memory & paging structures. Physical memory

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

Memory Management - Demand Paging and Multi-level Page Tables

CS399 New Beginnings. Jonathan Walpole

CS252 S05. Main memory management. Memory hardware. The scale of things. Memory hardware (cont.) Bottleneck

MEMORY MANAGEMENT/1 CS 409, FALL 2013

How to create a process? What does process look like?

Chapter 9 Memory Management Main Memory Operating system concepts. Sixth Edition. Silberschatz, Galvin, and Gagne 8.1

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

Computer Architecture. Lecture 8: Virtual Memory

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

Processes and Virtual Memory Concepts

CS 153 Design of Operating Systems Winter 2016

The memory of a program. Paging and Virtual Memory. Swapping. Paging. Physical to logical address mapping. Memory management: Review

Chapter 8: Main Memory

Another View of the Memory Hierarchy. Lecture #25 Virtual Memory I Memory Hierarchy Requirements. Memory Hierarchy Requirements

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Basic Memory Management

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access)

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

CSC 369 Operating Systems

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Chapter 8: Memory-Management Strategies

CSE 451: Operating Systems Winter Page Table Management, TLBs and Other Pragmatics. Gary Kimura

Recall from Tuesday. Our solution to fragmentation is to split up a process s address space into smaller chunks. Physical Memory OS.

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

CS 550 Operating Systems Spring Memory Management: Paging

Computer Systems. Virtual Memory. Han, Hwansoo

CHAPTER 8: MEMORY MANAGEMENT. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Opera&ng Systems ECE344

Address spaces and memory management

Chapter 8: Main Memory. Operating System Concepts 9 th Edition

Virtual Memory. Chapter 8

Outline. V Computer Systems Organization II (Honors) (Introductory Operating Systems) Advantages of Multi-level Page Tables

virtual memory. March 23, Levels in Memory Hierarchy. DRAM vs. SRAM as a Cache. Page 1. Motivation #1: DRAM a Cache for Disk

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

CS162 Operating Systems and Systems Programming Lecture 12. Address Translation. Page 1

Virtual to physical address translation

Virtual Memory Virtual memory first used to relive programmers from the burden of managing overlays.

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

The Virtual Memory Abstraction. Memory Management. Address spaces: Physical and Virtual. Address Translation

Chapter 8: Main Memory

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

Operating Systems. Operating Systems Sina Meraji U of T

Introduction to Operating Systems

Memory management, part 3: outline

2-Level Page Tables. Virtual Address Space: 2 32 bytes. Offset or Displacement field in VA: 12 bits

Memory Hierarchy. Goal: Fast, unlimited storage at a reasonable cost per bit.

CPS104 Computer Organization and Programming Lecture 16: Virtual Memory. Robert Wagner

CS370: Operating Systems [Spring 2016] Dept. Of Computer Science, Colorado State University

UC Berkeley CS61C : Machine Structures

Operating Systems CSE 410, Spring Virtual Memory. Stephen Wagner Michigan State University

LECTURE 12. Virtual Memory

Memory Management Cache Base and Limit Registers base limit Binding of Instructions and Data to Memory Compile time absolute code Load time

MEMORY MANAGEMENT. Jo, Heeseung

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

Topics: Memory Management (SGG, Chapter 08) 8.1, 8.2, 8.3, 8.5, 8.6 CS 3733 Operating Systems

Introduction to Virtual Memory Management

Part Three - Memory Management. Chapter 8: Memory-Management Strategies

Main Memory CHAPTER. Exercises. 7.9 Explain the difference between internal and external fragmentation. Answer:

Virtual Memory. control structures and hardware support

CSE 120 Principles of Operating Systems

Transcription:

VIRTUAL MEMORY Operating Systems 2015 Spring by Euiseong Seo

Today s Topics Virtual memory implementation Paging Segmentation

Paging Permits the physical address space of a process to be noncontiguous Divide physical memory into fixed-sized blocks called frames Divide logical memory into blocks of same size called pages Page (or frame) size is power of 2 (typically, 512B 8KB) To run a program of size n pages, need to find n free frames and load program OS keeps track of all free frames Set up a page table to translate virtual to physical addresses

Paging Physical memory Process B Virtual memory Page 3 Page 2 Frame 11 Frame 10 Frame 9 Page 1 Frame 8 Process A Page 0 Page 5 Page 4 Page tables Frame 7 Frame 6 Frame 5 Frame 4 Page 3 Frame 3 Page 2 Frame 2 Page 1 Frame 1 Page 0 Frame 0

Paging User s perspective Users (and processes) view memory as one contiguous address space from 0 through N n Virtual address space (VAS) In reality, pages are scattered throughout the physical memory n Virtual-to-physical mapping n This mapping is invisible to the program Protection is provided because a program cannot reference memory outside of its VAS n The virtual address 0xdeadcafe maps to different physical addresses for different processes.

Virtual Addresses Translating addresses virtual page number p m - n page offset VPN is an index into a page table d n Page table determines page frame number (PFN) Physical address is <PFN::offset> Page tables Managed by OS Map VPN to PFN n VPN is the index into the table that determines PFN One page table entry (PTE) per page in virtual address space, i.e. one PTE per VPN

Address Translation

Address Translation

Paging Example Paging example Virtual address: 32 bits Physical address: 20 bits Page size: 4KB Offset: 12 bits VPN: 20 bits 0 Virtual address (32bits) 0 0 0 4 A F E VPN 2 7 D 0 3 1 F E 4 6 Page tables Offset Page table entries: 2 20 A 4 PFN 4 6 A F E Physical address (20bits)

Protection Memory protection is implemented by associating protection bit with each frame Valid / Invalid bit Valid indicates that the associated page is in the process virtual address space, and is thus a legal page Invalid indicates that the page is not in the process virtual address space Finer level of protection is possible for valid pages n Provide read-only, read-write, or execute-only protection

Page Table Entries (PTEs) 1 1 1 2 20 V R M Prot Page Frame Number (PFN) Valid bit (V) says whether or not the PTE can be used It is checked each time a virtual address is used Reference bit (R) says whether the page has been accessed It is set when a read or write to the page occurs Modify bit (M) says whether or not the page is dirty It is set when a write to the page occurs Protection bits (Prot) control which operations are allowed on the page Read, Write, Execute, etc. Page frame number (PFN) determines physical page

Advantages of Paging Easy to allocate physical memory Physical memory is allocated from free list of frames To allocate a frame, just remove it from its free list No external fragmentation Easy to page out chunks of a program All chunks are the same size (page size) Use valid bit to detect reference to paged-out pages Pages sizes are usually chosen to be convenient multiple of disk block sizes Easy to protect pages from illegal accesses Easy to share pages

Disadvantages of Paging Can still have internal fragmentation Process may not use memory in exact multiple of pages Memory reference overhead 2 references per address lookup (page table, then memory) Solution: get a hardware support (TLB) Memory required to hold page tables can be large Need one PTE per page in virtual address space 32-bit address space with 4KB pages = 2 20 PTEs 4 bytes/pte = 4MB per page table OS s typically have separate page tables per process (25 processes = 100MB of page tables) Solution: page the page tables, multi-level page tables, inverted page tables, etc.

Demand Paging Bring a page into memory only when it is needed Less I/O needed Less memory needed Faster response More users OS uses main memory as a (page) cache of all of the data allocated by processes in the system Initially, pages are allocated from physical memory frames When physical memory fills up, allocating a page requires some other page to be evicted from its physical memory frame Evicted pages go to disk (only need to write if they are dirty) To a swap file Movement of pages between memory/disks is done by the OS Transparent to the application

Page Faults What happens to a process that references a virtual address in a page that has been evicted? When the page was evicted, the OS sets the PTE as invalid and stores (in PTE) the location of the page in the swap file When a process accesses the page, the invalid PTE will cause an exception to be thrown The OS will run the page fault handler in response Handler uses invalid PTE to locate page in swap file Handler reads page into a physical frame, updates PTE to point to it and to be valid Handler restarts the faulted process Where does the page that s read in go? Have to evict something else (page replacement algorithm) OS typically tries to keep a pool of free pages around so that allocations don t inevitably cause evictions

Page Fault Handling

Rationale Behind Demand Paging Locality Temporal locality: locations referenced recently tend to be referenced again soon Spatial locality: locations near recently referenced locations are likely to be referenced soon Locality means paging can be infrequent Once you ve paged something in, it will be used many times On average, you use things that are paged in But this depends on many things n Degree of locality in application n Page replacement policy n Amount of physical memory n Application s reference pattern and memory footprint

Basic Flow of Demand Paging When a process first starts up, it has a brand new page table, with all PTE valid bits false No pages are yet mapped to physical memory When the process starts executing Instructions immediately fault on both code and data pages Faults stop when all necessary code/data pages are in memory Only the code/data that is needed (demanded!!) by process needs to be loaded What is needed changes over time, of course

Segmentation Segmentation is a technique that partitions memory into logically related data units Code, stack, heap, etc. Users view memory as a collection of variable-sized segments, with no necessary ordering among them Virtual address: <Segment #::Offset> Different segments can grow or shrink independently, without affecting each other Natural extension of variable-sized partitions Variable-size partitions: 1 segment / process Segmentation: many segments / process

User s View of a Program

User s View of a Program

Segmentation Hardware support Multiple base/limit pairs, one per segment (segment table) Segments are named by segment #, used to index into table Segment table Physical memory limit base Segment# offset Virtual address Yes <? No protecnon fault +

Advantages of Segmentation Advantages Simplifies the handling of data structures that are growing or shrinking Easy to protect segments n With each entry in segment table, associate a valid bit n Protection bits (read/write/execute) are also associated with each segment table entry Easy to share segments n Put same translation into base/limit pair n Code/data sharing occurs at segment level n e.g. shared libraries

Disadvantages of Segmentation Cross-segment addresses Segments need to have same segment # for pointers to them to be shared among processes Otherwise, use indirect addressing only Large segment tables Keep in main memory, use hardware cache for speed External fragmentation Since segments vary in length, memory allocation is a dynamic storage-allocation problem

Paging vs. Segmentation Paging Segmenta3on Block size Fixed (4KB to 64KB) Variable Linear address space 1 Many Memory addressing Replacement One word (page number + offset) Easy (all same size) Two words (segment + offset) Difficult (find where segment fits) FragmentaNon Internal External Disk traffic Transparent to the programmers? Efficient (opnmized for page size) Yes Inefficient (may have small or large transfers) No

Paging vs. Segmentation Can the total address space exceed the size of physical memory? Can codes and data be disnnguished and separately protected? Can tables whose size fluctuates be accommodated easily? Is sharing of codes between users facilitated? Why was this technique invented? Paging Yes No No No To get a large linear address space without having to buy more physical memory Segmenta3on Yes Yes Yes Yes To allow programs and data to be broken up into logically independent address spaces and to aid sharing and protecnon

Paging vs. Segmentation Hybrid approaches Paged segments n Segmentation with Paging n Segments are a multiple of a page size Multiple page sizes n 4KB, 2MB, and 4MB page sizes are supported in IA32. n 8KB, 16KB, 32KB or 64KB in Alpha AXP Architecture. (43, 47, 51, or 55 bits virtual address)

Segmentation with Paging Combine segmentation and paging Use segments to manage logically related units n Code, data, heap, etc. n Segments vary in size, but usually large (multiple pages) Use pages to partition segments into fixed size chunks n Makes segments easier to manage with in physical memory n Segments become pageable rather than moving segments into and out of memory, just move page portions of segments n Need to allocate page table entries only for those pieces of the segments that have themselves been allocated n No external fragmentation The IA-32 supports segments and paging

Segmentation with Paging IA-32