Skip to content

Merge sorted minimizer runs within the process's open-file limits - #106

Merged
jermp merged 7 commits into
jermp:masterfrom
ratschlab:upstream-bounded-merge-fan-in
Nov 28, 2026
Merged

jermp merged 7 commits into
jermp:masterfrom
ratschlab:upstream-bounded-merge-fan-in

Conversation

@adamant-pwn

Copy link
Copy Markdown
Contributor

minimizers_tuples::merge() opens and memory-maps every sorted run at once. Every build thread writes at least one run, and large inputs write many more. Once there are more runs than RLIMIT_NOFILE allows (the soft limit is often 1024), the build aborts with "cannot open file".

This PR:

  • raises the soft RLIMIT_NOFILE to the hard limit at the start of merge();
  • merges at most half of min(RLIMIT_NOFILE, vm.max_map_count) runs at a time (at least 2) into intermediate runs, then does the final counting merge as before. When the runs fit, it is still a single pass;
  • initializes file_merging_iterator's counters for an empty merge (GCC 13 -O3 maybe-uninitialized).

The fan-in comes from the actual limits, not a fixed constant: a constant cap would add merge passes to builds whose runs already fit, such as the 1279-run case below.

New test test_merge_fan_in:

  • unit checks of the fan-in formula;
  • the soft limit is raised to the hard limit;
  • 49 threads with soft = hard = 32 open files: 49 runs, merged 16 at a time. Checks every k-mer id and that no temp files are left.

Measurements: master 2ea1f8b vs this branch. Wall time is median (range). The index is byte-identical in every successful run.

salmonella_100 (13.1 M k-mers), -t 32 -g 1, 5 reps:

limit (soft:hard) master this PR
4096:4096 0.47 s (0.45–0.49) 0.46 s (0.45–0.49), single pass
64:64 0.47 s (0.47–0.58) 0.48 s (0.46–0.49), single pass
24:24 aborts, "cannot open file" 0.53 s (0.51–0.54), one extra merge round
24:524288 aborts 0.47 s (0.45–0.51), soft raised, single pass

500 Mbp random, -t 64 -g 1, 3 reps:

limit master this PR
4096:4096 12.12 s (11.44–13.04) 12.22 s (11.55–13.49), single pass
64:64 aborts 13.01 s (11.99–13.76), 128 → 4 runs, then final merge

500 Mbp random, -t 640 -g 1 (1279 runs), 3 reps:

limit master this PR
4096:4096 29.89 s (28.81–30.23) 30.14 s (29.24–30.55), single pass
1024:524288 aborts (3/3) 30.02 s (29.30–30.89), soft raised, single pass

Peak RSS and peak temporary disk are unchanged: about 2.1 GB RSS and 1.96 GB temp (2× tuple volume) at -t 64, about 2.7 GB RSS at -t 640.

adamant-pwn and others added 6 commits October 29, 2026 01:12
The external sort of minimizer tuples opened and mapped every sorted run
at once in the final merge. Each build thread writes runs of
RAM / (2 * threads) bytes, so a large input at the default 8 GiB limit
writes about a thousand runs and the merge failed with "cannot open
file" under the usual soft limit of 1024 open files.

Merge at most max_merge_fan_in runs at a time (1024, and at most half
the soft RLIMIT_NOFILE) into longer runs until the rest fit in one final
merge. The index is unchanged; one extra pass over the tuples is made
only when the runs exceed the fan-in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Instead of capping the fan-in at 1024, raise the soft RLIMIT_NOFILE to
the hard limit before merging and merge at most half of
min(soft RLIMIT_NOFILE, vm.max_map_count) runs at a time. Builds whose
runs fit in those limits keep a single merge pass, as before the bounded
merge; extra rounds happen only when the runs exceed them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The constructor returns early when there is nothing to merge and left
m_num_files_to_merge uninitialized, which GCC 13 -O3 reports as
-Werror=maybe-uninitialized in test_merge_fan_in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jermp
jermp merged commit 43c0c2b into jermp:master Nov 28, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants