Pre-fault large allocations to reduce PTE lock contention#291
Closed
zkfriendly wants to merge 1 commit intoworldfnd:px/whir-pr215-compatfrom
Closed
Pre-fault large allocations to reduce PTE lock contention#291zkfriendly wants to merge 1 commit intoworldfnd:px/whir-pr215-compatfrom
zkfriendly wants to merge 1 commit intoworldfnd:px/whir-pr215-compatfrom
Conversation
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.
Pre-fault large allocations to reduce PTE lock contention
Use
madvise(MADV_POPULATE_WRITE)andMADV_HUGEPAGEon large allocations (>=128 KiB) so that rayon worker threads don't all hit anonymous page faults simultaneously, avoiding contention on the kernel's PTE spinlock.Changes
prefault()in the global allocator that hints huge pages and pre-faults writable pages for large allocations on Linux.sysconf(_SC_PAGESIZE)instead of a hardcoded value.Benchmark results
~13% wall-clock improvement, ~1 s less system time (fewer kernel page faults).
perf statcomparisonPre-faulting eliminates ~95k minor faults that would otherwise happen in parallel across rayon threads, which is what drives the system-time reduction.
The TLB miss reduction comes from
MADV_HUGEPAGEconsolidating pages into 2 MiB mappings.