Principle:ClickHouse ClickHouse ELF Program Header Caching
| Knowledge Sources | |
|---|---|
| Domains | Performance, System |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
An optimization technique that caches ELF program headers to avoid repeated kernel calls.
Description
On Linux, `dl_iterate_phdr` iterates over program headers of loaded shared libraries, requiring a kernel call. Operations like exception handling, stack unwinding, and profiling may call this frequently. Caching program headers in userspace and intercepting `dl_iterate_phdr` eliminates kernel overhead. ClickHouse caches headers at startup (assuming no dynamic loading afterward) for significant performance improvement in exception-heavy code.
Usage
Use in performance-critical applications with frequent stack unwinding, exception handling at scale, or when profiling shows `dl_iterate_phdr` as a bottleneck.
Theoretical Basis
ELF Format: Program headers describe memory segments (code, data, dynamic) loaded at runtime.
dl_iterate_phdr: Standard function to iterate program headers, used by libunwind and exception handling.
Interposition: By defining `dl_iterate_phdr`, the custom version is used instead of glibc's via symbol interposition.
Trade-offs: Assumes no dynamic library loading after cache initialization (acceptable for servers that load all libs at startup).