Files
obiskim/DevDoc/implementation/merge_mmap_audit/index.html
T
Eric Coissac f1b4b4ebda docs: rename project to obiskim and expand documentation
Rename the project from "obikmer" to "obiskim" across all documentation, user guides, and developer notes. Add extensive new theoretical and implementation documentation covering chance sharing, sibling partition unification, pair-coverage sampling, MPHF batch queries, merge scaling, and hot resume/memoization. Update navigation structures to reflect these new topics and the new project name.

- Rename "obikmer" to "obiskim" in all HTML titles, headers, navigation labels, and code examples across `DevDoc/` and `doc/` directories.
- Add new navigation links for "Chance sharing across genomes", "Sibling partition unification", "Pair-coverage-biased family sampling", "MPHF batch queries", "Merge mmap audit", "Merge scaling", and "Hot resume and memoization" throughout the documentation site.
- Move `DevDoc/architecture/numa_worker_pools/index.html` to `DevDoc/architecture/hot_resume_memoization/index.html` and update content to focus on hot resume and memoization strategies.
- Move `DevDoc/implementation/evidence_elimination/index.html` to `DevDoc/implementation/merge_mmap_audit/index.html` and update content to detail merge mmap audit findings and plans.
- Move `DevDoc/implementation/superkmer.refs/index.html` to `DevDoc/implementation/merge_scaling/index.html` and update content to discuss merge scaling costs and dependencies.
- Move `DevDoc/theory/indexing/index.html` to `DevDoc/theory/chance_sharing/index.html` and rewrite content to discuss chance sharing across genomes and null models.
- Move `DevDoc/theory/minimizer/index.html` to `DevDoc/theory/sibling_partition_unification/index.html` and update content to discuss sibling partition unification and Can3 masked canonical form.
- Add new `DevDoc/implementation/mphf_batch_queries/index.html` documenting MPHF batch query performance and inventory.
- Add new `DevDoc/theory/pair_coverage_sampling/index.html` documenting pair-coverage-biased family sampling theory and diagnostics.
- Update `DevDoc/architecture/query/index.html` to describe `by_partition` using `Vec<PartitionKmers>` instead of `HashMap` for reduced memory usage.
- Update `DevDoc/implementation/merge/index.html` to describe bootstrap output logic selecting base source by largest `unitigs.bin` size and using `MatrixBuilder::resume`.
- Update `DevDoc/implementation/unitig_evidence/index.html` to change `MAX_KMERS_PER_CHUNK` from 256 to 128 and update rank field documentation.
- Update `DevDoc/implementation/obipipeline/index.html` to reflect that `obiskim` uses `make_pipe!` and `.apply()` instead of `make_pipeline!` / `WorkerPool`.
- Update `DevDoc/implementation/filtering/index.html` to change `FilterArgs` inheritance to `obiskim::cmd::predicate::FilterArgs`.
- Update `DevDoc/implementation/partition_layer_cache/index.html` to reflect new crate dependency structure requiring external reachability for algorithm implementation traits.
- Update `doc/formats/index_layout/index.html` to describe new directory structure for index files including `part_NNNNN/index/layer_X/` and updated merging/packing logic.
- Update `doc/formats/vcf/index.html` to use `obiskim` prefixes for contigs and update VCF header source.
- Update `doc/usage/estimate/index.html` to add "Comparing an index with random sharing" section and clarify `--index` and `--presence-threshold` options.
- Update `doc/usage/phylo/index.html` to clarify that running `obiskim phylo` twice draws independent samples and update `--sibling-annex` behavior.
- Update `doc/usage/select/index.html` to clarify that `select` always writes to a new output directory and explains hard-linking mechanism.
- Add new BibTeX entries for Karlin et al. and Bennett et al. in `doc/references.bib`.
- Delete `scripts/smoke_test_index2.sh` which contained end-to-end smoke tests for `obikmer2 index` and `obikmer query`.
- Update `src/Cargo.lock` to bump "obiskim" package dependency from 1.4.8 to 1.4.9.
2026-12-02 16:12:54 +01:00

1825 lines
40 KiB
HTML

