Memory Management What if pgm mem > main mem ?. Memory Management What if pgm mem > main mem ? Overlays – program controlled.

Slides:



Advertisements
Similar presentations
Dynamic Memory Management
Advertisements

Lecture 10: Heap Management CS 540 GMU Spring 2009.
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
5. Memory Management From: Chapter 5, Modern Compiler Design, by Dick Grunt et al.
Dynamic Memory Allocation I October 16, 2008 Topics Simple explicit allocators Data structures Mechanisms Policies lecture-15.ppt “The course that.
Garbage Collection CSCI 2720 Spring Static vs. Dynamic Allocation Early versions of Fortran –All memory was static C –Mix of static and dynamic.
1 Dynamic Memory Allocation: Basic Concepts Andrew Case Slides adapted from Jinyang Li, Randy Bryant and Dave O’Hallaro.
CPSC 388 – Compiler Design and Construction
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
OS Fall’02 Memory Management Operating Systems Fall 2002.
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.
Dynamic Memory Allocation I Nov 5, 2002 Topics Simple explicit allocators Data structures Mechanisms Policies class21.ppt “The course that gives.
1 Storage Allocation Operating System Hebrew University Spring 2007.
1 Optimizing Malloc and Free Professor Jennifer Rexford
Memory Organization.
Dynamic Memory Allocation I November 1, 2006 Topics Simple explicit allocators Data structures Mechanisms Policies class18.ppt “The course that.
Uniprocessor Garbage Collection Techniques Paul R. Wilson.
Memory Management Last Update: July 31, 2014 Memory Management1.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
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.
Memory Management What if pgm mem > main mem ?. Memory Management What if pgm mem > main mem ? Overlays – program controlled.
© 2004, D. J. Foreman 1 Memory Management. © 2004, D. J. Foreman 2 Building a Module -1  Compiler ■ generates references for function addresses may be.
Memory Management Techniques
Storage Management - Chap 10 MANAGING A STORAGE HIERARCHY on-chip --> main memory --> 750ps - 8ns ns. 128kb - 16mb 2gb -1 tb. RATIO 1 10 hard disk.
University of Washington Today Finished up virtual memory On to memory allocation Lab 3 grades up HW 4 up later today. Lab 5 out (this afternoon): time.
1 Dynamic Memory Allocation: Basic Concepts. 2 Today Basic concepts Implicit free lists.
Memory Management What if pgm mem > main mem ?. Memory Management What if pgm mem > main mem ? Overlays – program controlled.
Writing You Own malloc() March 29, 2003 Topics Explicit Allocation Data structures Mechanisms Policies class19.ppt “The course that gives CMU its.
11/26/2015IT 3271 Memory Management (Ch 14) n Dynamic memory allocation Language systems provide an important hidden player: Runtime memory manager – Activation.
CS 241 Section Week #9 (11/05/09). Topics MP6 Overview Memory Management Virtual Memory Page Tables.
Memory Management -Memory allocation -Garbage collection.
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
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Dynamic Memory Allocation: Basic Concepts :
Dynamic Memory Allocation April 9, 2002 Topics Simple explicit allocators Data structures Mechanisms Policies Reading: 10.9 Problems: and class21.ppt.
University of Washington Today More memory allocation!
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)
Chapter 17 Free-Space Management
Instructor: Phil Gibbons
Section 10: Memory Allocation Topics
Chapter 2 Memory and process management
Dynamic Memory Allocation I
CS 326 Programming Languages, Concepts and Implementation
Memory Management 6/20/ :27 PM
Memory Management I: Dynamic Storage Allocation Oct 7, 1999
Dynamic Memory Allocation
Memory Management © 2004, D. J. Foreman.
Dynamic Memory Allocation I October 28, 2003
Dynamic Memory Allocation: Basic Concepts CS220: Computer Systems II
The Hardware/Software Interface CSE351 Winter 2013
Module 9: Virtual Memory
Optimizing Malloc and Free
Memory Management I: Dynamic Storage Allocation March 2, 2000
Dynamic Memory Allocation I
CS703 - Advanced Operating Systems
Dynamic Memory Allocation
Dynamic Memory Allocation I
Dynamic Memory Allocation: Basic Concepts /18-213/14-513/15-513: Introduction to Computer Systems 19th Lecture, October 30, 2018.
Optimizing Dynamic Memory Management
Operating System Chapter 7. Memory Management
Dynamic Memory Allocation November 2, 2000
Dynamic Memory Allocation: Basic Concepts CSCI 380: Operating Systems
Dynamic Memory Allocation I
CS703 - Advanced Operating Systems
Module 9: Virtual Memory
COMP755 Advanced Operating Systems
Module IV Memory Organization.
Presentation transcript:

Memory Management What if pgm mem > main mem ?

Memory Management What if pgm mem > main mem ? Overlays – program controlled

