-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Performance
-
Product Performance
-
ALL
-
None
-
None
-
None
-
None
-
None
-
None
-
None
mongod's code is about 74 MB and request processing is front-end bound; with 4KB pages the instruction TLB covers a small part of the hot code and each miss costs a page walk. Kernels that cannot map file-backed executables with huge pages leave the code on 4KB pages.
The new startup parameter remapCodeToHugePages (default false, Linux only) copies, at startup, the 2MB-aligned parts of the main executable's code segments that are laid out for huge pages (segment alignment of at least 2MB, for example BOLT-optimized code) into anonymous memory backed by transparent huge pages, and moves the copy over the original addresses with a single mremap(). Addresses and bytes do not change, so running threads are not affected. Nothing is done when transparent huge pages are disabled, and the original mapping is kept if any step fails. It runs before PinCodeSegments, so lockCodeSegmentsInMemory applies to the new mapping. In our measurements it removed about two thirds of the instruction TLB walk cycles in mongod's code.
Measured effect
- YCSB workload B (95% read, 5% update) with remapCodeToHugePages=true: cycles/op -2.3%
- YCSB workload C (100% read) with remapCodeToHugePages=true: cycles/op -0.9%
YCSB, single-node replica set, 5M documents in the WiredTiger cache; cycles and instructions per operation.
Risk
Off by default. The remapped range is anonymous memory, so profilers that symbolize through the file mapping (perf, VTune) cannot resolve symbols in it.
Tests
Adds jstests/noPassthrough/remap_code_to_huge_pages.js: mongod starts with the parameter, logs the remap (when transparent huge pages are enabled) and serves a workload; with the default nothing is remapped.