allocator
Class info¶
🛈 DocStrings¶
Process-wide allocator setup, so that dropped frames give their memory back to the OS.
Measured (3M x 7 frame, 4 steps, then "Free memory"; DATACOOK_PLAN.md, phase 3 memory note): after the drop only the cached frames are alive, but with the defaults ~450 MiB of freed memory stays resident:
- pyarrow's default pool (mimalloc; jemalloc in some builds) keeps freed pages until
release_unused(). - With the system pool, glibc serves column buffers from its heaps: its mmap threshold
grows dynamically (up to 32 MiB) after the first large free, and
malloc_trimdoes not shrink the heaps of worker-thread arenas.
configure() makes Arrow use the system allocator and pins glibc's mmap threshold, so every
buffer from 1 MiB up is its own mapping and is unmapped as soon as its last reference dies.
release() returns what is left in the allocators' free lists. Cost: ~15 % slower on
allocation-heavy ops (fresh pages are faulted in again).
This module does not import pyarrow at import time: Arrow reads ARROW_DEFAULT_MEMORY_POOL
when pyarrow is imported, and pa.set_memory_pool() only covers the Python bindings (C++
internals such as the Parquet reader keep using the pool chosen at import).
MMAP_THRESHOLD
module-attribute
¶
glibc: allocations from 1 MiB up get their own mapping.
configure
¶
configure(mmap_threshold: int = MMAP_THRESHOLD) -> None
Set up the allocators for a long-lived process; call before pyarrow is imported.
Explicit settings win: a set ARROW_DEFAULT_MEMORY_POOL keeps the chosen Arrow pool,
a set MALLOC_MMAP_THRESHOLD_ keeps glibc's threshold. Calling it again is harmless.
Source code in src/datacook/allocator.py
release
¶
Give memory freed by dropped frames back to the OS (Arrow pools, glibc heaps).