# Ext4 orphan-file capacity

A 4 KiB orphan block holds 1,022 inode-number slots, not 1,024. Eight bytes
belong to the magic/checksum tail. More slots do not establish greater deletion
throughput or faster recovery.

## Reproduce

Run `node model.mjs` beside this file and compare the output with
[examples.json](./examples.json). The code uses integer layout arithmetic for
power-of-two block sizes from 1 KiB through 64 KiB. This range is an arithmetic
input domain, not a promise that every kernel or machine mounts every size.

For block size B bytes, slots per block = (B - 8) / 4.
At the pinned revision below, the upper-size comparison is
file bytes <= max(512 * B, 2 * 1024 * 1024).

Thus the guard permits up to 2,048 blocks at 1 KiB, 1,024 at 2 KiB, and 512 at
4 KiB. At 64 KiB its byte ceiling is 32 MiB. These are ceilings for this one
comparison, not measured occupancies or default allocation sizes. A one-byte
file can pass the size comparison without representing a valid orphan file.
The complete initialization also reads blocks and validates metadata.

## Version boundaries

[Linux ca20d5a011d35fc25e328fe31ac47f7aae557c5a, ext4.h](https://github.com/torvalds/linux/blob/ca20d5a011d35fc25e328fe31ac47f7aae557c5a/fs/ext4/ext4.h#L1545-L1557)
defines the tail and slot calculation.
[The matching orphan.c](https://github.com/torvalds/linux/blob/ca20d5a011d35fc25e328fe31ac47f7aae557c5a/fs/ext4/orphan.c#L577-L661)
defines the size guard; its comment explains the 2 MiB floor as compatibility
with e2fsprogs 1.47.4 output.

This is not a version-independent ext4 limit.
[The earlier change 0a6ce20c1564](https://github.com/torvalds/linux/commit/0a6ce20c156442a4ce2a404747bb0fb05d54eeb3)
introduced an 8 MiB cap.
[Linux v6.12](https://github.com/torvalds/linux/blob/adc218676eef25575469234709c2d87185ca223a/fs/ext4/orphan.c)
predates that check. Backports require inspecting the actual source, not
assuming that a distribution release number uniquely determines behavior.

## Why the structure exists

Min, Kashyap, Maass, Kang and Kim, *Understanding Manycore Scalability of File
Systems*, USENIX ATC 2016, pp. 71-85, identifies the old ext4 orphan list as a
serialization point in file deletion (Section 5.2.3, printed p. 78; Table 3).
The study used Linux 4.2-rc8 on an 80-core, eight-socket machine with 512 GB RAM.
Its FXMARK method separates metadata operations and sharing levels. The
historical observation motivates investigating bookkeeping contention; it
does not measure the later orphan-file implementation or predict its speedup.
[Paper and bibliographic record](https://www.usenix.org/conference/atc16/technical-sessions/presentation/min).

This packet is source synthesis and arithmetic. No filesystem was mounted,
no crash recovery was exercised, and no performance benchmark was run.
See the [corpus definition](https://hesela.dev/terms/ext4-orphan-file/) and
[existing recovery analysis](https://hesela.com/analyses/ext4-journal-replay-revocation/#orphan-cleanup).
