# HP AutoRAID: capacity is also placement freedom

A fixed amount of logical data can fit in a parity layout while leaving little
room to keep frequently written data mirrored. This example isolates that
capacity trade-off. It does not estimate IOPS, latency, failure probability or
the time required to migrate data.

Read the [sourced historical record](https://hesela.dev/terms/hp-autoraid/).
The original [1996 paper](https://john.e-wilkes.com/papers/AutoRAID.TOCS.pdf)
provides the architecture; the equations and numbers below are Hesela's
constructed teaching example, not values extracted from its experiments.

## Model and units

All sizes use one common abstract capacity unit. Let P be physical capacity,
R a fixed amount excluded from allocation, D logical data and M the portion
of D held in two-copy mirroring. The remaining D - M uses a parity layout
with k data units per one parity unit, k >= 2.

Assume perfectly divisible capacity, fully occupied stripes and no placement
constraints. Physical occupancy is:

```text
C(M) = 2M + ((k + 1) / k)(D - M)
C(M) + R <= P
0 <= M <= D
```

The two terms account for disjoint portions of logical data. Adding a complete
parity copy of D underneath all mirrored data would describe a different
architecture and overcount this model.

## Exact bound

Multiplying the capacity inequality by k gives:

```text
(k - 1)M <= k(P - R) - (k + 1)D

M_max = min(D, [k(P - R) - (k + 1)D] / (k - 1))
```

If the numerator is negative, even M = 0 cannot fit: report infeasible, not
zero mirrored capacity. An exactly zero numerator is a distinct, feasible
all-parity boundary. The implementation uses rational arithmetic, so a
fractional bound is not silently rounded into a usable allocation.

For P = 120, D = 80, k = 3, no reserve allows M = 20. Reserving R = 12
reduces that ceiling to M = 2. In the latter case 4 physical units hold
the mirrored portion and 104 hold the remaining 78 logical units with parity:
4 + 104 + 12 = 120.

A write-active set of 16 logical units could fit under the first ceiling but
not the second. Passing this capacity condition is only necessary, not
sufficient, for keeping that set mirrored in a real implementation.

See the [generated table](EXAMPLES.md) and [machine-readable rows](examples.json).
The reserve of 12 is deliberately chosen for illustration; it is not an
AutoRAID default, hot-spare policy or guarantee of recoverability.

## What this does not prove

Allocation granularity, uneven device capacities, per-disk placement, metadata,
cleaning space, free-slot fragmentation and temporary copies during migration
can all reduce achievable capacity. R does not model those separately.
An exact arithmetic result is still only an idealized upper bound.

This is a static capacity model, not a controller simulation, recovery proof or
replication of the paper's trace experiments. There is no sampled population,
random seed, confidence interval or empirical speedup here. Modern arrays must
be evaluated against their own layout and failure contracts.

## Reproduce

Python 3.8 or later, standard library only:

```bash
python3 -B render.py --check
python3 -B -m unittest -v test_model.py
python3 -B -O -m unittest -v test_model.py
```

Run from this directory. To intentionally regenerate the published example
files, run `python3 -B render.py` without `--check`.
The independent test enumerates all candidate mixtures on a grid containing
every exact optimum across 5,040 input cases. Other tests cover zero data,
fractional boundaries, huge integers, invalid types and reserve monotonicity.

Files: [model](model.py), [tests](test_model.py), [generator](render.py).
