# msync over an unmapped interval

Files: [C probe](probe.c), [Python runner](observe.py),
[recorded observations](results.json). Results describe the recorded environment,
not a drive population.

A failed synchronization call is not a rollback receipt. Applications that manage
mapped regions should track their live extents and coordinate mapping changes,
instead of treating a return code as an inventory of work completed.

## Evidence boundaries

The Linux msync(2) manual defines ENOMEM when part of the requested interval
is unmapped. EINVAL instead covers an unaligned address or conflicting
MS_SYNC and MS_ASYNC flags. Neither alone diagnoses damaged media.
[Linux manual](https://man7.org/linux/man-pages/man2/msync.2.html)

Linux v6.12 mm/msync.c lines 68-75 record a gap and continue for MS_SYNC.
Lines 87-96 call vfs_fsync_range for eligible shared file-backed regions.
The final return preserves a pending gap error unless another error takes
precedence. Thus synchronization may occur on either side before ENOMEM reaches
the caller. Earlier argument rejection follows a different path. This is a
version-pinned implementation reading, not a guarantee that every region completed.
[Kernel source](https://github.com/torvalds/linux/blob/adc218676eef25575469234709c2d87185ca223a/mm/msync.c#L68)

The native probe creates a fresh three-page file per case, edits its first and
last pages and, where requested, unmaps one page before the call. Nothing
allocates or maps memory between unmap and msync. The eight cases include gaps
at each position, invalid-argument controls, a private mapping and MS_ASYNC.
The file is unlinked immediately; no existing user file is opened.

## Reproduce

On Linux with Python 3 and a C compiler:

    python3 observe.py --temp-dir /path/to/writable/scratch > results.json

The runner compiles with warnings treated as errors, executes three fresh
processes, and records kernel, page size, compiler, filesystem magic, UTC time
and source hashes. Repetitions are repeatability controls, not a sample of disks.
File bytes returned by pread can come from cache. They do not establish durable
storage or causally attribute writes to msync.

## Why this is not a storage-failure study

Rebello et al., *Can Applications Recover from fsync Failures?*, USENIX ATC 2020,
pp. 753-767, distinguish block-level injected faults from a mocked syscall error.
Section 3.2 tests transient sector/block write failures; section 5, observation 9
explains why testing only syscall return handling misses filesystem recovery.
This probe injects no storage fault, emulates no CuttleFS behavior and does not
replicate those experiments. The paper motivates the evidence boundary, not
the msync gap claim.
[Full paper](https://research.cs.wisc.edu/adsl/Publications/atc20-cuttlefs.pdf)

## Practical interpretation

- Retain the error together with the requested range.
- Keep mapping lifetime stable during synchronization; a prior range check alone
  cannot prevent another thread from unmapping it.
- Do not equate ENOMEM with disk exhaustion, media failure or zero completed work.
- Do not infer a successful transaction from cached rereads or from syncing
  surviving subranges after an error.

Canonical definition: [msync](https://hesela.dev/terms/msync/).
Broader context: [synchronization and recovery](https://hesela.com/analyses/fsync-failure-retry-durability/).
