# Counting protected bytes

One protected object can account for most of a cache's capacity. Counting keys alone cannot establish a byte share.

## Constructed example

Assume a full 12 MiB physical cache holding four objects: A = 1 MiB, B = 1 MiB, C = 1 MiB and D = 9 MiB. Compare two independently specified protected sets; no policy is claimed to choose them.

| Protected keys | Protected objects / resident objects | Protected bytes / physical capacity |
| --- | --- | --- |
| A | 1/4 = 25% | 1/12 = 8.33% |
| D | 1/4 = 25% | 9/12 = 75% |
| A, B, C | 3/4 = 75% | 3/12 = 25% |
| A, B, C, D | 4/4 = 100% | 12/12 = 100% |

Every row retains the same physical contents and capacity. Changing the protected set does not immediately remove the other objects. A byte-based target also need not be exactly achievable with indivisible objects: these sizes offer no subset totaling 6 MiB. That is a property of this constructed example, not a claim about how an implementation rounds or adjusts its target.

## Reproduce

Download [accounting.mjs](./accounting.mjs) and [accounting.test.mjs](./accounting.test.mjs). Run with a Node.js release supporting the built-in test runner:

```sh
node accounting.mjs
node --test accounting.test.mjs
```

The function validates unique keys, positive safe-integer byte sizes, capacity, and protected-set membership. It reports exact integer numerators and denominators alongside display ratios. Empty protected sets are valid; zero capacity is not. The physical-capacity denominator remains explicit even for a partially filled cache.

## Scope

SIPQ's virtual cache controls reinsertion at physical reclamation; its logical occupancy is byte-based. See [Tang et al., section 5](https://www.usenix.org/conference/fast15/technical-sessions/presentation/tang) and the [SIPQ definition](https://hesela.dev/terms/sipq/).

This is an accounting example, not a SIPQ simulator, trace replay or SSD measurement. It cannot predict hit ratio, reinsertion volume, DRAM overhead or NAND writes. Object bytes exclude metadata and padding in this example; an implementation must state its own byte boundary.
