Virtual Memory CS 537 - Introduction to Operating Systems.

Slides:



Advertisements
Similar presentations
Chapter 4 Memory Management Basic memory management Swapping
Advertisements

1 Lecture 13: Cache and Virtual Memroy Review Cache optimization approaches, cache miss classification, Adapted from UCB CS252 S01.
Operating Systems Lecture 10 Issues in Paging and Virtual Memory Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing.
Virtual Memory. The Limits of Physical Addressing CPU Memory A0-A31 D0-D31 “Physical addresses” of memory locations Data All programs share one address.
Computer Organization CS224 Fall 2012 Lesson 44. Virtual Memory  Use main memory as a “cache” for secondary (disk) storage l Managed jointly by CPU hardware.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
CSIE30300 Computer Architecture Unit 10: Virtual Memory Hsin-Chou Chi [Adapted from material by and
Cs 325 virtualmemory.1 Accessing Caches in Virtual Memory Environment.
Memory/Storage Architecture Lab Computer Architecture Virtual Memory.
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
CSCE 212 Chapter 7 Memory Hierarchy Instructor: Jason D. Bakos.
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 and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
CS 333 Introduction to Operating Systems Class 11 – Virtual Memory (1)
1 Virtual Memory vs. Physical Memory So far, all of a job’s virtual address space must be in physical memory However, many parts of programs are never.
CS 300 – Lecture 22 Intro to Computer Architecture / Assembly Language Virtual Memory.
CS 104 Introduction to Computer Science and Graphics Problems
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.
©UCB CS 162 Ch 7: Virtual Memory LECTURE 13 Instructor: L.N. Bhuyan
1 Memory Management Virtual Memory Chapter 4. 2 The virtual memory concept In a multiprogramming environment, an entire process does not have to take.
03/22/2004CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
©UCB CS 161 Ch 7: Memory Hierarchy LECTURE 24 Instructor: L.N. Bhuyan
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
Segmentation CS 537 – Introduction to Operating Systems.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Virtual Memory.
Review of Memory Management, Virtual Memory CS448.
Operating Systems Chapter 8
Topics covered: Memory subsystem CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Lecture 19: Virtual Memory
July 30, 2001Systems Architecture II1 Systems Architecture II (CS ) Lecture 8: Exploiting Memory Hierarchy: Virtual Memory * Jeremy R. Johnson Monday.
IT253: Computer Organization
Operating Systems COMP 4850/CISG 5550 Page Tables TLBs Inverted Page Tables Dr. James Money.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
Virtual Memory Review Goal: give illusion of a large memory Allow many processes to share single memory Strategy Break physical memory up into blocks (pages)
Virtual Memory. Virtual Memory: Topics Why virtual memory? Virtual to physical address translation Page Table Translation Lookaside Buffer (TLB)
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
4.3 Virtual Memory. Virtual memory  Want to run programs (code+stack+data) larger than available memory.  Overlays programmer divides program into pieces.
Multilevel Caches Microprocessors are getting faster and including a small high speed cache on the same chip.
Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously.
Memory Management OS Fazal Rehman Shamil. swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium.
CSCI 156: Lab 11 Paging. Our Simple Architecture Logical memory space for a process consists of 16 pages of 4k bytes each. Your program thinks it has.
Virtual Memory Review Goal: give illusion of a large memory Allow many processes to share single memory Strategy Break physical memory up into blocks (pages)
LECTURE 12 Virtual Memory. VIRTUAL MEMORY Just as a cache can provide fast, easy access to recently-used code and data, main memory acts as a “cache”
Operating Systems Lecture 9 Introduction to Paging Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of.
CDA 5155 Virtual Memory Lecture 27. Memory Hierarchy Cache (SRAM) Main Memory (DRAM) Disk Storage (Magnetic media) CostLatencyAccess.
Memory: Page Table Structure CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
CS161 – Design and Architecture of Computer
Memory: Page Table Structure
Virtual Memory So, how is this possible?
CS161 – Design and Architecture of Computer
Lecture 12 Virtual Memory.
Virtual Memory - Part II
CS703 - Advanced Operating Systems
Paging COMP 755.
CSCI206 - Computer Organization & Programming
Chapter 8 Digital Design and Computer Architecture: ARM® Edition
Lecture 29: Virtual Memory-Address Translation
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
CSC3050 – Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Virtual Memory.
4.3 Virtual Memory.
Module IV Memory Organization.
Presentation transcript:

Virtual Memory CS Introduction to Operating Systems

Multiprogramming Modern systems keep more than one program in memory at a time Often, all these programs together require more memory than what is available What to do? –use a part of disk and make it look like memory –this is called virtual memory

Disk vs. Memory Memory characteristics –fast - typically 100 ns per access –small - hundreds of megabytes –random access of any byte Disk characteristics –very slow - several milliseconds per access –large - tens of gigabytes –random access of any block (512 bytes)

Virtual Memory Basic concept –keep frequently used process data in physical memory –keep the rest of a processes address space on disk –if a piece of infrequently used data is needed, bring it in from disk Before any data can be used, it must be in physical memory

Virtual Memory swap spacefile system virtual memory P0P0 P2P2 P3P3 P0P0 P1P1 P2P2 P3P3 Physical Memory Disk

Overlays User controls what info is on disk, and what is in memory To access info kept on disk –save some portion of current memory to disk –bring in desired info to memory Very difficult to implement Becomes very system dependant –what if more memory becomes available? –what if less is available?

Overlays Physical Memory Disk P0P0 O 1,1 O 1,2 O 2,1 O 2,2

Paging This is the way it done today User thinks virtual memory is one large array of real memory Let special hardware and the OS keep up this illusion Basic idea –user enters address from virtual space usually 32 or 64 bits (2 32 or 2 64 addressable bytes) –hardware and OS map this virtual address to physical address

Paging Break physical memory into frames Break virtual memory into pages Page size must be multiple of frame size –for simplicity, we’ll assume the same size When an address is accessed –find out which page it is –if not in memory, bring it in –now grab the data

Memory Map Two solutions to almost every problem in computer science –indirection –caching The memory map is a form of indirection Call this memory map the page table

Paging Disk Transfer of Pages Physical Memory Virtual Memory Memory Map

Page Table Keep a record of every page in virtual memory Record actual location of page in this table –frame in memory Also record some other information in table –valid or invalid (in memory or not) –protection bits (read/write/executable)

Page Table Entry Assume 32 bit addressing Entry in table will be 32 bits plus a few extra –32 bits are address in memory –extra bits are valid/invalid and protection bits If entry is valid, the address is the starting location of the page in main memory Index of entry is the page number

Page Table VWX Location of start of page (disk or memory) Page Number Assume the page size is 100

Calculating Physical Address User supplies a virtual address –high order bits are the page number –low order bits are the offset into the page Go to appropriate index in page table Examine valid bit –if valid, grab starting address of page from table –if not, generate a page fault, bring it into memory, set page table entry, grab starting address OS uses another table to find location on disk –now combine the page table entry and offset to calculate the true physical address

Calculating Physical Address ld r1, x virtual address p = VA / size o = VA % size p in page table? grab page address yesno do page fault o base combine base and offset physical address MEMORYMEMORY

Calculating Physical Address user instruction: st r1, x page numberoffset 533 check index 5 in page table: - it is valid and writeable - base = 900 now calculate physical address: PA = base + offset = = 933 user instruction: st r1, y page numberoffset 275 check index 2 in page table: - it is not valid - invoke page fault handler and load page into memory - assume following is now true: base = 1400 now calculate physical address: PA = base + offset = = 1475

Virtual Address Make all pages a power of 2 in size –and make them a multiple of 512 (disk blocks) A virtual address consists of 32 bits –64 bits in some systems Assume a page size of 4K –need 12 bits for the offset (2 12 = 4K) –that leaves 20 bits for the page number –our system can hold 1M (2 20 ) of 4K pages 4 GB

Virtual Address Given the following virtual address: offsetpage number page number = 51 offset in page = 26 bytes How many pages would there be with 16 K pages 1 K pages

Locality of Reference Important concept in computer science spatial locality –if an address x is accessed, high probability that address x+1 will also be referenced temporal locality –if an address x is accessed at time t, high probability it will be accessed again in t+  where  is small

Page Size Proper page size depends on the program reference behavior Too small a page size –too much overhead –does not consider locality of reference Too large a page size –waste memory with data that will never be used holding space that another process could use –assumes too much locality of reference