At CPPCon 2019, Samy Al Bahra, Paul Khuong and Hannes Frederic Sowa collaborated on presenting the foundations of malloc and the tips that helped them improve performance in the real world.

Abstract

Memory allocators are a critical part of the run-time system for languages such as C++. Over the last few decades, the requirements for general-purpose memory allocation have become significantly more complex with different allocators evolving to handle different workloads varying by process age, concurrency, allocation patterns, object sizes, access patterns and more. Unfortunately, many application developers are unaware of their internals and their respective limitations and this directly impacts their ability to debug both performance and correctness problems related to dynamic memory allocation.

This talk will introduce the current industry standard memory allocators (general-purpose and specialized), the categories of memory allocators and their intended workloads and shed some light into their design and implementation. With this foundation, we will review real world problems and their respective solutions, where application performance was significantly hindered or complex bugs were introduced. The audience will walk away with knowledge of (sometimes surprising) anti-patterns to avoid when making use of dynamic memory allocation, and new technologies and techniques to use for improving performance and reliability. We will investigate cases where the general purpose allocator interface fails, and when alternatives are better. Finally, we will reinforce our new-found understanding of some basic memory allocator internals to improve our ability to investigate and root cause heap corruption bugs that would otherwise take hours (sometimes even weeks) to fix.

Finally, we will look to the horizon and introduce some exciting new work being done in the area including memory allocator interfaces for improved spatial locality for related objects from both academia and industry.

Video