PMTilesElevationProvider: planet import crashes the JVM — one mmap per cached tile, never released, exceeds vm.max_map_count

Author: AntoineVisorandoCreated Aug 25, 2026Updated Aug 30, 2026

Describe the bug

PMTilesElevationProvider memory-maps every decoded elevation tile and keeps the mapping alive for the whole import: each tile is persisted to a .tile file and immediately mapped via FileChannel.map() (loadTileData, reached from both tryMmapTileFile and persistAndLoad), then stored in the tileBuffers HashMap, which has no eviction — only release() ever unmaps.

A planet import touches on the order of a million distinct z11 land tiles (the PR that introduced the provider, #3287, reports ~110 GB of tile cache for planet z11). Since OSM ways are ordered by ID — i.e. globally interleaved geographically — distinct tiles accumulate very fast in pass2. On a default Linux kernel, vm.max_map_count is 65530 mappings per process, so the import hits the cap after roughly 20 minutes of pass2 and the JVM dies with a confusing native OOM, even though the heap is mostly free.

To Reproduce

Planet import with pmtiles elevation and a tile cache dir, on a Linux host with the default vm.max_map_count (65530):

yaml
graph.elevation.provider: pmtiles
graph.elevation.pmtiles.location: /data/planet.pmtiles   # Mapterhorn planet, z11, 184 GB
graph.elevation.pmtiles.zoom: 11
graph.elevation.cache_dir: /data/pmtiles-cache

Environment: GraphHopper 12.0|2026-04-09T09:26:34Z (master build), Temurin 21, Docker on Debian (kernel 4.19), 256 GB RAM, JAVA_OPTS=-Xmx200g -Xms200g -XX:+UseParallelGC.

What happens

About 20 minutes into pass2 (~10M ways processed, heap used 108 GB out of 200), a cascade of:

PMTilesElevationProvider.getEle(-1.4614054, -48.5036657) failed: Map failed
PMTilesElevationProvider.getEle(-1.4603921, -48.5038) failed: Map failed
...

immediately followed by a fatal native failure:

OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00007f8220f00000, 16384, 0) failed; error='Not enough space' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 16384 bytes for committing reserved memory.

Root cause

Both failures are the per-process VMA cap, not memory:

  • Map failed is FileChannelImpl.map() getting ENOMEM from mmap once the process reaches max_map_count. The exception is swallowed by getEle (returns NaN), and the failure is not cached, so it retries and logs on every subsequent node in that tile.
  • os::commit_memory of 16 KB fails for the same reason: committing a page inside a reserved region splits a VMA, which also needs a free mapping slot. That kills the JVM.
  • It cannot be RAM/overcommit: the tile mappings are READ_ONLY file-backed (they don't count toward Committed_AS), heap usage was 108 GB of 200 GB, and the failing allocation was 16 KB on a 256 GB machine.

Empirical confirmation: after the crash the cache directory contained 65,183 .tile files — the default cap of 65,530 minus a few hundred baseline JVM mappings. The counter stopped exactly at the wall.

Same failure signature as the old MMapDataAccess report in #1866, but here the mapping count is unbounded by design (one mapping per land tile touched, for the whole import).

Workaround

Raise the cap on the host (it is not namespaced, so docker run --sysctl cannot set it):

sysctl -w vm.max_map_count=2000000

sized for ~1.1M land tiles at z11 plus margin. With that the import proceeds past the previous failure point and the cached tiles from the crashed run are reused cleanly.

Suggested fix

Any of:

  • bound the number of concurrently mapped tiles (LRU eviction in tileBuffers, unmapping evicted tiles), or
  • read the packed tiles into (direct) buffers from a bounded cache instead of keeping one mmap per tile, or
  • at minimum document the vm.max_map_count requirement for planet-scale imports in docs/core/elevation.md — the current failure mode (native OOM with a mostly-empty heap) is very hard to trace back to the kernel setting.

Note that the no-cache_dir fallback (packed tiles on heap) is not a planet-scale alternative: ~110 GB of packed tiles would land on the heap.

Two minor related observations:

  • a failed getEle is not cached as failed, so during the cascade every node in an affected tile retries the mmap and logs again;
  • all-sea tiles (SEA_LEVEL_TILE) are never persisted to the cache dir, so they are re-decoded from the pmtiles on every run.