Skip to content

bcachefs: make nocow lock waits SRCU-aware#659

Closed
Komzpa wants to merge 2 commits into
koverstreet:masterfrom
Komzpa:komzpa/nocow-lock-srcu-wait
Closed

bcachefs: make nocow lock waits SRCU-aware#659
Komzpa wants to merge 2 commits into
koverstreet:masterfrom
Komzpa:komzpa/nocow-lock-srcu-wait

Conversation

@Komzpa

@Komzpa Komzpa commented Jun 28, 2026

Copy link
Copy Markdown

Summary

  • threads the active btree_trans into blocking nocow lock waits
  • uses the existing trans_wait_event() wrapper so long waits can drop SRCU via the current short-wait budget
  • leaves the fast trylock path unchanged and avoids the blanket bch2_trans_unlock_long() replacement from the conflicted kernel PR

Context

This targets the nocow-write stall path reported in koverstreet/bcachefs#680, where writeback was blocked around bch2_nocow_write() / nocow locking while the transaction still held SRCU. It is also the narrow form of the maintainer direction on koverstreet/bcachefs#1069: start with the normal unlock path, but escalate long blocking waits through the transaction-aware wait helper instead of dropping SRCU unconditionally at every callsite.

Tests

Validation

  • git diff --check
  • make generate_version && BINDGEN=/home/kom/.cargo/bin/bindgen LIBCLANG_PATH=/usr/lib/llvm-18/lib CARGO_BUILD_JOBS=4 make -j4 bcachefs
  • safe staged kbuild module compile without unload/install side effects:
    make -C /lib/modules/$(uname -r)/build M=/home/kom/tmp/bcachefs-module-nocow-srcu-wait modules -j4
  • GitHub Actions: Nix Flake actions run 28427644776, 15/15 jobs passed on head 896612eb72c2741ce554d147a65006475adfc042

Related: koverstreet/bcachefs#1069

@koverstreet

Copy link
Copy Markdown
Owner

Merged — cherry-picked onto master (36c7a31, authorship preserved). The SRCU-aware nocow waits are the right fix; the write.c caller was blocking under a held SRCU read lock.

Followed it with a small cleanup commit on our side: since bch2_data_update_init() now takes @trans and the nocow path only runs with ctxt != NULL (promote path bails earlier), the ctxt ? ctxt->trans : NULL and if (ctxt) guards were dead — @trans == ctxt->trans there, so we pass @trans directly. Also corrected the stale 'we don't have a pointer to the trans' comment: we do now, but promotes intentionally don't block on nocow locks so they can't pile up. Thanks!

@koverstreet koverstreet closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants