Skip to content

perf(inode): replace syncutil.InvariantMutex with sync.Mutex in FileInode - #5218

Draft
kislaykishore wants to merge 1 commit into
perf/lru-memory-optfrom
perf/file-inode-mutex-opt
Draft

kislaykishore wants to merge 1 commit into
perf/lru-memory-optfrom
perf/file-inode-mutex-opt

Conversation

@kislaykishore

@kislaykishore kislaykishore commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Reduce FileInode size and per-inode heap allocations by replacing syncutil.InvariantMutex with sync.Mutex:

  • Replace mu syncutil.InvariantMutex (32 bytes, embedding sync.RWMutex and a func() callback) with mu sync.Mutex (8 bytes), saving 24 bytes per FileInode.
  • Invoke f.checkInvariants() directly when syncutil.InvariantCheckingEnabled() is true in NewFileInode, Lock(), and Unlock().
  • Eliminates the 16-byte f.checkInvariants method-value closure heap allocation previously performed by syncutil.NewInvariantMutex(f.checkInvariants) on every NewFileInode call.

Link to the issue in case of a bug fix.

b/585048166

Testing details

  1. Manual - Verified compilation and static analysis via make build.
  2. Unit tests - Verified go test -v -race ./internal/fs/inode/... and go test -tags=check_invariants -race ./internal/fs/inode/....
  3. Integration tests - N/A

Any backward incompatible change? If so, please explain.

N/A

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request replaces the custom syncutil.InvariantMutex with a standard sync.Mutex in FileInode. It manually integrates invariant checking inside NewFileInode, Lock, and Unlock methods, conditioned on syncutil.InvariantCheckingEnabled(). As there are no review comments provided, I have no additional feedback to offer.

@kislaykishore
kislaykishore added this pull request to stack #5220 November 4, 2026 14:29
@kislaykishore
kislaykishore force-pushed the perf/file-inode-mutex-opt branch from ed3a4f4 to e7ad8a8 Compare November 4, 2026 14:30
@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.21%. Comparing base (cebe590) to head (f5e1a01).

Additional details and impacted files
@@                 Coverage Diff                  @@
##           perf/lru-memory-opt    #5218   +/-   ##
====================================================
  Coverage                85.21%   85.21%           
====================================================
  Files                      181      181           
  Lines                    19946    19951    +5     
====================================================
+ Hits                     16997    17002    +5     
  Misses                    2948     2948           
  Partials                     1        1           
Flag Coverage Δ
unittests 85.21% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@kislaykishore
kislaykishore force-pushed the perf/file-inode-mutex-opt branch 2 times, most recently from 6fceffb to 181b72a Compare November 13, 2026 14:43
@kislaykishore
kislaykishore removed this pull request from stack #5220 November 13, 2026 14:47
@kislaykishore
kislaykishore changed the base branch from perf/lookup-count-memory-opt to perf/lru-memory-opt November 13, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant