Operating Systems CMPSC 473 Virtual Memory Management (4) November 18 2010 – Lecture 22 Instructor: Bhuvan Urgaonkar.

Slides:



Advertisements
Similar presentations
國立台灣大學 資訊工程學系 Chapter 9: Virtual Memory. 資工系網媒所 NEWS 實驗室 Objectives To describe the benefits of a virtual memory system To explain the concepts of demand.
Advertisements

Virtual Memory Operating System Concepts chapter 9 CS 355
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory OSC: Chapter 9. Demand Paging Copy-on-Write Page Replacement.
Advanced Operating Systems - Spring 2009 Lecture 17 – March 23, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours:
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 9: Virtual Memory Background Demand Paging.
Segmentation and Paging Considerations
Virtual-Memory Management
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 17: Wrapping up Virtual Memory.
Virtual Memory CS 3100 Virutal Memory.
Chapter 9: Virtual Memory
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 9: Virtual Memory.
CS 333 Introduction to Operating Systems Class 18 - File System Performance Jonathan Walpole Computer Science Portland State University.
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.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Chapter 9: Virtual Memory. Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
CS 346 – Chapter 8 Main memory –Addressing –Swapping –Allocation and fragmentation –Paging –Segmentation Commitment –Please finish chapter 8.
Chapter 9: Virtual Memory. 9.2CSCI 380 – Operating Systems Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Chapter 9: Virtual-Memory Management. 9.2Operating System Principles Chapter 9: Virtual-Memory Management Background Demand Paging Copy-on-Write Page.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Background Virtual memory –
Operating System Concepts 7th Edition Abraham SilBerschatz Peter Baer Galvin Greg Gagne Prerequisite: CSE212.
Chapter 4 Memory Management Virtual Memory.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Outline n Background n Demand.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Chapter 17 Free-Space Management Chien-Chung Shen CIS, UD
Chapter 9: Virtual Memory. 9.2 Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped.
Saurav Karmakar. Chapter 9: Virtual Memory  Background  Demand Paging  Copy-on-Write  Page Replacement  Allocation of Frames  Thrashing  Memory-Mapped.
Processes and Virtual Memory
9.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 9.5 Allocation of Frames Each process needs minimum number of pages Example: machine.
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 9: Virtual Memory.
Chapter 9: Virtual Memory
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Memory Management OS Fazal Rehman Shamil. swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 9: Virtual Memory.
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 9: Virtual Memory.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
CSE Operating System Principles Virtual Memory.
Chapter 9: Virtual Memory. Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
Chapter 9: Virtual Memory. Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 9: Virtual Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual-Memory Management.
Chapter 9: Virtual Memory
Chapter 17 Free-Space Management
OPERATING SYSTEM CONCEPTS AND PRACTISE
Jonathan Walpole Computer Science Portland State University
Chapter 9: Virtual Memory – Part II
Virtual Memory CSSE 332 Operating Systems
Chapter 2 Memory and process management
Chapter 9: Virtual Memory
O.S Lecture 13 Virtual Memory.
Chapter 9: Virtual-Memory Management
What Happens if There is no Free Frame?
Chapter 9: Virtual Memory
CSE 451: Operating Systems Autumn 2005 Memory Management
Virtual Memory Overcoming main memory size limitation
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Chapter 9: Virtual Memory
Buddy Allocation CS 161: Lecture 5 2/11/19.
Chapter 10: Virtual Memory
Presentation transcript:

Operating Systems CMPSC 473 Virtual Memory Management (4) November – Lecture 22 Instructor: Bhuvan Urgaonkar

Allocating Kernel Memory Treated differently from user memory Often allocated from a free-memory pool –Kernel requests memory for structures of varying sizes –Some kernel memory needs to be contiguous

Buddy System Allocates memory from fixed-size segment consisting of physically-contiguous pages Memory allocated using power-of-2 allocator –Satisfies requests in units sized as power of 2 –Request rounded up to next highest power of 2 –When smaller allocation needed than is available, current chunk split into two buddies of next-lower power of 2 Continue until appropriate sized chunk available

Buddy System Allocator