<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="prev" href="../merge_parallelism/">
<link rel="next" href="../merge_scaling/">
<link rel="icon" href="../../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.7.6">
<title>Merge mmap audit (2026-11) - obiskim</title>
<link rel="stylesheet" href="../../assets/stylesheets/main.484c7ddc.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<script>__md_scope=new URL("../..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head>
<body dir="ltr">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#merge-mmap-audit-2026-11-17" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<header class="md-header md-header--shadow" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href="../.." title="obiskim" class="md-header__button md-logo" aria-label="obiskim" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
obiskim
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Merge mmap audit (2026-11)
</span>
</div>
</div>
</div>
<script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
</nav>
</header>
<div class="md-container" data-md-component="container">
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href="../.." title="obiskim" class="md-nav__button md-logo" aria-label="obiskim" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
</a>
obiskim
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../.." class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../installation/" class="md-nav__link">
<span class="md-ellipsis">
Installation
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
<span class="md-ellipsis">
Theory
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3">
<span class="md-nav__icon md-icon"></span>
Theory
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../kmers/" class="md-nav__link">
<span class="md-ellipsis">
Kmers and super-kmers
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/encoding/" class="md-nav__link">
<span class="md-ellipsis">
DNA encoding
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/entropy/" class="md-nav__link">
<span class="md-ellipsis">
Entropy filter
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/minimizer/" class="md-nav__link">
<span class="md-ellipsis">
Minimizer selection
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/indexing/" class="md-nav__link">
<span class="md-ellipsis">
Partitioning architecture
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/chance_sharing/" class="md-nav__link">
<span class="md-ellipsis">
Chance sharing across genomes (discussion)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/evolutionary_distances/" class="md-nav__link">
<span class="md-ellipsis">
Central-position SNP distance (discussion)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/sibling_partition_unification/" class="md-nav__link">
<span class="md-ellipsis">
Sibling partition unification (discussion)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../theory/pair_coverage_sampling/" class="md-nav__link">
<span class="md-ellipsis">
Pair-coverage-biased family sampling (discussion)
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" checked>
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
<span class="md-ellipsis">
Implementation
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="true">
<label class="md-nav__title" for="__nav_4">
<span class="md-nav__icon md-icon"></span>
Implementation
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../superkmer/" class="md-nav__link">
<span class="md-ellipsis">
SuperKmer
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../kmer/" class="md-nav__link">
<span class="md-ellipsis">
Kmer
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../chunkreader/" class="md-nav__link">
<span class="md-ellipsis">
Chunk reader
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../pipeline/" class="md-nav__link">
<span class="md-ellipsis">
Construction pipeline
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../obipipeline/" class="md-nav__link">
<span class="md-ellipsis">
obipipeline library
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../storage/" class="md-nav__link">
<span class="md-ellipsis">
On-disk storage
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../mphf/" class="md-nav__link">
<span class="md-ellipsis">
MPHF selection
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../mphf_batch_queries/" class="md-nav__link">
<span class="md-ellipsis">
MPHF batch queries (inventory)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../unitig_evidence/" class="md-nav__link">
<span class="md-ellipsis">
Unitig evidence encoding
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../evidence_elimination/" class="md-nav__link">
<span class="md-ellipsis">
Evidence elimination (discussion)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../layer_tier/" class="md-nav__link">
<span class="md-ellipsis">
obikindex layer tier
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../persistent_compact_int_vec/" class="md-nav__link">
<span class="md-ellipsis">
PersistentCompactIntVec
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../persistent_bit_vec/" class="md-nav__link">
<span class="md-ellipsis">
PersistentBitVec
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../merge/" class="md-nav__link">
<span class="md-ellipsis">
Merge command
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../merge_parallelism/" class="md-nav__link">
<span class="md-ellipsis">
Merge parallelism & memory
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
Merge mmap audit (2026-11)
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
Merge mmap audit (2026-11)
</span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#observed-failures" class="md-nav__link">
<span class="md-ellipsis">
Observed failures
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#inventory-mappings-held-by-one-merge_partition-call" class="md-nav__link">
<span class="md-ellipsis">
Inventory: mappings held by one merge_partition call
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#weaknesses" class="md-nav__link">
<span class="md-ellipsis">
Weaknesses
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#plan" class="md-nav__link">
<span class="md-ellipsis">
Plan
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#implementation-2026-11-17" class="md-nav__link">
<span class="md-ellipsis">
Implementation (2026-11-17)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#re-merging-a-merge-output-resolved-2026-11-18" class="md-nav__link">
<span class="md-ellipsis">
Re-merging a merge output (resolved 2026-11-18)
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../merge_scaling/" class="md-nav__link">
<span class="md-ellipsis">
Merge scaling (open)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../filtering/" class="md-nav__link">
<span class="md-ellipsis">
Kmer filtering
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../select/" class="md-nav__link">
<span class="md-ellipsis">
Select command
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../obitaxonomy/" class="md-nav__link">
<span class="md-ellipsis">
obitaxonomy crate
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../benchmark_query_testing/" class="md-nav__link">
<span class="md-ellipsis">
Benchmark: query-path testing
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../partition_layer_cache/" class="md-nav__link">
<span class="md-ellipsis">
Partition and layer caching (discussion)
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5" >
<label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0">
<span class="md-ellipsis">
Architecture
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_5">
<span class="md-nav__icon md-icon"></span>
Architecture
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../architecture/sequences/invariant/" class="md-nav__link">
<span class="md-ellipsis">
Sequences
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../architecture/index_architecture/" class="md-nav__link">
<span class="md-ellipsis">
Kmer index
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../architecture/siblings/" class="md-nav__link">
<span class="md-ellipsis">
Sibling annex
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../architecture/hot_resume_memoization/" class="md-nav__link">
<span class="md-ellipsis">
Hot resume and memoization
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../architecture/numa_worker_pools/" class="md-nav__link">
<span class="md-ellipsis">
NUMA-aware worker pools
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../../architecture/numa_partition_runner/" class="md-nav__link">
<span class="md-ellipsis">
NUMA-aware partition runner
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#observed-failures" class="md-nav__link">
<span class="md-ellipsis">
Observed failures
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#inventory-mappings-held-by-one-merge_partition-call" class="md-nav__link">
<span class="md-ellipsis">
Inventory: mappings held by one merge_partition call
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#weaknesses" class="md-nav__link">
<span class="md-ellipsis">
Weaknesses
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#plan" class="md-nav__link">
<span class="md-ellipsis">
Plan
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#implementation-2026-11-17" class="md-nav__link">
<span class="md-ellipsis">
Implementation (2026-11-17)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#re-merging-a-merge-output-resolved-2026-11-18" class="md-nav__link">
<span class="md-ellipsis">
Re-merging a merge output (resolved 2026-11-18)
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1 id="merge-mmap-audit-2026-11-17">Merge: mmap audit (2026-11-17)</h1>
<p>Audit of the memory-mapping behaviour of <code>obikmerge::partition_merge::merge_partition</code>, triggered by two production failures on a 192-core NUMA server merging 186 freshly built mono-genome presence indexes (256 partitions, data on BeeGFS <code>/hoyt</code>). Status: <strong>A + C implemented (2026-11-17)</strong>, B deferred. See <a href="#implementation-2026-11-17">Implementation</a>. Implementation prompt: <code>prompts/merge_mmap_refactor.md</code> (repository root, outside the doc tree).</p>
<h2 id="observed-failures">Observed failures</h2>
<table>
<thead>
<tr>
<th>Run</th>
<th>Flags</th>
<th>Failure</th>
<th>When</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>none</td>
<td><code>Bus error</code> (SIGBUS)</td>
<td>seconds after <code>merge_partitions</code> starts</td>
</tr>
<tr>
<td>2</td>
<td><code>--cpu-max 32</code></td>
<td><code>memory allocation of 32768 bytes failed</code> → abort, many threads at once</td>
<td>after ~1 h, 128/256 partitions done</td>
</tr>
</tbody>
</table>
<p>Run 2 rules out "one partition too large for RAM": partitions are scheduled largest first (LFD, <code>merge.rs:289</code>), so at 50 % every remaining partition is smaller than one already merged. Small <code>malloc</code> failures on a 700 GB host are not RAM exhaustion either. Linux would OOM-kill (SIGKILL) instead. A NULL from <code>malloc</code> means <code>mmap</code>/<code>brk</code> returned <code>ENOMEM</code>: <code>vm.max_map_count</code> (default 65 530), <code>RLIMIT_AS</code>, or strict overcommit. Root access is not available on the compute server, so the fix must be in the code.</p>
<h2 id="inventory-mappings-held-by-one-merge_partition-call">Inventory: mappings held by one <code>merge_partition</code> call</h2>
<p>Counts read from the code; totals assume 1 layer per source partition and 1 pre-existing dst layer (estimate, not measured).</p>
<table>
<thead>
<tr>
<th>Resource</th>
<th>Where</th>
<th>Maps</th>
<th>Lifetime</th>
<th>Needed?</th>
</tr>
</thead>
<tbody>
<tr>
<td>Source layers, fully opened</td>
<td><code>partition_merge.rs:219-227</code> → <code>KmerLayer::open</code> → <code>MphfLayer::open</code> (<code>mphf_layer.rs:171</code>)</td>
<td>4 per layer: MPHF (<code>MphfOnly</code>), <code>unitigs.bin</code> (direct access), <code>evidence.bin</code>, <code>unitigs.bin</code> again (<code>LayerEvidence::open</code>, <code>mphf_layer.rs:100</code>). ≈ <strong>740</strong></td>
<td>whole partition</td>
<td>Only the MPHF. Pass 2 calls <code>hash_batch</code> (MPHF only, <code>mphf_layer.rs:258</code>) and <code>fill_sub_matrix</code> (matrix: <code>Implicit</code> for mono-genome, zero maps). Pass 1 only needs the <code>unitigs.bin</code> <em>path</em>.</td>
</tr>
<tr>
<td>Writable columns, created up front</td>
<td><code>partition_merge.rs:327</code>, <code>:349</code> → <code>PersistentBitVecBuilder::new</code> / <code>PersistentCompactIntVecBuilder::new</code></td>
<td><code>set_len</code> (sparse) + <code>MmapMut</code>, <code>n_src_total × (L_dst + 1)</code> ≈ <strong>370</strong></td>
<td>whole pass 2</td>
<td>Only the columns of the ≤ 2 sources being streamed (<code>max_open = 2</code>).</td>
</tr>
<tr>
<td>dst layers, new-layer MPHF, sequential readers</td>
<td>various</td>
<td>≈ 10</td>
<td>variable</td>
<td>yes</td>
</tr>
</tbody>
</table>
<p>≈ <strong>1 100 maps per partition</strong>, &gt; 95 % idle at any instant. × ~32 concurrent partitions (<code>--cpu-max 32</code>) ≈ 35 k, plus stacks and glibc arenas of several hundred pipeline threads. That is within reach of 65 530. Without a cap (192 cores) it is several times over. Consistent with run 2, <strong>not measured</strong>. Whether run 1's SIGBUS comes from the same exhaustion or from failure 4 below is <strong>not established</strong>.</p>
<h2 id="weaknesses">Weaknesses</h2>
<ol>
<li><strong>Source layers opened in full</strong> although merge needs MPHF + matrix only. Evidence and both <code>unitigs.bin</code> maps are dead weight.</li>
<li><strong>All sources opened up front, for the whole partition.</strong> This contradicts the point of partitioning, which is to work on a bounded sub-part of the index. The cost of one partition grows linearly with the number of sources, whatever the partition size.</li>
<li><strong>All destination columns created up front</strong>, the same mismatch on the write side.</li>
<li><strong>Sparse files written through <code>MmapMut</code>.</strong> A page whose block cannot be allocated (quota, full FS, BeeGFS) faults with SIGBUS. That cannot be caught and reports nothing.</li>
<li><strong>No bound on live mappings.</strong> <code>obipipeline::throttle</code> only bounds open read streams.</li>
<li><em>(minor)</em> <code>obicompactvec::mmap_file::open_mmap_file</code> validates magic and header length, not file length against <code>n</code>.</li>
</ol>
<p>Side finding: <code>merge_parallelism.md</code> documents a <code>MemoryBudget</code> semaphore and <code>--budget-fraction</code>. <code>obisys::MemoryBudget</code> still exists but <code>merge.rs</code> no longer uses it (scheduling is <code>PartitionRunner</code>). That page is stale on this point.</p>
<h2 id="plan">Plan</h2>
<p><strong>A. Source-group streaming in pass 2</strong> (<code>obikmerge</code>). Process sources in consecutive groups of <code>G</code> (G = 2, matching <code>max_open</code>). Per group: open its layers, resume each dst matrix (existing layers + new layer), append its <code>src_n</code> columns, fill them through the existing pipeline, close, drop. Pass 1 opens no source layer: it builds paths through <code>KmerLayer::new(..).unitigs_path()</code> (valid on <code>Empty</code>). Live maps per partition become independent of the source count. Column order is unchanged (sources visited in order, columns appended in order), so the on-disk result is identical. Fixes 2, 3, 5.</p>
<p><strong>C. In-memory column builders</strong> (<code>obicompactvec</code>). Under A only <code>G × src_n × (L_dst+1)</code> columns are alive. Build them in RAM (bits: n/8 B; counts: n B + overflow map) and write once with <code>write_all</code> to the <code>.building</code> path, then publish. No sparse file and no <code>MmapMut</code> on the merge write path, so <code>ENOSPC</code>/quota becomes an <code>io::Error</code>. The on-disk format must be byte-identical to the current builders' output. Exposed through <code>MatrixBuilder</code>/<code>ColBuilder</code> so <code>obikselect</code>/<code>obikfilter</code> can adopt it later. Fixes 4.</p>
<p><strong>B. Slots-only layer opening</strong> (<code>obikindex</code>, the authority crate). <strong>Deferred to a separate work item</strong> (decision 2026-11-17). Consumers whose kmers are members by construction need MPHF + matrix, never evidence. The same <code>hash_batch</code> + <code>fill_sub_matrix</code> pattern without <code>find</code> appears in three crates: <code>obikmerge</code> (<code>partition_merge.rs:489</code>), <code>obikfilter</code> (<code>partition_iter.rs:106</code>), <code>obikphylo</code> (<code>family_scan.rs:289</code>). <code>family_scan.rs:402</code> hashes <code>variants</code>; whether those are guaranteed members is unchecked. Fixes 1.</p>
<ul>
<li><strong>Rejected: lazy evidence inside <code>MphfLayer</code>.</strong> <code>find</code>/<code>confirm</code> return <code>Option&lt;usize&gt;</code>, so an evidence open error at first use cannot be propagated (panic, or a signature change across the query path). It would also add an "initialised?" branch to the hottest path, and hide in runtime state a distinction that is structural: external query (<code>find</code>, needs evidence) vs in-layer iteration (<code>index</code>/<code>index_batch</code>, no evidence).</li>
<li><strong>Rejected: a standalone parallel type</strong> next to <code>KmerLayer</code>/<code>TypedLayer</code>. It would duplicate count/presence detection and matrix access, and two opening paths would drift.</li>
<li><strong>Retained: composition.</strong> A slots layer = <code>MphfOnly</code> + matrix, carrying <code>hash_batch</code>, <code>fill_sub_matrix</code>, <code>n_cols</code>. The full layer = slots layer + evidence, keeping <code>find</code>/<code>confirm</code>. <code>KmerLayer</code> exposes both openings (<code>open()</code> / e.g. <code>open_slots()</code>) over a single count/presence detection. Open point: <code>MphfLayer::n</code> currently comes from the evidence (<code>evidence.len()</code> / <code>fingerprint.n()</code>). A slots layer must take it from the matrix (<code>n_rows</code>; <code>layer_meta.json</code> for <code>Implicit</code>), so the two must be checked to always agree.</li>
</ul>
<p>Why deferred: after A, B only takes merge from ~8 to ~2 maps per partition, which is negligible. It touches the <code>obikindex</code> query path and needs its own session with <code>query</code> performance checks.</p>
<p>Order: oracle first (end-to-end merge golden output), then A → C. A alone removes the scaling problem; C removes the SIGBUS class.</p>
<h2 id="implementation-2026-11-17">Implementation (2026-11-17)</h2>
<p><strong>A — source-group streaming</strong> (<code>obikmerge/src/partition_merge/</code>, split into <code>mod.rs</code> + <code>pass2.rs</code>). As planned: pass 1 builds paths only; the new-layer matrix is created with its absent columns and closed; pass 2 iterates <code>sources.chunks(SRC_GROUP = 2)</code>, resuming each dst matrix, checking <code>n_cols == n_dst_genomes + col_base</code> (<code>InvalidData</code> otherwise), and appending the group's columns. Prerequisite: <code>MatrixBuilder::n_cols</code> (<code>obicompactvec</code>).</p>
<p><strong>C — in-memory columns</strong> (<code>obicompactvec</code>). New <code>mem_builder.rs</code> (<code>MemBitVecBuilder</code>, <code>MemCompactIntVecBuilder</code>), <code>add_mem_col</code> on both matrix builders and on <code>MatrixBuilder</code>, and <code>ColBuilder::MemBit</code>/<code>MemInt</code>. Format writing is factored rather than duplicated: <code>format::write_pciv_header</code>/<code>write_pciv_tail</code> (also used by <code>finalize_pciv</code>), <code>mmap_file::write_std_header</code>/<code>write_built</code>. Byte identity with the mmap builders is unit-tested for n ∈ {0, 1, 63, 64, 65, 10 000}, with overwrites and &gt; 2 048 overflow entries. Merge uses <code>add_mem_col</code> for source columns; <code>add_absent_col</code> is unchanged (never written through its mapping).</p>
<p>Deviations from the plan:</p>
<ul>
<li><strong>No <code>sync_all</code> in <code>close</code>.</strong> With one forced sync per column file, <code>merge_partitions</code> went from 7.4 s to 63.6 s on the benchmark; without it, 7.0 s (measured, macOS). The mmap builders never synced either. The <code>rename</code> still prevents publishing a partial file. Caveat: on a write-back network FS an allocation error may only surface at <code>close(2)</code>, which <code>File</code>'s drop ignores.</li>
<li><code>add_mem_col</code> returns <code>ColBuilder</code>, not <code>io::Result&lt;ColBuilder&gt;</code>: it does no I/O.</li>
<li>The mmap count builder (<code>PersistentCompactIntVecBuilder</code>) writes in place, without <code>.building</code>; the in-memory one goes through <code>.building</code> + <code>rename</code>. Same final bytes.</li>
<li><code>obikmerge</code>'s <code>matrix_builder_tests</code> were removed: they only exercised <code>obicompactvec::MatrixBuilder</code> and are covered by <code>obicompactvec/src/tests/{matrix_builder,mem_builder}.rs</code>. <code>tempfile</code> dev-dependency of <code>obikmerge</code> removed with them.</li>
</ul>
<p><strong>Verification.</strong> Two golden-output oracles, recorded on the unmodified code:</p>
<ul>
<li><code>scripts/smoke_test_merge.sh</code>: synthetic, 4 genomes with shared fragments and counts ≥ 255, presence/count/<code>--dense</code>; frozen source indexes;</li>
<li><code>scripts/bench_merge_oracle.sh</code>: 20 real specimen presence indexes, sorted <code>dump --debug</code> hash, 85 681 700 k-mers.</li>
</ul>
<p>Both pass after every step. The existing <code>global_index_presence</code> (October binary) gives the same hash.</p>
<p><code>merge_partitions</code> wall time on the benchmark: 7.40 s (ref) → 7.91 s (A) → 7.07 s (A + C) → 8.05 s (after the module split, same code). Single runs; the spread is noise. RSS 243–256 MB throughout. The benchmark is too small to show either the mapping or the memory effect.</p>
<p><strong>Live mappings per partition (estimate, not measured).</strong> Assumptions: 186 mono-genome sources, 1 layer each, 1 pre-existing dst layer.</p>
<table>
<thead>
<tr>
<th></th>
<th>Source layers</th>
<th>Dst columns</th>
<th>Other</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>Before</td>
<td>186 × 4 ≈ 744</td>
<td>186 × 2 ≈ 372 (<code>MmapMut</code>)</td>
<td>≈ 10</td>
<td><strong>≈ 1 100</strong></td>
</tr>
<tr>
<td>After A + C</td>
<td>2 × 4 = 8</td>
<td>0 (in RAM)</td>
<td>≈ 10</td>
<td><strong>≈ 20</strong>, independent of the source count</td>
</tr>
</tbody>
</table>
<p>B would take the 8 down to ~2.</p>
<p><strong>Follow-up — sparse pack (same day).</strong> <code>pack_sparse_bit_matrix</code>/<code>pack_sparse_compact_int_matrix</code> used to open the columnar matrix directly, which maps every column file of a layer at once: <code>n_genomes</code> maps per partition, since layers are packed one after another. Both now call the dense pack first. It concatenates the column files one at a time without mapping them, so the sparse matrix is built from a single <code>matrix.pbmx</code>/<code>.pcmx</code> mapping. This deliberately reverses an earlier choice ("never materialise a packed copy just to read it back once"). It costs one extra write and read of the dense matrix: <code>pack</code> went from 1.11 s to 1.60 s on the benchmark (single run). As a side effect, a stale <code>matrix.pbmx</code> that predates newer columnar data is now re-packed instead of being used as is (<code>pack_bit_matrix</code> compares <code>n_cols</code>). Both oracles pass.</p>
<h2 id="re-merging-a-merge-output-resolved-2026-11-18">Re-merging a merge output (resolved 2026-11-18)</h2>
<p>Symptom: <code>I/O error: No such file or directory</code> in <code>merge_partitions</code> when a merge output was one of the sources. Cause (verified): <code>finalize_indexed</code> packs the output matrices (<code>sparse_meta.json</code> + dict/PFIV files, or <code>matrix.pbmx</code>), so <code>presence/</code>/<code>counts/</code> no longer holds <code>meta.json</code> + <code>col_*</code>. <code>choose_base</code> picks the largest source as destination, i.e. the merged one; bootstrap copies the packed layout and <code>MatrixBuilder::resume</code> → <code>MatrixMeta::load</code> finds no <code>meta.json</code>.</p>
<p>Fix: a packed index can only be a <em>source</em> (pass 2 reads it through <code>PersistentBitMatrix</code>/<code>PersistentIntMatrix::open</code>, which handle every layout). <code>choose_base</code> now filters candidates with <code>can_be_destination</code> (<code>obikmerge/src/merge.rs</code>): one layer is probed with <code>detect_storage</code>; <code>Columnar</code> qualifies, <code>Implicit</code> only for a single genome (materialized on the fly), <code>Packed</code>/<code>Sparse</code> never. With a single source there is nothing to append and the filter is skipped. When several sources are given and none qualifies, <code>run</code> returns an explicit error before any work. Consequence: the result's column order follows the chosen base first, so it can differ from the command-line order.</p>
<p>Not done: in-place unpack of a packed index to allow it as destination, or a destination-side append on the packed format — the sparse incremental strategy is tracked in <code>merge_scaling.md</code>.</p>
<p>Oracle: <code>scripts/smoke_test_merge.sh</code> scenario 2 (A B → AB, then AB C D) is compared against the flat merge by genome label (not against the golden dumps, whose layer placement differs), and merging only packed indexes is checked to be refused.</p>
<p>Residual risk, accepted: read-only maps still SIGBUS if a file is truncated by another process during a merge. That is inherent to <code>mmap</code>.</p>
</article>
</div>
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
</div>
</main>
<footer class="md-footer">
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<script id="__config" type="application/json">{"annotate": null, "base": "../..", "features": [], "search": "../../assets/javascripts/workers/search.2c215733.min.js", "tags": null, "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": null}</script>
<script src="../../assets/javascripts/bundle.79ae519e.min.js"></script>
<script src="https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js"></script>
</body>
</html>