interplane.Get Omega
Read in your language

synapse

A component of the AienOS ecosystem.

Brought by drakestapleton

branch main Branches Tags History

synapse / evidence / g2-content-defined-chunking / x6 / RULE.md

121 lines · 7469 bytes Raw Blame History Rendered
1# X6 Rule: Content-Defined Chunking Threshold and Chunk Sizes
2
3ADR 0003 section 6.4 row X6, for step G2 (issue #45). This file fixes the candidates, the corpus,
4the measurements, the deduplication rule, and the decision criterion BEFORE any X6 run. It is
5committed on its own; the runs, the raw samples, and the outcome are added in later commits and
6must not change anything below.
7
8## 1. The Chunker (fixed for every candidate)
9
10A FastCDC-style gear chunker [S20] with normalized chunking, written in `synapse-store`:
11
12- **Gear table.** `G[i]`, `i = 0..255`, is the `i`-th output (first output is `G[0]`) of SplitMix64
13 seeded with `0x5359_4E41_5053_4531` (ASCII `SYNAPSE1`): `state += 0x9E37_79B9_7F4A_7C15;
14 z = state; z = (z ^ (z >> 30)) * 0xBF58_476D_1CE4_E5B9; z = (z ^ (z >> 27)) * 0x94D0_49BB_1331_11EB;
15 out = z ^ (z >> 31)` (wrapping arithmetic on `u64`).
16- **Rolling hash.** `h = (h << 1) + G[byte]` (wrapping), reset to 0 at the start of every chunk.
17- **Cut rule** for the remaining bytes `src` of a blob, with `bits = log2(avg)`, `mask_s` = the top
18 `bits + 2` bits of a `u64` set, `mask_l` = the top `bits - 2` bits set:
19 if `len(src) <= min` the rest is one chunk; otherwise `n = min(len(src), max)`, hashing starts at
20 byte `min` (bytes before it are skipped), the cut is after byte `i` at the first `i` with
21 `h & mask_s == 0` while `i < min(avg, n)`, else the first `i` with `h & mask_l == 0` while `i < n`,
22 else at `n`.
23- **Threshold.** A blob of `len <= T` bytes is stored whole (one copy per `BlobDigest`, as before
24 G2). A blob of `len > T` bytes is cut into chunks; each chunk is stored once per `ChunkDigest`.
25- **Chunk identity.** `ChunkDigest = SHA-256("SYNAPSE_CHUNK_V1\0" || u64 LE length || bytes)`. A
26 blob's identity stays its `BlobDigest` over the whole content (CONTEXT.md).
27
28## 2. Candidates
29
30`min = avg / 4`, `max = 4 * avg` for every chunked candidate.
31
32| Id | Threshold T | min | avg | max |
33| :--- | ---: | ---: | ---: | ---: |
34| C0 | no chunking (control: every blob whole, the A2 behaviour) | | | |
35| K1 | 16 KiB | 1 KiB | 4 KiB | 16 KiB |
36| K2 | 16 KiB | 2 KiB | 8 KiB | 32 KiB |
37| K3 | 64 KiB | 2 KiB | 8 KiB | 32 KiB |
38| K4 | 64 KiB | 4 KiB | 16 KiB | 64 KiB |
39| K5 | 64 KiB | 8 KiB | 32 KiB | 128 KiB |
40| K6 | 256 KiB | 4 KiB | 16 KiB | 64 KiB |
41| K7 | 256 KiB | 16 KiB | 64 KiB | 256 KiB |
42
43## 3. Corpus: Real AIEN Repository Histories
44
45Bare clones of four AIEN repositories at these commits (fetched 2026-10-16):
46
47| Repository | Commit |
48| :--- | :--- |
49| `aien-spark/aien-architecture` | `d2768e9b8730af5f13c0fbbdfbfa4ba788f7605a` |
50| `aien-spark/aienos` | `b7ebf7cde234e1ddcc91eb8fcaf378d060cfb3a2` |
51| `aien-spark/omega` | `43d8d20da2f64319bcf6196ac7204021c3f280eb` |
52| `aien-spark/synapse` | `b9f46b16aa74301f0b330cfb5fa2e06f07d60b43` |
53
54- History: `git log --reverse --first-parent --raw --no-renames` of each commit, repositories in the
55 order of the table. Survey before the runs (from `git cat-file --batch-check`, not a run):
56 24,093 added or modified regular-file revisions, 434 MB of content, 4,676 revisions above 16 KiB.
57- **One accepted change per commit** that adds or modifies at least one regular file (mode `100644`
58 or `100755`): one signed changeset with one `Upsert` per such file. Deletions, symlinks, and
59 submodules store no content and are left out. Paths are replaced by a stable synthetic path per
60 repository path (`p<n>`), since paths do not affect storage.
61- The client provides a blob's bytes only the first time its `BlobDigest` appears in the run (as a
62 client that asks which blobs the server lacks would); later references name the committed blob.
63- Store limits for the run: `max_paths_per_changeset` and `max_total_changeset_bytes` raised so that
64 no commit is refused (the largest commit decides; the value is recorded in the raw output); every
65 other limit at its default; group commit (`GROUP_COMMIT_DEFAULT`), one agent, strict recovery.
66
67## 4. Measurements
68
69Per candidate and repetition, on a fresh store on the same ext4/NVMe filesystem as the A2 runs:
70
711. **Ingest phase:** submit every change in order, one agent; record each change's time from submit
72 to durable acknowledgement (raw samples) and the phase wall time. Energy: one `aien_spbm` package
73 window around the phase (`INSTRUMENT_UNAVAILABLE` when the meter refuses, never a substitute).
742. **Log bytes:** bytes the store appended to its segments during the ingest phase (4 KiB-padded
75 batches, so frame headers, metadata, chunk tables, manifests, and padding all count), and the
76 content bytes stored (whole blobs plus distinct chunks). Both are deterministic for a sequential
77 run; if repetitions of one candidate disagree, the run is invalid.
783. **Read phase:** read every distinct committed blob once, in commit order, through
79 `get_blob_visible`; each read is compared byte for byte with the corpus bytes (any difference makes
80 the run invalid); record each read's time (raw samples), the phase wall time, and one energy window.
81
82Three repetitions; inside each repetition all eight configurations run once, in an order rotated by
83one position per repetition. Bounds (ADR section 6.2): seconds per accepted change against the A2 flush
84bound (1.006 ms, `evidence/a2-segment-store/measurement/floor.json`, cheapest
85`overwrite_*_fdatasync` p50); a read of `n` bytes against `n` / 273 GB/s plus one index lookup.
86
87## 5. Deduplication Rule (the G2 acceptance)
88
89For a store with chunk parameters `(T, min, avg, max)`:
90
911. A blob of `len <= T` is stored whole and is never cut.
922. A blob of `len > T` is cut by the chunker of section 1; reading it returns exactly its bytes, and
93 its `BlobDigest` is unchanged.
943. The store keeps one copy of every `ChunkDigest` it indexes. Committing a revision `B` of a blob
95 above `T` after a committed revision `A` whose chunks are still indexed stores exactly the distinct
96 chunks of `B` whose `ChunkDigest` is not already indexed (chunks committed earlier in the same batch
97 count as indexed): content bytes added = the sum of their lengths, nothing for the shared chunks.
98 A revision whose `BlobDigest` is already stored adds no chunk.
99
100## 6. Decision Criterion
101
102Let, for configuration `k`: `W_k` = median over the three repetitions of (ingest phase wall time /
103accepted changes); `R_k` = median of (read phase wall time / reads); `S_k` = log bytes of the ingest
104phase.
105
1061. A chunked candidate is **eligible** when all three hold: `W_k <= 1.10 * W_C0` (seconds per accepted
107 change at most 10 % above the control), `R_k <= 1.25 * R_C0` (seconds per read at most 25 % above),
108 and `S_k <= 0.95 * S_C0` (at least 5 % fewer log bytes).
1092. The **winner** is the eligible candidate with the smallest `S_k`. Candidates within 1 % of that
110 smallest `S_k` are ties; among ties the larger `avg` wins, then the larger `T` (fewer chunks to
111 index and fewer reads).
1123. If no candidate is eligible, G2 ships the chunk store with chunking off by default
113 (`T` = unlimited) and reports that outcome; the round-trip and deduplication tests still run with
114 explicit parameters.
1154. Joules per accepted change and per read are measured and reported for every configuration but do
116 not enter the decision: on this shared host the A2 package energy above idle was inside the noise
117 (some A2 cells read below idle), so a joule criterion would decide on noise.
118
119## Sources
120
121- [S20] Xia et al., "FastCDC", USENIX ATC 2016 (ADR 0003 section 12).