Slab Allocator Alternate strategy Slab is one or more physically contiguous pages Cache consists of one or more slabs Single cache for each unique kernel data structure –Each cache filled with objects – instantiations of the data structure When cache created, filled with objects marked as free When structures stored, objects marked as used If slab is full of used objects, next object allocated from empty slab –If no empty slabs, new slab allocated Benefits include no fragmentation, fast memory request satisfaction

Slab Allocation

How does malloc work? Your process has a heap spanning from virtual address x to virtual address y –All your “malloced” data lives here malloc() is part of a user-level library that keeps some data structures, say a list, of all the free chunks of space in the heap When you call malloc, it looks through the list for a chunk that is big enough for your request, returns a pointer to it, and records the fact that it is not free anymore as well as how big it is

malloc (contd.) When you call free() with the same pointer, free() looks up how big that chunk is and adds it back into the list of free chunks() If you call malloc() and it can't find any large enough chunk in the heap, it uses the brk() syscall to grow the heap, i.e. increase address y and cause all the addresses between the old y and the new y to be valid memory –brk() must be a syscall; there is no way to do the same thing entirely from userspace

brk() system call NAME brk, sbrk - change the amount of space allocated for the calling process's data segment SYNOPSIS #include int brk(void *endds); void *sbrk(intptr_t incr); DESCRIPTION The brk() and sbrk() functions are used to change dynamically the amount of space allocated for the calling process's data segment (see exec(2)). The change is made by resetting the process's break value and allocating the appropriate amount of space. The break value is the address of the first location beyond the end of the data segment. The amount of allocated space increases as the break value increases. Newly allocated space is set to zero. If, how-ever, the same memory space is reallocated to the same process its contents are undefined ……

Memory-Mapped Files Memory-mapped file I/O allows file I/O to be treated as routine memory access by mapping a disk block to a page in memory A file is initially read using demand paging. A page-sized portion of the file is read from the file system into a physical page. Subsequent reads/writes to/from the file are treated as ordinary memory accesses. Simplifies file access by treating file I/O through memory rather than read() write() system calls Also allows several processes to map the same file allowing the pages in memory to be shared

Reading from and writing to a memory-mapped file avoids the extra copy that occurs when using the read() and write system calls where data must be copied to and from a user- space buffer Aside from any potential page faults, reading from and writing to a memory-mapped file does not incur any system call or context switch overhead mmap vs. read/write: advantages

When multiple processes map the same object into memory, data is shared among all the processes Read-only and shared writable mappings are shared in their entirety Private writable mappings have their not-yet COW pages shared Seeking around the mapping involves trivial pointer manipulations. There is no need for the lseek() system call mmap advantages (contd.)

Memory mappings are always at granularity of page => Wastage for small files Very large number of various-sized mappings can cause fragmentation of address space making it hard to find large free contiguous regions Overhead in creating and maintaining the mappings and associated data structures inside kernel mmap vs. read/write: disadvantages

Memory Mapped Files

Quiz Q1: Explain the difference between internal and external fragmentation. What is the most internal fragmentation if address spaces > 4kB, 4kB <= page size <= 8kB Q2: Consider a paging system with the page table stored in memory –If a memory ref. takes 200 nsec, how long does a paged memory ref. take? –If we add TLBs, and TLB hit ratio is 90%, what is the effective mem. ref. time? Assume TLB access takes 0 time Q3: How much memory is needed to store an entire page table for 32-bit address space if –Page size = 4kB, single-level page table –Page size = 4kB, 3-level page table, p1=10, p2=10, d=12

Quiz Q4: Consider a demand-paging system with the following time-measured utilizations: CPU util = 20%, Paging disk (swap device) = 97.7%, Other I/O devices = 5%. For each of the following, say whether it will (or is likely to) improve CPU utilization. Explain your answer. –Install a faster CPU –Install a bigger swap device –Increase the degree of multi-programming –Decrease the degree of multi-programming –Install more main memory –Install a faster hard disk (on which the swapping device resides) –Increase the page size

Quiz Q5: Consider a system with the following #memory refs vs. LRU queue position curve If the following two computers cost the same, which would you buy 1. CPU = 1GHz, RAM = 400pages 2. CPU = 2GHz, RAM = 500pages Assume memory access time of 100 cycles and swap access time of 100,000 cycles. Ignore memory needed to store page tables, ignore the TLB