J-ay-max commented on issue #48135: URL: https://github.com/apache/arrow/issues/48135#issuecomment-7192338929
Hi all, Commenting before this closes as stale — this is close to a problem I ran into while building a memory pool earlier this year, and I'd like to add a concrete angle to the discussion. +1 to what Antoine said about the setter. The weak symbol route is tempting because it sidesteps init order, but there's a case where it quietly fails: if anything calls `default_memory_pool()` before the override takes effect — a static initializer, or a shared library loaded earlier — that call site is already bound to the built-in pool. Then some code uses your pool and some doesn't, which is basically the "easy to miss some" problem Tobias described, just one level down. There's also no clean moment where you can say "the override is live everywhere now." The setter is what I'd actually want to use. Something like an `std::atomic<MemoryPool*>` that starts out lazily pointing at the built-in pool, so static init order isn't an issue. `SetDefaultMemoryPool()` does a CAS and refuses to run once the first allocation has happened. `default_memory_pool()` stays a single atomic load — I'd really rather not put a lock on that path. I spent a good part of this year chasing exactly that kind of contention in my own allocator: thread-local caches feeding a shared central cache, and the page-map mutex becoming the scaling bottleneck at 16 threads. One thing I'd push back on is runtime switching. Swap the pool halfway through and everything allocated from the old pool is still out there, getting freed against the new one. Unless someone wants to tackle that, I'd make it set-once and document it. Worth documenting two more things too: the caller owns the pool's lifetime, and the setter should win over `ARROW_DEFAULT_MEMORY_POOL`. Kou mentioned the dev list — I'll post there as well so this gets a wider audience. If the maintainers want someone to pick it up, I'm happy to write the implementation. I've been working through the same synchronization questions in a three-tier allocator (ThreadCache / CentralCache / PageCache), so this corner of C++ isn't new to me. Wenting Shen -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
