290 likes | 386 Views
Memory Allocation Costs in Large C and C++ Programs. An article by David Detlefs, Al Dosser and Benjamin Zorn Presented by Vered Ojalvo. Agenda. Introduction Programs Used in the Tests Allocators Used in the Tests Overview of a Memory Allocator Test Results Summary. Introduction.
E N D
Memory Allocation Costs in Large C and C++ Programs • An article by David Detlefs, Al Dosser and Benjamin Zorn • Presented by Vered Ojalvo
Agenda • Introduction • Programs Used in the Tests • Allocators Used in the Tests • Overview of a Memory Allocator • Test Results • Summary
Introduction • Dynamic Storage Allocation Efficiency Importance • Many Algorithms for DSA Exist • Comparison Between Allocators is Needed • How to Compare Allocators?
Programs • Drawn from Wide Variety of Application Areas • Most are Publicly Available • Used in Previous DSA Comparisons
Allocators • Several Allocators Tested • Most are Public, One Commercially Available • Each Implements a Different Allocation Algorithm
A Memory Allocator • Introduction • Goals • Algorithm • Implementation Considerations
Memory Allocator - Introduction • Written by Doug Lea • Publicly Available • Widely Used in Linux, embedded systems and PC environments
Memory Allocator -Goals Balance Between a Number of Goals: • Maximizing Compatibility • Maximizing Portability • Minimizing Space
Memory Allocator -Goals (cont.) • Minimizing Time • Maximizing Locality • Maximizing Error Detection
Memory Allocator - Goal Discussion Some say (Paul Wilson and others in “Dynamic Storage Allocation: A Survey and Critical Review”) that the allocator’s primary goal is minimizing space by minimizing wastage.
Memory Allocator - Goal Discussion (cont.) Doug Lea believes that while time/space issues dominate, the set of tradeoffs and compromises is nearly endless.
Memory Allocator - Goal Discussion (cont.) For Example: • Worst-case alignment increases wastage by forcing skips of bytes to align chunks • Some methods that improve time/space for small programs may cause unacceptably worse time/space characteristics in large programs
Memory Allocator - Algorithms Two core elements: • Boundary Tags - Size Information Before and After the Chunk • Binning - Available Chunks are Maintained in Bins, and Grouped by Size
Data Gathering Methods • Instruction Counts Using Larus QPT’ tool Provides Per-Procedure Counts • Execution time Measured Using the c-shell time Command • Program Live Data Using a Modified malloc / free
Tests Results • How Many Instructions (Absolute and Relative) for Every malloc / free Operation • Using All Combinations of Programs and Allocators
Test Results • Number of Instructions per Object Allocated (absolute and relative) • Number of Instructions in malloc, free and realloc (and all related routines), by Total Number of Instructions
Summary The Paper Presents Detailed Measurements of the Costs of Dynamic Storage Allocation in 11 Diverse C and C++ Programs Using 5 Different DSA Implementations