# ffsck: bitmap memory is not the whole RAM budget

**A dense bitmap budget scales with the represented block address space, while
the benefit of grouping depends on where the rescan work is concentrated.**
These are exact accounting examples, not measurements of ffsck.

## Historical mechanism

In FAST 2013, ffsck keeps cumulative allocation snapshots for inode groups.
The earliest snapshot containing a block identifies its first-claim group,
which can be rescanned to recover the inode identity. More snapshots trade
memory for finer grouping. Separately, metadata compression retains fields
needed by later cross-checks; section 6 leaves earlier per-file release as
unevaluated work. See sections 4.3.2-4.3.3 and 6 of
[Ma et al.](https://www.usenix.org/system/files/fast13-final52_0-v2_1.pdf).

## Count the represented addresses, not occupied bytes

Our explicitly assumed representation stores one bit for each of N possible
block addresses in each of S independently byte-padded snapshots:

`payload_bytes = S * ceil(N / 8)`

For an aligned address span C bytes and block size B bytes, N = C / B.
The formula excludes headers, alignment beyond a byte, allocator overhead,
the working bitmap, inode summaries, indirect-block summaries, I/O buffers,
directories and other checker state. It is neither a measurement nor an upper
bound on process memory. Compressed or shared bitmap representations need a
different accounting model. Large address spans below are hypothetical,
not a claim that the historical prototype supports those volume sizes.

| Address span | Block size | Snapshots | Dense snapshot payload |
| --- | --- | --- | --- |
| 1 TiB | 4 KiB | 2 | 64 MiB |
| 1 TiB | 4 KiB | 16 | 512 MiB |
| 16 TiB | 4 KiB | 16 | 8 GiB |
| 1 TiB | 1 KiB | 16 | 2 GiB |

TiB, GiB, MiB and KiB use powers of 1024. The model requires an integral block
count rather than silently rounding an inconsistent capacity. With the same
represented address span, reducing occupancy alone does not shrink these dense
bit arrays. For nine addresses and two snapshots the payload is four bytes,
not three: each bitmap has its own byte padding.

## A group is not an owner

Consider four inode groups. A selected block is first claimed by an inode in
group 2 (zero-based), then claimed again in group 3. Its cumulative membership
sequence is `[false, false, true, true]`.

Changing the first claimant from inode 8 to inode 11, within group 2, leaves
that sequence unchanged. The bitmap sequence therefore identifies the group,
not the exact inode, and does not decide which claimant should retain data.
This example is about information discarded by the representation, not a
defect in ffsck. It does not simulate allocation errors or repair decisions.

## A smaller group need not be a proportionally cheaper scan

Our invented workload has 16 inodes split into four equal groups. Twelve inodes
each have one metadata-work unit; the four in group 2 each have 100. Searching
that entire group examines 4/16 of the inodes but 400/412 of the modeled work
(100/103 exactly). With equal per-inode costs, the same group accounts for 4/16
of both quantities.

The denominator here is the total work in all four groups. It is not the work
already visited when a real duplicate is discovered, and it is not a claimed
speedup against e2fsck. A metadata-work unit is an abstract weight, not a byte,
I/O operation or second. Seek distance, caching, batching of conflicts and
early stopping are outside the model. Therefore neither ratio establishes
elapsed-time improvement.

This gives a concrete evaluation checklist: report the grouping rule, the
represented block count, retained snapshot count, implementation memory
overheads, distribution of work per group, duplicate discovery point and
actual rescan bytes/time. A single compression factor or inode-count ratio
cannot supply those missing measurements.

## A different memory tradeoff in FreeBSD

McKusick's 2013 adaptation cached cylinder-group blocks between checker passes.
He reported a nearly doubled memory footprint and released that cache when
allocations failed. This is retained block content to avoid rereads, not the
cumulative per-inode-group snapshots modeled above. His tests used freshly
populated, mostly large-file filesystems; they do not establish a universal
speedup. See printed pp. 21-22 of
[the FreeBSD follow-up](https://files.usenix.org/s3fs-public/cdn/05a_mckusick_020-023_online.pdf).

## Reproduce

Run from this directory with Python 3 and no third-party dependencies:

```sh
python3 -B model.py --check
python3 -B -m unittest discover -s . -p test_model.py
python3 -B -O -m unittest discover -s . -p test_model.py
```

[results.json](./results.json) is generated by [model.py](./model.py);
[test_model.py](./test_model.py) checks rounding independently by packing small
bit arrays, exact large integers, memory monotonicity, invalid inputs and
group membership. `model.py --write` deliberately regenerates the results.
The output records units, inputs, exact denominators and exclusions.

[Evidence map](./evidence.json) | [ffsck record](https://hesela.dev/terms/ffsck/)
| [Address-sum identity example](../ffsck-scan-identity/README.md)

Original Hesela analysis, 2026-12-04. No prototype benchmark, source figure,
current-e2fsck performance claim, hardware experiment or field rate.
