CS 153 Design of Operating Systems Spring 2015

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 36 Virtual Memory Read.
Paging 1 CS502 Spring 2006 Paging CS-502 Operating Systems.
Operating Systems ECE344 Ding Yuan Final Review Lecture 13: Final Review.
CS 153 Design of Operating Systems Spring 2015
Memory Management Design & Implementation Segmentation Chapter 4.
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Memory Management 2010.
Chapter 3.2 : Virtual Memory
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Memory ManagementCS-502 Fall Memory Management CS-502 Operating Systems Fall 2006 (Slides include materials from Operating System Concepts, 7 th.
Computer Organization and Architecture
Memory Management CSE451 Andrew Whitaker. Big Picture Up till now, we’ve focused on how multiple programs share the CPU Now: how do multiple programs.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
CSE451 Operating Systems Winter 2012 Memory Management Mark Zbikowski Gary Kimura.
CS 153 Design of Operating Systems Spring 2015 Final Review.
Operating Systems Chapter 8
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Operating System Main Memory.
Operating Systems ECE344 Ding Yuan Memory Management Lecture 7: Memory Management.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
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.
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
CSE 451: Operating Systems Fall 2010 Module 10 Memory Management Adapted from slides by Chia-Chi Teng.
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.
Paging (continued) & Caching CS-3013 A-term Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
CSE 451: Operating Systems Winter 2015 Module 11 Memory Management Mark Zbikowski Allen Center 476 © 2013 Gribble, Lazowska, Levy,
Memory Management Continued Questions answered in this lecture: What is paging? How can segmentation and paging be combined? How can one speed up address.
Virtual Memory Pranav Shah CS147 - Sin Min Lee. Concept of Virtual Memory Purpose of Virtual Memory - to use hard disk as an extension of RAM. Personal.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
Memory Management Chapter 5 Advanced Operating System.
CS703 - Advanced Operating Systems By Mr. Farhan Zaidi.
Non Contiguous Memory Allocation
CSE 120 Principles of Operating
CSE 451: Operating Systems Winter 2007 Module 10 Memory Management
CS703 - Advanced Operating Systems
Paging COMP 755.
CSE451 Operating Systems Winter 2011
CSE 451: Operating Systems Winter 2010 Module 10 Memory Management
CSE 451: Operating Systems Winter 2014 Module 11 Memory Management
Chapter 8: Main Memory.
Lecture 28: Virtual Memory-Address Translation
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Computer Architecture
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Operating System Main Memory
Lecture 3: Main Memory.
CSE 451: Operating Systems Autumn 2005 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2004 Memory Management
Contents Memory types & memory hierarchy Virtual memory (VM)
CSE 451: Operating Systems Winter 2007 Module 10 Memory Management
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CS444/CS544 Operating Systems
CSE 451: Operating Systems Autumn 2009 Module 10 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Memory Management CSE451 Andrew Whitaker.
CSE 451: Operating Systems Winter 2004 Module 10 Memory Management
Paging and Segmentation
CS703 - Advanced Operating Systems
CSE451 Operating Systems Winter 2009
COMP755 Advanced Operating Systems
Operating Systems: Internals and Design Principles, 6/E
CSE 451: Operating Systems Autumn 2010 Module 10 Memory Management
Presentation transcript:

CS 153 Design of Operating Systems Spring 2015 Lecture 15: Memory Management

Announcements Get started on project 2 ASAP Please ask questions if unclear REMINDER: 4% for class participation Come to office hours

OS Abstractions Applications Process Virtual memory File system Operating System CPU Hardware RAM Disk

Memory Management Next few lectures are going to cover memory management Goals of memory management To provide a convenient abstraction for programming To allocate scarce memory resources among competing processes to maximize performance with minimal overhead Mechanisms Physical and virtual addressing Techniques: partitioning, paging, segmentation Page table management, TLBs, VM tricks Policies Page replacement algorithms

Lecture Overview Virtual memory Survey techniques for implementing virtual memory Fixed and variable partitioning Paging Segmentation Focus on hardware support and lookup procedure Next lecture we’ll go into sharing, protection, efficient implementations, and other VM tricks and features

Need for Virtual Memory Rewind to the days of “second-generation” computers Programs use physical addresses directly OS loads job, runs it, unloads it Multiprogramming changes all of this Want multiple processes in memory at once Overlap I/O and CPU of multiple jobs How to share physical memory across multiple processes? Many programs do not need all of their code and data at once (or ever) – no need to allocate memory for it A program can run on machine with less memory than it “needs”

Virtual Addresses To make it easier to manage the memory of processes running in the system, we’re going to make them use virtual addresses (logical addresses) Virtual addresses are independent of the actual physical location of the data referenced OS determines location of data in physical memory Instructions executed by the CPU issue virtual addresses Virtual addresses are translated by hardware into physical addresses (with help from OS) The set of virtual addresses that can be used by a process comprises its virtual address space

Virtual Addresses Many ways to do this translation… Requirements physical addresses physical memory processor vmap Many ways to do this translation… Need hardware support and OS management algorithms Requirements Need protection – restrict which addresses jobs can use Fast translation – lookups need to be fast Fast change – updating memory hardware on context switch

First Try: Fixed Partitions Physical memory is broken up into fixed partitions Size of each partition is the same and fixed Hardware requirements: base register Physical address = virtual address + base register Base register loaded by OS when it switches to a process (part of PCB) Physical Memory P1 P2 P3 P4 P5

First Try: Fixed Partitions Physical Memory Base Register P1 P4’s Base P2 P3 Virtual Address Offset + P4 P5 How do we provide protection?

First Try: Fixed Partitions Advantages Easy to implement Need base register Verify that offset is less than fixed partition size Fast context switch Problems? Internal fragmentation: memory in a partition not used by a process is not available to other processes Partition size: one size does not fit all (very large processes?)

Second Try: Variable Partitions Natural extension – physical memory is broken up into variable sized partitions Hardware requirements: base register and limit register Physical address = virtual address + base register Why do we need the limit register? Protection: if (virtual address > limit) then fault

Second Try: Variable Partitions Base Register P1 P3’s Base Limit Register P2 P3’s Limit Virtual Address Yes? Offset < + P3 No? Protection Fault

Variable Partitions Advantages Problems? No internal fragmentation: allocate just enough for process Problems? External fragmentation: job loading and unloading produces empty holes scattered throughout memory P1 P2 P3 P4

State-of-the-Art: Paging Paging solves the external fragmentation problem by using fixed sized units in both physical and virtual memory Physical Memory Virtual Memory Page 1 Page 2 Page 3 Page N

Process Perspective Processes view memory as one contiguous address space from 0 through N (N = 2^32 on 32-bit arch.) Virtual address space (VAS) In reality, pages are scattered throughout physical memory The mapping is invisible to the program Protection is provided because a program cannot reference memory outside of its VAS The address “0x1000” maps to different physical addresses in different processes

Paging Translating addresses Page tables Virtual address has two parts: virtual page number and offset Virtual page number (VPN) is an index into a page table Page table determines page frame number (PFN) Physical address is PFN::offset Page tables Map virtual page number (VPN) to page frame number (PFN) VPN is the index into the table that determines PFN One page table entry (PTE) per page in virtual address space Or, one PTE per VPN

Page Lookups Base Addr Physical Memory Virtual Address Page number Offset Physical Address Page Table Page frame Offset Page frame Base Addr Register storing page table addr

Page out (the cold pages) What if we run short on physical memory? Well, we transfer a page worth of physical memory to disks Physical Memory Virtual Memory In-use Page 1 Page 2 Disk In-use Page 3 In-use Page N In-use

Virtual Memory of Process 1 Virtual Memory of Process 2 Page out What if we run short on physical memory? Well, we transfer a page worth of physical memory to disks Physical Memory Virtual Memory of Process 1 Virtual Memory of Process 2 In-use 2 Page 1 Page 1 In-use 2 Page 2 Page 2 Disk In-use 1 Page 3 Page 3 In-use 1 In-use 2 Page N Page N In-use 1

Virtual Memory of Process 1 Paging question Can we serve a process asking for more memory than we physically have? Virtual Memory of Process 1 Physical Memory Page 1 Page 2 Page 3 Page N

Paging Example Pages are 4KB Virtual address is 0x7468 Offset is 12 bits (because 4KB = 212 bytes) VPN is 20 bits (32 bits is the length of every virtual address) Virtual address is 0x7468 Virtual page is 0x7, offset is 0x468 Page table entry 0x7 contains 0x2000 Page frame number is 0x2000 Seventh virtual page is at address 0x2000 (2nd physical page) Physical address = 0x2000 + 0x468 = 0x2468

Page Table Entries (PTEs) 1 1 1 2 20 M R V Prot Page Frame Number Page table entries control mapping The Modify bit says whether or not the page has been written It is set when a write to the page occurs The Reference bit says whether the page has been accessed It is set when a read or write to the page occurs The Valid bit says whether or not the PTE can be used It is checked each time the virtual address is used (Why?) The Protection bits say what operations are allowed on page Read, write, execute (Why do we need these?) The page frame number (PFN) determines physical page

Paging Advantages Easy to allocate memory Memory comes from a free list of fixed size chunks Allocating a page is just removing it from the list External fragmentation not a problem All pages of the same size Easy to swap out chunks of a program All chunks are the same size Use valid bit to detect references to swapped pages Pages are a convenient multiple of the disk block size 4KB vs. 512 bytes

Paging Limitations Can still have internal fragmentation Process may not use memory in multiples of a page Memory reference overhead 2 references per address lookup (page table, then memory) Solution – use a hardware cache of lookups (more later) Memory required to hold page table can be significant Need one PTE per page 32 bit address space w/ 4KB pages = 220 PTEs 4 bytes/PTE = 4MB/page table 25 processes = 100MB just for page tables! Solution – page the page tables (more later)

Summary Virtual memory Various techniques Processes use virtual addresses OS + hardware translates virtual address into physical addresses Various techniques Fixed partitions – easy to use, but internal fragmentation Variable partitions – more efficient, but external fragmentation Paging – use small, fixed size chunks, efficient for OS

Next time… Read chapters 8 and 9 in either textbook