Skip to content

arc: add a few invariant checks in release builds - #18840

Merged
behlendorf merged 1 commit into
openzfs:masterfrom
andriytk:fix-arc-race
Jul 28, 2026
Merged

arc: add a few invariant checks in release builds#18840
behlendorf merged 1 commit into
openzfs:masterfrom
andriytk:fix-arc-race

Conversation

@andriytk

@andriytk andriytk commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

There are these very-hard-to-reproduce kernel panics #18782 and #11338, so it would be nice to root-case them.

Description

Convert a couple ASSERTs invariants to VERIFYs to enforce them in release builds. They should help to understand the cause of the problem, whenever it happens again.

How Has This Been Tested?

CI tests here would be enough I guess.

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Quality assurance (non-breaking change which makes the code more robust against bugs)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist

@andriytk
andriytk force-pushed the fix-arc-race branch 7 times, most recently from 350c3c0 to 2afa094 Compare July 22, 2026 09:31
@amotin

amotin commented Jul 22, 2026

Copy link
Copy Markdown
Member

arc_evict_hdr() should not be called with I/O in progress, or when any reference is present (I/O also holds a references). It is asserted there. So the provided example does not sound real. The comment mention block free during I/O, not eviction...

@andriytk

andriytk commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

It is asserted there.

@amotin, I'm not sure those asserts are checked in release builds, are they?

The comment mention block free during I/O, not eviction...

Thanks for that. Just to clarify, you mean this comment, right?

         * not possible to evict it during the I/O.  The only possible
         * reason for it not to be found is if we were freed during the
         * read.

Do you mean that when block free happens hdr->b_l1hdr.b_state changes to arc_anon and that's why it may not be present in buf_hash? If so, it makes sense.

@amotin

amotin commented Jul 22, 2026

Copy link
Copy Markdown
Member

It is asserted there.

I'm not sure those asserts are checked in release builds, are they?

VERIFY() are built always. ASSERT() only in debug builds. But we can't assert everything production, that is why we have debug builds.

The comment mention block free during I/O, not eviction...

Thanks for that. Just to clarify, you mean this comment, right?

         * not possible to evict it during the I/O.  The only possible
         * reason for it not to be found is if we were freed during the
         * read.

Do you mean that when block free happens hdr->b_l1hdr.b_state changes to arc_anon and that's why it may not be present in buf_hash? If so, it makes sense.

Yes and yes, but I haven't looked on the free path recently.

@andriytk
andriytk marked this pull request as draft July 22, 2026 19:23
@github-actions github-actions Bot added the Status: Work in Progress Not yet ready for general review label Jul 22, 2026
Comment thread module/zfs/arc.c Outdated
@andriytk

andriytk commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

Last couple of days I almost cracked my head staring at the code, chatting with different AIs and trying to figure out a possible scenario that could lead to the bug - no luck. But it was a good exercise to become familiar with the code!

So yeah, converting a couple of ASSERTs to VERIFYs is the only thing we can do atm.

@andriytk andriytk changed the title arc: fix race between arc_read_done() and arc_evict_hdr() arc: add a few invariant checks in release builds Jul 25, 2026
@andriytk
andriytk marked this pull request as ready for review July 25, 2026 17:57
@github-actions github-actions Bot added Status: Code Review Needed Ready for review and testing and removed Status: Work in Progress Not yet ready for general review labels Jul 25, 2026
Convert a couple ASSERTs invariants to VERIFYs to enforce them
in release builds to be able to root-case openzfs#18782 kernel panic,
whenever it happens again.

Signed-off-by: Andriy Tkachuk <atkachuk@wasabi.com>

@behlendorf behlendorf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, given how elusive this race has been promoting these checks to VERIFYs as a debugging change may result in some new evidence and insight.

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Jul 27, 2026
@behlendorf
behlendorf merged commit 023d44b into openzfs:master Jul 28, 2026
61 of 66 checks passed
@andriytk
andriytk deleted the fix-arc-race branch July 28, 2026 23:12
behlendorf pushed a commit that referenced this pull request Aug 6, 2026
Convert a couple ASSERTs invariants to VERIFYs to enforce them
in release builds to be able to root-case #18782 kernel panic,
whenever it happens again.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Andriy Tkachuk <atkachuk@wasabi.com>
Closes #18840
(cherry picked from commit 023d44b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Accepted Ready to integrate (reviewed, tested)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants