Avoid mmap during predownload local segment check to reduce page faults#18467
Open
rohityadav1993 wants to merge 1 commit into
Open
Avoid mmap during predownload local segment check to reduce page faults#18467rohityadav1993 wants to merge 1 commit into
rohityadav1993 wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #18467 +/- ##
=============================================
+ Coverage 34.99% 63.67% +28.68%
- Complexity 869 1684 +815
=============================================
Files 3256 3262 +6
Lines 199548 199826 +278
Branches 30986 31031 +45
=============================================
+ Hits 69840 127248 +57408
+ Misses 123570 62428 -61142
- Partials 6138 10150 +4012
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cd2acab to
d5473a3
Compare
PredownloadScheduler.loadSegmentsFromLocal() previously opened a full SegmentLocalFSDirectory(ReadMode.mmap) for each segment to read its CRC, causing ~C×5 major page faults per segment (one per index chunk boundary validated by SingleFileIndexDirectory.mapBufferEntries). On hosts with thousands of segments this creates a page fault storm at startup. The CRC is pre-written to creation.meta (8 bytes) during segment build and does not require mmapping index files. Replace the SegmentDirectory open with a direct read of creation.meta via DataInputStream, and replace getDiskSizeBytes() with FileUtils.sizeOfDirectory() for the post-download size metric. Both Phase 1 (local check) and Phase 2 (post-download size reporting) now use this optimised path through loadSegmentFromLocal. If a segment CRC matches but the local directory is corrupted, the server startup path handles recovery: BaseTableDataManager.tryLoadExistingSegment performs a full segment load, falling back to downloadAndLoadSegment to re-fetch from deep store or peers.
d5473a3 to
d10cfec
Compare
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.
performanceSummary
Eliminates page faults during segment predownload before server start up. PredownloadScheduler does full segment load:
Both lead to major page faults, in practice for 6000 segments and 5TB data size to download led to 10K+/second major page faults and ~30% io waits.
Note: using stream+untar mode helps with l
Details
Problem
Phase 1
When
PredownloadSchedulerchecks if segments already exist locally (Phase 1), it opens each segment directory viaSegmentLocalFSDirectory(dir, ReadMode.mmap). This triggersSingleFileIndexDirectory.mapBufferEntries()which mmaps the entire index file and validates magic markers at every chunk boundary — causing a major page fault per index entry. With concurrent download threads across thousands of segments, the aggregate fault rate becomes very high.If a segment's CRC matches but the local segment directory is corrupted (e.g. truncated or missing index files), the server startup path handles recovery:
BaseTableDataManager.addNewOnlineSegmentcallstryLoadExistingSegment, which performs a full segment load. If loading fails, it falls back todownloadAndLoadSegmentto re-fetch the segment from deep store or peers.Phase 2
After downloading segments (Phase 2), the scheduler calls
loadSegmentFromLocal()again solely to populate the local size metric — mmapping a freshly-written cold segment and causing another round of major page faults per segment.Fix
Phase 1 — CRC check: The CRC is only needed to check whether a segment was already downloaded to local disk. Replace
SegmentDirectoryopen with a direct 8-byte read fromcreation.meta.Phase 2 — post-download size: Replace
getDiskSizeBytes()withFileUtils.sizeOfDirectory(). No mmap needed for a directory size walk.Cluster Testing Results
Tested on hosts with ~5TB of segment data (thousands of segments), 48 cores, 266GB memory, SSD.
Test Setups
Predownload Duration
Host Metrics During Predownload
Key Takeaways
pgpgin +404%shows it was still performing unnecessary disk reads via mmap. The favorable host conditions (near-zero baseline faults, low memory pressure) masked the impact. On production hosts with higher memory contention, those same reads would cause major fault spikes (as seen in S3).Test plan
PredownloadSegmentInfoTest— updated to verifyPreconditionsthrows on non-directory paths and regular filesPredownloadTableInfoTest— existing tests cover CRC match/mismatch and missing segment scenarios./mvnw -pl pinot-server -am -Dtest=PredownloadSegmentInfoTest,PredownloadTableInfoTest test🤖 Generated with Claude Code