Skip to content

Adapt mmap threshold handling for aligned memory

Sebastian Ohlmann requested to merge adapt_mmap_threshold into main

Description

Setting the mmap threshold is needed for the glibc implementation of malloc to avoid heap fragmentation when allocating aligned memory. When mmap is used, the corresponding memory can always be freed, thus circumventing the issue.

This commit introduces an adaptive threshold: it is initially set to 100kB, and subsequently reduced to 90% of the requested memory to ensure that aligned memory is always allocated using mmap. This avoids out-of-memory errors caused by heap fragmentation.

Merge request reports