Fix kmermatcher memory size allocation OOM.#1117
Open
bbuschkaemper wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts kmermatcher split sizing to better account for 64-bit per-kmer memory footprint and fixed/per-thread allocations, reducing the likelihood of OOM on large databases when --split-memory-limit is tight.
Changes:
- Introduces saturating arithmetic and helper routines to compute split budgets with fixed-memory reservations and headroom.
- Reworks main and count-table split calculations to use a computed “available budget” instead of sizing right up to the raw memory limit.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| size_t mainBytesPerKmer = sizeof(KmerPosition<T, includeAdjacency, IncludeSeqLen>) + | ||
| (par.needWriteBuffer ? sizeof(KmerPosition<T, false, IncludeSeqLen>) : 0); | ||
| size_t totalSizeNeeded = saturatingMul(totalKmers, mainBytesPerKmer); | ||
| size_t totalKmersPerSplit = entriesFittingMemoryBudget(mainSplitMemoryBudget, mainBytesPerKmer); |
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.
The split memory limit doesn't account for 64-bit types, causing OOM failure.
Summary
This fixes an OOM failure in the
kmermatcheron 64-bit builds on large dbs. Sincekmermatcherids areDBKeyType, the per-kmer memory footprint increases in 64-bit mode. The current split sizing could allocate the main kmer arrays almost exactly up to--split-memory-limit, leaving no room for fixed allocations, per-thread scratch buffers, allocator overhead, etc.The calculation now:
seqkey_to_lenand per-thread kmer generation buffersValidation
Our clustering of the Uniprac db with ca. 1B sequences crashed at the
kmermatcherstep. With this fix, the run completes successfully. The old split calculation selected 2 splits but sized each split too close to our 900G memory limit, causing OOM with additional allocations.