CS703 - Advanced Operating Systems

Slides:



Advertisements
Similar presentations
Dynamic Memory Allocation II
Advertisements

Dynamic Memory Management
Lecture 10: Heap Management CS 540 GMU Spring 2009.
1. Dynamic Memory Allocation. Dynamic Memory Allocation Programmers use dynamic memory allocators (such as malloc ) to acquire VM at run time.  For data.
Garbage Collection  records not reachable  reclaim to allow reuse  performed by runtime system (support programs linked with the compiled code) (support.
1 Binghamton University Dynamic Memory Allocation: Advanced Concepts CS220: Computer Systems II.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
CPSC 388 – Compiler Design and Construction
Mark and Sweep Algorithm Reference Counting Memory Related PitFalls
CS 536 Spring Automatic Memory Management Lecture 24.
CS 1114: Data Structures – memory allocation Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Carnegie Mellon Introduction to Computer Systems /18-243, spring th Lecture, Mar. 31 st Instructors: Gregory Kesden and Markus Püschel.
Lab 3: Malloc Lab. “What do we need to do?”  Due 11/26  One more assignment after this one  Partnering  Non-Honors students may work with one other.
CS 61C L07 More Memory Management (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
Dynamic Memory Allocation II Nov 7, 2002 Topics Explicit doubly-linked free lists Segregated free lists Garbage collection Memory-related perils and pitfalls.
Memory Management Memory Areas and their use Memory Manager Tasks:
Dynamic Memory Allocation II November 7, 2007 Topics Explicit doubly-linked free lists Segregated free lists Garbage collection Review of pointers Memory-related.
CS61C L07 More Memory Management (1) Garcia, Spring 2008 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
Dynamic Memory Allocation Questions answered in this lecture: When is a stack appropriate? When is a heap? What are best-fit, first-fit, worst-fit, and.
Explicit Free Lists Use data space for link pointers –Typically doubly linked –Still need boundary tags for coalescing –It is important to realize that.
Memory Management II: Dynamic Storage Allocation Mar 7, 2000 Topics Segregated free lists –Buddy system Garbage collection –Mark and Sweep –Copying –Reference.
1 Dynamic Memory Allocation: Basic Concepts. 2 Today Basic concepts Implicit free lists.
Writing You Own malloc() March 29, 2003 Topics Explicit Allocation Data structures Mechanisms Policies class19.ppt “The course that gives CMU its.
CS 241 Discussion Section (11/17/2011). Outline Review of MP7 MP8 Overview Simple Code Examples (Bad before the Good) Theory behind MP8.
Carnegie Mellon /18-243: Introduction to Computer Systems Instructors: Bill Nace and Gregory Kesden (c) All Rights Reserved. All work.
University of Washington Wouldn’t it be nice… If we never had to free memory? Do you free objects in Java? 1.
Memory Management -Memory allocation -Garbage collection.
Dynamic Memory Allocation II Topics Explicit doubly-linked free lists Segregated free lists Garbage collection.
Dynamic Memory Allocation II April 1, 2004 Topics Explicit doubly-linked free lists Segregated free lists Garbage collection Memory-related perils and.
Consider Starting with 160 k of memory do: Starting with 160 k of memory do: Allocate p1 (50 k) Allocate p1 (50 k) Allocate p2 (30 k) Allocate p2 (30 k)
Dynamic Memory Allocation II November 4, 2004 Topics Explicit doubly-linked free lists Segregated free lists Garbage collection Memory-related perils and.
Dynamic Memory Allocation II
University of Washington Today More memory allocation!
CS 241 Discussion Section (2/9/2012). MP2 continued Implement malloc, free, calloc and realloc Reuse free memory – Sequential fit – Segregated fit.
Carnegie Mellon 1 Dynamic Memory Allocation: Basic Concepts Instructors: Adapted from CMU course
CS 241 Discussion Section (12/1/2011). Tradeoffs When do you: – Expand Increase total memory usage – Split Make smaller chunks (avoid internal fragmentation)
1 Dynamic Memory Allocation (II) Implementation. 2 Outline Implementation of a simple allocator Explicit Free List Segregated Free List Suggested reading:
University of Washington Implementation Issues How do we know how much memory to free given just a pointer? How do we keep track of the free blocks? How.
Dynamic Memory Management Jennifer Rexford 1. 2 Goals of this Lecture Dynamic memory management techniques Garbage collection by the run-time system (Java)
CS61C L07 More Memory Management (1) Garcia, Spring 2010 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
University of Washington Today More memory allocation!
Memory Management What if pgm mem > main mem ?. Memory Management What if pgm mem > main mem ? Overlays – program controlled.
Instructor: Phil Gibbons
Dynamic Memory Allocation II
Section 10: Memory Allocation Topics
Memory Management Memory Areas and their use Memory Manager Tasks:
CS 3214 Introduction to Computer Systems
Inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 – More Memory Management Lecturer PSOE Dan Garcia
Dynamic Memory Allocation
Instructor: Haryadi Gunawi
Dynamic Memory Allocation II Nov 7, 2000
Memory Management I: Dynamic Storage Allocation Oct 7, 1999
Dynamic Memory Allocation
Memory Management Memory Areas and their use Memory Manager Tasks:
Automatic Memory Management
Dynamic Memory Allocation: Basic Concepts CS220: Computer Systems II
Optimizing Malloc and Free
Memory Management I: Dynamic Storage Allocation March 2, 2000
User-Level Dynamic Memory Allocation: Malloc and Free
Strategies for automatic memory management
CS703 - Advanced Operating Systems
Dynamic Memory Allocation: Basic Concepts /18-213/14-513/15-513: Introduction to Computer Systems 19th Lecture, October 30, 2018.
Memory Allocation II CSE 351 Autumn 2017
Memory Allocation II CSE 351 Winter 2018
Memory Allocation II CSE 351 Winter 2018
Dynamic Memory Allocation: Basic Concepts CSCI 380: Operating Systems
Lecturer PSOE Dan Garcia
Memory Management Memory Areas and their use Memory Manager Tasks:
Inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 – More Memory Management Lecturer PSOE Dan Garcia
Presentation transcript:

CS703 - Advanced Operating Systems By Mr. Farhan Zaidi

Lecture No. 21

Overview of today’s lecture Explicit free lists base allocator details Freeing with LIFO policy Segregated free lists Exploiting allocation patterns of programs Exploiting peaks via arena allocators Garbage collection

Explicit Free Lists A B C Forward links A B 4 4 4 4 6 6 4 4 4 4 C Back links

Allocating From Explicit Free Lists pred succ free block Before: pred succ After: (with splitting) free block

Freeing With Explicit Free Lists Insertion policy: Where in the free list do you put a newly freed block? LIFO (last-in-first-out) policy Insert freed block at the beginning of the free list Address-ordered policy Insert freed blocks so that free list blocks are always in address order i.e. addr(pred) < addr(curr) < addr(succ)

Freeing With a LIFO Policy pred (p) succ (s) Case 1: a-a-a Case 2: a-a-f a self a p s before: a self f p s after: a f

Freeing With a LIFO Policy (cont) s before: f self a Case 3: f-a-a Case 4: f-a-f p s after: f a p1 s1 p2 s2 before: f self f p1 s1 p2 s2 after: f

Explicit List Summary Comparison to implicit list: Allocate is linear time in number of free blocks instead of total blocks -- much faster allocates when most of the memory is full Slightly more complicated allocate and free since needs to move blocks in and out of the list Some extra space for the links (2 extra words needed for each block) Main use of linked lists is in conjunction with segregated free lists Keep multiple linked lists of different size classes, or possibly for different types of objects

Simple Segregated Storage Separate free list for each size class No splitting Tradeoffs: Fast, but can fragment badly

Segregated Fits Coalesce and place on appropriate list (optional) Array of free lists, each one for some size class To free a block: Coalesce and place on appropriate list (optional) Tradeoffs: Faster search than sequential fits (i.e., log time for power of two size classes) Controls fragmentation of simple segregated storage Coalescing can increase search times Deferred coalescing can help

Known patterns of real programs ramps: accumulate data monotonically over time peaks: allocate many objects, use briefly, then free all plateaus: allocate many objects, use for a long time bytes bytes bytes

Exploiting peaks 64k 64k free pointer Peak phases: alloc a lot, then free everything Advantages: alloc is a pointer increment, free is “free”, & there is no wasted space for tags or list pointers. 64k 64k free pointer

Implicit Memory Management: Garbage Collection Garbage collection: automatic reclamation of heap-allocated storage -- application never has to free

Garbage Collection How does the memory manager know when memory can be freed? Need to make certain assumptions about pointers Memory manager can distinguish pointers from non-pointers All pointers point to the start of a block Cannot hide pointers (e.g., by coercing them to an int, and then back again)

Reference counting ref=2 a b Algorithm: counter pointers to object each object has “ref count” of pointers to it increment when pointer set to it decremented when pointer killed ref=2 a b void foo(bar c) { bar a, b; a = c; c->refcnt++; b = a; a->refcnt++; a = 0; a->refcnt--; return; b->refcnt--; }

Problems Circular data structures always have refcnt > 0 ref=1

Memory as a Graph Each block is a node in the graph We view memory as a directed graph Each block is a node in the graph Each pointer is an edge in the graph Locations not in the heap that contain pointers into the heap are called root nodes (e.g. registers, locations on the stack, global variables) Root nodes Heap nodes Not-reachable (garbage) reachable

Assumptions Instructions used by the Garbage Collector is_ptr(p): determines whether p is a pointer length(b): returns the length of block b, not including the header get_roots(): returns all the roots