Skip to content

[Core] Share one fsync between concurrent segment appends #235

Open

Description

@saworbit

Context

#198 moved compression, hashing and encryption off the pipeline lock. Each new segment's append and its fsync still run under the lock, on the runtime worker: NvramLog::append_records calls sync_data() once per segment. So concurrent writes still take turns on the fsync, and a worker can't run other tasks while it waits.

Running the append in block_in_place measured slower. On cargo bench -p capsule-registry --bench end_to_end -- write_concurrent_encrypted (four 16 MiB writers at once), it took 729 ms against 345 ms before #198. Without it, #198 takes 206 ms.

Where

Pipeline::place_chunk in crates/pipeline/src/lib.rs, and the append path in crates/nvram-sim/src/lib.rs.

Proposed direction

Group commit: segments appended while an fsync is in flight are written, then covered by the next single fsync, and each waiting write is told when its segment is durable. The ordering rule in docs/on-disk-format.md §6 must still hold: the data log is fsynced after a write's last segment and before its CAPSULE record goes to the journal.

Acceptance

  • write_concurrent_encrypted improves on 206 ms on the same machine, and single-writer throughput doesn't drop.
  • A test shows a crash after the append and before the shared fsync leaves no committed capsule pointing at a missing segment.

Activity

  1. added
    enhancement
    on Nov 15, 2026
  2. saworbit commented on Nov 16, 2026

    @saworbit
    OwnerAuthor

    Leaving this open. Group commit can't live in NvramLog alone. write_from_reader (capsule-registry lib.rs) calls place_chunk with the pipeline mutex held, and place_chunk commits the storage transaction there, so append_records and its sync_data always run one writer at a time. A shared fsync inside the log would never have a second writer to share with.

    The fsync has to move out of the pipeline lock:

    1. StorageBackend gets an append that doesn't sync, plus a durability barrier that covers everything appended before it. That means every backend: NvramBackend, the storage root, InMemoryBackend, CachedBackend and the io_uring one.
    2. The writers call the barrier unlocked, after their last place_chunk and before finish_write. That covers write_from_reader, the S3 PUT and UploadPart paths, and Complete, which commits the parts' segments. A dedup hit on a segment another writer hasn't made durable yet is covered too, because the barrier syncs everything appended so far.
    3. The crash test from the acceptance list: append, cut the data log back to the last barrier, reopen, and check no committed capsule names a missing segment.

    Missing the barrier on any one commit path loses data after a crash, so this is a durability redesign, not a tuning change. It should be its own fix/ branch, reviewed before it merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions