Memory Allocation

2 posts

meta2 min readCurated summary

Investing in Infrastructure: Meta’s Renewed Commitment to jemalloc

Meta is renewing its commitment to jemalloc, recognizing its long-term role in delivering reliable and efficient infrastructure alongside the Linux kernel and compilers. After acknowledging that short-term decisions created technical debt and slowed development, Meta has unarchived the original repository and begun rebuilding a long-term roadmap. The effort will focus on modernization, reduced maintenance, hardware adaptation, and closer collaboration with the open-source community. ## Why jemalloc Matters - jemalloc is a high-performance memory allocator used as a foundational component of Meta’s software stack. - It has adapted to changing hardware and workloads over time. - Its impact is comparable to other core infrastructure components such as the Linux kernel and compilers. ## Reflecting on Technical Debt - Meta says recent development gradually moved away from the rigorous engineering principles needed for foundational software. - Some changes provided short-term benefits but introduced technical debt. - That debt increased maintenance burdens and slowed future progress. - Community feedback, including discussions with jemalloc founder Jason Evans, prompted Meta to reassess its stewardship. ## Renewed Development Priorities - **Technical debt reduction:** Clean up, refactor, and improve the codebase to make jemalloc more efficient, reliable, and maintainable. - **Huge-page allocation:** Continue improving the hugepage allocator (HPA) and its use of transparent hugepages (THP) to improve CPU efficiency. - **Memory efficiency:** Optimize memory packing, caching, and purging mechanisms. - **AArch64 support:** Improve out-of-the-box performance on ARM64 systems. - **Hardware and workload adaptation:** Continue evolving jemalloc for current and emerging platforms. ## Open-Source Collaboration - The original jemalloc repository has been unarchived. - Meta intends to work with the open-source community on the project’s future. - The company acknowledges that renewed trust must come through measurable improvements and sustained development. - Community members are invited to provide feedback, contributions, and collaboration. Meta’s practical next step is to demonstrate its renewed commitment through code cleanup, performance improvements, and transparent collaboration. The project’s long-term health will depend on consistent execution rather than statements alone.

Read original(opens in new tab)
datadog3 min readCurated summary

How we wrote a Python profiler

Datadog built a Python continuous profiler because Python lacked Java-style, always-on production profiling tools. The post argues that deterministic profilers such as `cProfile` impose too much overhead for continuous use, while statistical profiling can provide representative performance data with minimal disruption. Datadog’s profiler addresses this through modular collectors, recording, scheduling, and data export. ## Profiling Versus Tracing - **Profiling** measures resource consumption such as CPU time and memory allocation to reveal performance problems. - **Tracing** records individual operations—such as SQL queries or HTTP requests—within a request timeline. - Tracing explains request latency, but profiling provides deeper insight into code-level execution and operating-system resource usage. ## Limitations of Deterministic Python Profilers - Python’s `cProfile`, available since CPython 2.5, records every function call and the time spent in each call. - It can provide a complete execution flow, but its usefulness depends heavily on code structure: - A program built around a few large functions produces little actionable detail. - A program containing thousands of functions can incur two- or three-times runtime overhead. - This overhead makes deterministic profiling unsuitable for always-on production environments. ## Why Profile in Production? - Optimizing without profiling is essentially guessing; real workloads often differ from development environments. - Production systems vary from developer machines in hardware, concurrency, input data, and workload behavior. - Continuous profiling captures how an application actually consumes resources under authentic conditions. - These requirements lead to statistical rather than deterministic profiling. ## Statistical Profiling in Python - Statistical profilers sample program activity periodically instead of recording every function call. - Individual short-lived calls may be missed, but repeated sampling over hours produces a reliable picture of resource consumption. - Lower overhead allows the application to run closer to its normal, unprofiled behavior. - Datadog evaluated numerous open-source Python profilers but found limitations involving platform support, collected data, or presentation-focused designs. - The team therefore developed its own statistical profiler, incorporating ideas from the tools it studied. ## Datadog Python Profiler Design The profiler was designed around three constraints: - Keep runtime overhead as low as possible. - Make deployment simple. - Support common operating systems and environments. Its architecture, inspired by the JDK Flight Recorder, consists of: - **Collectors:** Gather data such as CPU usage and memory allocation. - **Recorder:** Stores events produced by collectors. - **Exporter:** Sends profiling data outside the application. - **Scheduler:** Invokes components at appropriate intervals, such as exporting data every 60 seconds. - **Profiler:** Provides the high-level interface used by applications. ## Stack Collection - The stack collector is the primary built-in collector. - It wakes 100 times per second and captures the execution stack of every Python thread. - For each thread, it gathers information including: - The currently executing function - CPU time consumed - Exceptions being handled - The collector monitors the time required to inspect the application so it can control and limit its own CPU overhead. A statistical profiler with low overhead is the appropriate foundation for continuous production profiling, giving teams evidence about real application behavior without substantially changing that behavior.

Read original(opens in new tab)