Lecture 11 Page 1 CS 111 Online Memory Management: Paging and Virtual Memory CS 111 On-Line MS Program Operating Systems Peter Reiher.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Memory Management Questions answered in this lecture: How do processes share memory? What is static relocation? What is dynamic relocation? What is segmentation?
CS 311 – Lecture 21 Outline Memory management in UNIX
CS 153 Design of Operating Systems Spring 2015
CS 153 Design of Operating Systems Spring 2015
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Multiprocessing Memory Management
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.
A. Frank - P. Weisberg Operating Systems Simple/Basic Paging.
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.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, Operating System Concepts Operating Systems Lecture 24 Paging.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Review of Memory Management, Virtual Memory CS448.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Operating Systems Chapter 8
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
IT253: Computer Organization
Lecture Topics: 11/17 Page tables TLBs Virtual memory flat page tables
Memory Management – Page 1 of 49CSCI 4717 – Computer Architecture Memory Management Uni-program – memory split into two parts –One for Operating System.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui COMP 203 / NWEN 201 Computer Organisation / Computer Architectures Virtual.
CE Operating Systems Lecture 14 Memory management.
CS 149: Operating Systems March 3 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Operating Systems Lecture 14 Segments Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software Engineering.
1 Memory Management. 2 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k Internal fragmentation (cannot be reallocated) Divide memory into n (possible.
ICOM Noack Memory management Virtual memory Paging and segmentation Demand paging Memory management hardware.
Lecture 11 Page 1 CS 111 Fall 2015 Memory Management: Virtual Memory and Paging CS 111 Operating Systems Peter Reiher.
Lecture 11 Page 1 CS 111 Spring 2015 Memory Management: Virtual Memory and Paging CS 111 Operating Systems Peter Reiher.
Virtual Memory From course notes University of Waikato. Some material by Tony McGregor Other material from: The Architecture.
OS Memory Addressing. Architecture CPU – Processing units – Caches – Interrupt controllers – MMU Memory Interconnect North bridge South bridge PCI, etc.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
Memory Management Chapter 5 Advanced Operating System.
Lecture 4 Page 1 CS 111 Online Modularity and Memory Clearly, programs must have access to memory We need abstractions that give them the required access.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 33 Paging Read Ch. 9.4.
Lecture 13 Page 1 CS 111 Winter 2014 Memory Management: Virtual Memory and Paging CS 111 Operating Systems Peter Reiher.
Basic Paging (1) logical address space of a process can be made noncontiguous; process is allocated physical memory whenever the latter is available. Divide.
Memory Management.
Non Contiguous Memory Allocation
CS161 – Design and Architecture of Computer
CSE 120 Principles of Operating
CS703 - Advanced Operating Systems
Outline Paging Swapping and demand paging Virtual memory.
COMBINED PAGING AND SEGMENTATION
Chapter 8: Main Memory.
Lecture 28: Virtual Memory-Address Translation
CSCI206 - Computer Organization & Programming
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Main Memory Background Swapping Contiguous Allocation Paging
CS399 New Beginnings Jonathan Walpole.
Virtual Memory Hardware
Lecture 3: Main Memory.
So far in memory management…
CSE 451: Operating Systems Autumn 2005 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
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
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Page Main Memory.
Presentation transcript:

Lecture 11 Page 1 CS 111 Online Memory Management: Paging and Virtual Memory CS 111 On-Line MS Program Operating Systems Peter Reiher

Lecture 11 Page 2 CS 111 Online Outline Paging Swapping and demand paging Virtual memory

Lecture 11 Page 3 CS 111 Online Paging What is paging? – What problem does it solve? – How does it do so? Paged address translation Paging and fragmentation Paging memory management units Paging and segmentation

Lecture 11 Page 4 CS 111 Online Segmentation Revisited Segment relocation solved the relocation problem for us It used base registers to compute a physical address from a virtual address – Allowing us to move data around in physical memory – By only updating the base register It did nothing about external fragmentation – Because segments are still required to be contiguous We need to eliminate the “contiguity requirement”

Lecture 11 Page 5 CS 111 Online The Paging Approach Divide physical memory into units of a single fixed size – A pretty small one, like 1-4K bytes or words – Typically called a page frame Treat the virtual address space in the same way For each virtual address space page, store its data in one physical address page frame Use some magic per-page translation mechanism to convert virtual to physical pages

Lecture 11 Page 6 CS 111 Online Paged Address Translation CODEDATASTACK process virtual address space physical memory

Lecture 11 Page 7 CS 111 Online Paging and Fragmentation A segment is implemented as a set of virtual pages Internal fragmentation − Averages only ½ page (half of the last one) External fragmentation − Completely non-existent − We never carve up pages

Lecture 11 Page 8 CS 111 Online How Does This Compare To Segment Fragmentation? Consider this scenario: – Average requested allocation is 128K – 256K fixed size segments available – In the paging system, 4K pages For segmentation, average internal fragmentation is 50% (128K of 256K used) For paging? – Only the last page of an allocation is not full – On average, half of it is unused, or 2K – So 2K of 128K is wasted, or around 1.5% Segmentation: 50% waste Paging: 1.5% waste If paging’s space savings is based on wasting only half a page, should we use smaller pages? At the extreme, should we provide translation magic on a per-word basis?

Lecture 11 Page 9 CS 111 Online Providing the Magic Translation Mechanism On per page basis, we need to change a virtual address to a physical address Needs to be fast – So we’ll use hardware The Memory Management Unit (MMU) – A piece of hardware designed to perform the magic quickly

Lecture 11 Page 10 CS 111 Online Paging and MMUs page # offset Virtual addressPhysical address page # Page Table V V V V V V 0 0 Virtual page number is used as an index into the page table Selected entry contains physical page number Offset within page remains the same Valid bit is checked to ensure that this virtual page number is legal

Lecture 11 Page 11 CS 111 Online Some Examples F1C08 Virtual addressPhysical address 0C A1 041F 0D10 0AC3 Page Table V V V V V V C E28 Hmm, no address Why might that happen? And what can we do about it?

Lecture 11 Page 12 CS 111 Online The MMU Hardware MMUs used to sit between the CPU and bus – Now they are typically integrated into the CPU What about the page tables? – Originally implemented in special fast registers – But there’s a problem with that today – If we have 4K pages, and a 64 Gbyte memory, how many pages are there? – 2 36 /2 12 = 2 24 – Or 16 M of pages – We can’t afford 16 M of fast registers

Lecture 11 Page 13 CS 111 Online Handling Big Page Tables 16 M entries in a page table means we can’t use registers So now they are stored in normal memory But we can’t afford 2 bus cycles for each memory access – One to look up the page table entry – One to get the actual data So we have a very fast set of MMU registers used as a cache – Which means we need to worry about hit ratios, cache invalidation, and other nasty issues – TANSTAAFL

Lecture 11 Page 14 CS 111 Online The MMU and Multiple Processes There are several processes running Each needs a set of pages We can put any page anywhere But if they need, in total, more pages than we’ve physically got, Something’s got to go How do we handle these ongoing paging requirements?

Lecture 11 Page 15 CS 111 Online Ongoing MMU Operations What if the current process adds or removes pages? – Directly update active page table in memory – Privileged instruction to flush (stale) cached entries What if we switch from one process to another? – Maintain separate page tables for each process – Privileged instruction loads pointer to new page table – A reload instruction flushes previously cached entries How to share pages between multiple processes? – Make each page table point to same physical page – Can be read-only or read/write sharing

Lecture 11 Page 16 CS 111 Online So Is Paging Perfect? Pages are a very nice memory allocation unit – They eliminate internal and external fragmentation – They require a very simple but powerful MMU They are not a particularly natural unit of data – Programmers don’t think in terms of pages – Programs are comprised of, and operate on, segments – Segments are the natural “chunks” of virtual address space E.g., we map a new segment into the virtual address space – Each code, data, stack segment contains many pages

Lecture 11 Page 17 CS 111 Online Paging and Segmentation We can use both segments and pages Programs request segments – Each code, data, stack segment contains many pages Requires t wo levels of memory management abstraction – A virtual address space is comprised of segments – Relocation & swapping is done on a page basis – Segment based addressing, with page based relocation User processes see segments, paging is invisible

Lecture 11 Page 18 CS 111 Online Relationships Between Segments and Pages A segment is a named collection of pages Operations on segments: – Create/open/destroy – Map/unmap segment to/from process – Find physical page number of virtual page n Connection between paging & segmentation – Segment mapping implemented with page mapping – Page faulting uses segments to find requested page

Lecture 11 Page 19 CS 111 Online Segmentation on Top of Paging Process virtual address space cs ss Segment base registers ds es Process physical address space