Repository navigation
Conversation
Like M_TRIM_THRESHOLD, an explicit M_TOP_PAD disables glibc's dynamic mmap threshold, and it grows the heap in 16 MB steps instead of 128 KB, saving brk() calls and page faults with many threads. Planet (PMTiles, 32 threads): -3.6% wall, -5.3% sys, +0.26 GB anon peak. Germany: -5% wall, page faults 6.1M -> 3.5M (-42%), +60 MB RSS.
Setting any malloc parameter freezes glibc's mmap threshold at 128 KB, so every larger buffer is a fresh mmap with zeroed pages. Boost's is_valid grows such vectors over and over for a huge polygon: the Tongass National Forest relation (1.9M points) took 3x as long as before systemed#939. Tongass relation 677 -> 232 s; planet -2.6% wall for +0.85 GB peak heap; planet on 4 CPUs / 16 GB unchanged within noise, same heap peak. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
cldellow
added a commit
to cldellow/tilemaker
that referenced
this pull request
Nov 2, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01736kJW6d4B5wvq7B5vaKD9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Gain: a huge relation (Tongass National Forest, 1.9M points) is built 2.9× faster again (677 → 232 s), planet wall another −2.6% (1,572.5 → 1,532.0 s) for +0.85 GB peak heap, on top of the top pad's planet −3.6% and Germany −5% (page faults −42%). A planet on 4 CPUs with 16 GB is unaffected (same heap peak, time within run-to-run noise). Output unchanged.
Update: mmap threshold 8 MB
Setting any malloc parameter also freezes glibc's mmap threshold at its 128 KB default. Then every buffer above 128 KB is a fresh
mmapwhose pages the kernel has to zero on first touch. For a huge polygon, Boost'sis_valid(insectionalize) grows such vectors over and over: in @cldellow's report in #977, the Tongass National Forest relation (r6535292, 29,059 ways) took 22.8 minutes on a GitHub runner, about 3× as long as before #939. A profile showed most of that time in vector reallocation. With the mmap threshold raised, the relation is back to its pre-#939 time. So this PR now also setsM_MMAP_THRESHOLDto 8 MB.Tongass alone (
osmium getid -rfrom North America), relation phase, 4 threads:Planet, PMTiles, 32 threads,
--store --fast, master + open performance PRs, one run each:Planet on a small machine (4 CPUs pinned with
taskset, 16 GB cgroup limit without swap,--store), to check the extra memory doesn't hurt there:Two identical runs differ by 3.2% there, so the 8 MB run (+1.8% against run 2) is within noise, with the same heap peak. Germany (in memory, 32 threads, 2 rounds) runs at the same speed with all thresholds. 8 MB is the smallest value that fixes Tongass, is as fast as larger ones on the planet, and costs the least memory. Setting the threshold with
malloptbehaves the same as the tunable (checked with 32 MB: Tongass 230.8 s, Germany peak RSS identical).#939 calls
mallopt(M_TRIM_THRESHOLD, 4 MB)at startup. Setting any malloc parameter explicitly stops glibc from raising its mmap threshold on the fly, which had inflated peak RSS. This PR setsM_TOP_PADto 16 MB instead. That also stops the dynamic adjustment, and it makes the heap grow and shrink in 16 MB steps rather than 128 KB ones. With 32 threads allocating, the small steps mean manybrk()calls and page faults, which shows up as sys time.As before, nothing is set when the user tunes malloc through
GLIBC_TUNABLESor theMALLOC_*_variables (now includingMALLOC_TOP_PAD_), and nothing changes on non-glibc systems.Planet, PMTiles, 32 threads,
--store --fastOne run each; the planet runs used
GLIBC_TUNABLES=glibc.malloc.top_pad=16777216on the same binary. The Germany runs below show that themalloptcall in this PR behaves the same as the tunable.Germany, PMTiles, 32 threads, two rounds
An earlier series on the MBTiles writer (planet, same machine) found the same effect at larger scale: top pad 16 MB −8.4% wall, 64 MB −10% wall for +2.6 GB. 16 MB is the middle ground between speed and memory.
The output is unchanged (only memory management differs).
🤖 Generated with Claude Code