Memory Management What if pgm mem > main mem ? Virtual Memory – OS controlled (with architecture help)

Memory Management Separate physical, logical address space Page faults Demand paging

Memory Access in VM Is access legal ? (seg fault) If page in physical memory, return mem Else – Find free page – Schedule disk operation – Perform disk operation – Update page table – Restart program at offending address

Memory Access Time Assume machine characteristics – 200ns clock rate – Main Mem access of 5 cycles  1000ns – 25 milisecond page service time

Computing Average Access Time MAT = (1 – p) * p * 25,000,000 e.g. assume page fault rate of.001 MAT =.999 * * 25,000,000 = ,000  26x penalty

Your Turn Those were 1998 numbers Assume 2x speedup in clock speed every two years, 2x speedup in disk access time every 4 years What penalty would.001 page fault rate lead to in 2010? What page fault rate would allow MAT of 2x main memory access time.

Replacement Policy (Page) FIFO Random Optimal LRU LRU approximation

Sample References

FIFO – 4 pages

Optimal – 4 pages

LRU – 4 pages

Your Turn Show FIFO, LRU, Optimal for references above but with 3 pages.

Dynamic Memory Allocation (malloc, free) Memory at execution time? – Static area – Runtime stack – Heap Start with large chunk of memory Reuse memory when possible

Consider Starting with 160 units of memory do: – Allocate p1 (50 u) – Allocate p2 (30 u) – Allocate p3 (40 u) – Free p2 – Allocate p4 (40 u) – Free p3 – Allocate p5 (60 u) – Free p1 – Allocate p6 (30u)

Memory Allocation Algorithms Design YOUR algorithm for allocation and deallocation of memory

Memory Management Dynamic (heap) Significant issues – Significant execution time (16%) – Memory performance not uniform – Allocation policies – Bugs Dereference problems Memory leaks

Memory Allocation Strategies Explicit vs. Implicit Memory Allocator General purpose vs. custom allocator Software vs. hardware

Allocation Examples p1 = malloc(4) p2 = malloc(5) p3 = malloc(6) free(p2) p4 = malloc(2)

Goals of Good malloc/free Good execution-time performance Good space utilization Good locality properties

Fragmentation Poor memory utilization --- fragmentation – Internal – overhead associated with a block of memory – External – have enough blocks of memory for a request, but not contiguous Space in use

External Fragmentation p1 = malloc(4) p2 = malloc(5) p3 = malloc(6) free(p2) p4 = malloc(6) External fragmentation depends on future requests; thus difficult to anticipate

Bidirectional Coalescing – Boundary tags [Knuth73] » Replicate size/allocated word at bottom of free blocks » Allows us to traverse the “ list ” backwards, but requires extra space » Important and general technique!

Boundary Tags size 1 word Format of allocated and free blocks Application Memory (and padding?) a = 1: allocated block a = 0: free block size: total block size Application memory (allocated blocks only) a sizea Boundary tag (footer) Header

Your turn Using boundary tag data structure, define algorithms for: – Allocation – Free

Key Allocator Policies Placement policy: – First fit, next fit, best fit, etc. – Trades off lower throughput for less fragmentation Splitting policy: – When do we go ahead and split free blocks? – How much internal fragmentation are we willing to tolerate? Coalescing policy: – Immediate coalescing: coalesce adjacent blocks each time free is called – Deferred coalescing: try to improve performance of free by deferring coalescing until needed. e.g.,

Refinements Separate lists Binary buddy Lea allocator Custom allocators

Lea Allocator An approximate best-fit allocator with different behavior based on object size – Small Objects (<64 bytes) allocated by exact-size quicklists – Medium Objects (<128K) – coalesce quicklists – Large Objects – allocate and free by mmap The best allocator known

Why programmers use Custom Allocators? Improving runtime performance Reducing memory consumption Improving software engineering (?)

Alternative Memory Management Region (arenas) – Reserve memory blocks for program “ parts ” – Deallocate entire regions, not per allocation Garbage collection – Programmer allocates but doesn ’ t free –“ System ” keeps track of memory “ pointed to ” locations, removes the rest – Java

Why Garbage Collect at All? Safety – Memory leaks – Continued use of freed pointers Simplicity Correctness Programming ease

The Two-Phase Abstraction 1. Detection 2. Reclamation

Liveness and Garbage There is a root set which is defined as live. Anything reachable from a live pointer is also live Everything else is garbage

The Root Set – Static global and module variables – Local Variables – Variables on any activation stack(s) Everyone else – Anything Reachable From a live value

Reference Counting Each allocated chunk has reference count that shows how many locations point (refer) to this one. – Advantages ??? – Disadvantages ???

Mark-Sweep Collection Starting from the root set traverse all pointers via depth/breadth first search. Free everything that is not marked.