Revise SignalSafeElfCache to allocate with mmap
Summary: [Folly] Revise `SignalSafeElfCache` to use `mmap` for dynamic allocation and not to require static preallocation. While, technically, `mmap` is not documented to be async-signal-safe, in practice it is so at least on Linux. Take advantage. Prior to this change, the `SignalSafeElfCache` with all of its storage would have to be preallocated before setting the signal handler and must not be destroyed ever. Prior to this change, the preallocation would require at least `sizeof(Path) * capacity`, which defaults to ~2MB. It is now possible to use stack-allocated SignalSafeElfCache in signal handlers. This change adds a multi-thread-safe and async-signal-safe `mmap`-based allocator. Details as follows: * All allocations are rounded up to the nearest power of two in size and alignment. * Page or larger allocations are handled directly by `mmap` and free by `munmap` and are not tracked. * Smaller allocations are handled by an `mmap`-backed refcounted arena. Arena sections are 16 pages in size; they are allocated on demand; and they are linked together to allow for `munmap` when the allocator refcounted arena is destroyed. Reviewed By: davidtgoldblatt Differential Revision: D18760282 fbshipit-source-id: 56a34abfe39a7108f790537afeda832fd39714d7
Showing
Please register or sign in to comment