350 likes | 378 Views
Memory Management. Kathryn McKinley. About me. About You!. Course Logistics. Goals Presentations & Discussion Partner Written research problem identification and proposed solutions. Due date FIRM. Volunteers for next week?. Outline.
E N D
Memory Management Kathryn McKinley
Course Logistics • Goals • Presentations & Discussion • Partner • Written research problem identification and proposed solutions. Due date FIRM. • Volunteers for next week?
Outline • Briefly introduce the challenges and key ideas in Memory Management • Explicit vs Automatic • Memory Organization • Contiguous allocation (bump pointer) • Free lists (analogous to pages in memory) • Reclamation • Tracing • Reference counting
Memory Management • Program Objects/Data occupy memory • Problem: How does the runtime system efficiently create and recycle memory on behalf of the program? • What makes this problem important? • What makes this problem hard? • Why are researchers (e.g. me) still working on it?
Dynamic memory allocation and reclamation • Heap contains dynamically allocated objects • Object allocation: malloc, new • Deallocation: • Manual/explicit: free, delete • automatic: garbage collection
Explicit Memory ManagementChallenges • More code to maintain • Correctness • Free an object too soon - core dump • Free an object too late - waste space • Never free - at best waste, at worst fail • Efficiency can be very high • Gives programmers “control”
Garbage collection:Automatic memory management • reduces programmer burden • eliminates sources of errors • integral to modern object-oriented languages, i.e., Java, C# • now part of mainstream computing • Challenge: • performance efficiency
Key Issues • For both • Fast allocation • Fast reclamation • Low fragmentation (wasted space) • How to organize the memory space • Garbage Collection • Discriminating live objects and garbage
Perfect Live Object Detection • live object has a future use • prove that object is not live, and deallocate it • do it as soon as possible after last use
Estimating liveness in practice • approximate liveness by reachability from outside the heap • an unreachable object cannot ever be used – it is garbage • find and preserve reachable objects • Tracing or counting • recycle the space of garbage objects
Identifying Garbage • Reference Counting (reachability) • Count the number of references to each object (RC) • If RC = 0, the object is garbage • Does not work for cycles
Identifying Garbage • ‘Tracing’ (reachability) • Trace reachability from program ‘roots’ • Registers • Stacks • Statics • Objects not traced are unreachable
Space Management • Two broad approaches: • Copying • Bump allocation & en masse reclamation • Fast allocation & reclaim • Space overhead, copy cost • Non-copying • Free-list allocation & reclamation • Space efficiency • Internal fragmentation
Mapping Objects to Computer Resources Data Structure Declarations
Contiguous Allocation New (Plate1)
Contiguous Allocation New (Plate1) New (Plate2) New (Bowl1) New (Fork1) New (Fork2) New (Spoon1)
Explicit Memory ManagementFree with Continuous Allocation Free (Bowl3)
Free with Contiguous Allocation Free (Bowl3) Free (Spoon1)
Garbage Collectionwith Contiguous Allocation Wait longer
Garbage Collection with Contiguous Allocation L L Find live objects: L L L
Garbage Collection with Contiguous Allocation Find live objects: L Copy live objects to new area L
Garbage Collection with Contiguous Allocation Find live objects: L Copy live objects to new area Reclaim old space L
Garbage Collection with Contiguous Allocation Find live objects: L Copy them to new area Reclaim old space Allocate into new space
Explicit Memory Management:Free with Size-Classes Free-Lists Free (Bowl3) Free (Spoon1)
Taxonomy of Design Choices • Incrementality • Composability • Concurrency • Parallelism • Distribution
Incrementality • ‘Full heap’ tracing: • ‘Pause time’ goes up with heap size • Incremental tracing: • Bounded tracing time • Conservative assumption: • All objects in rest of heap are live • Remember pointers from rest of heap • Add ‘remembered set’ to roots for tracing • Generational Collectors • Collect young objects more frequently • Young objects die quickly
Composability • Hybrids - example • Copy younger objects • Non-copying collection of older objects • Hierarchies • Copying intra-partition (increment) • Reference counting inter-partition
Concurrency • ‘Mutator’ and GC operate concurrently
Parallelism • Concurrency among multiple GC threads • Load balancing • Race conditions when tracing • Synchronization
Distribution • Typically implies: • Incrementality • Concurrency • Parallelism • Composability • Detecting termination • When has a partition become isolated?
GC Performance • Three key dimensions: • Throughput (bandwidth) • Responsiveness (latency) • Space • Measurement issues: • Selecting benchmarks • What makes a good GC Benchmark?