-
Notifications
You must be signed in to change notification settings - Fork 2.7k
refactor(locking): Make disabling locking on NFS mounts explicit #16177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/cargo/core/compiler/locking.rs
Outdated
| let build_dir_locking_mode = if ws.target_dir() == ws.build_dir() { | ||
| None | ||
| } else { | ||
| Some(match is_on_nfs_mount(ws.build_dir().as_path_unlocked()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: To me, I prefer returning wrapped values like this to be limited to values and not expressions. It just always reads in a funny way to me and adds extra nesting on wrapping to complex expressions that could instead use them being simplified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The motivation is to move logic to determine if we should disable locking outside of try_acquire()
While I kinda can guess why this is useful, would you mind saying it a bit clearer how this is going to be used and evolve to help the fine grained locking implementation?
(Or any comments/code I should read first in the other PR?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is to eventually add a LockingMode enum that can be controlled by the cargo operation.
The vision I have is the have 3 variants Disabled, Coarse, Fine which can be determined by the operation & environment.
For example, cargo clean would use either Disabled or Coarse as it does not have access to the dep graph.
Another motivation is to fallback to Coarse grain locking if we detect that Fine grain locking may fail. (e.g. too many file descriptors)
See determine_locking_mode() in the original PR for proposed heuristics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good from my end
4a6d2b9 to
231505c
Compare
Update cargo submodule 22 commits in 6368002885a04cbeae39a82cf5118f941559a40a..445fe4a68f469bf936b2fd81de2c503b233a7f4f 2025-10-31 14:31:52 +0000 to 2025-11-07 18:08:19 +0000 - fix(depinfo): prevent invalid trailing backslash on Windows (rust-lang/cargo#16223) - refactor: Remove lazycell (rust-lang/cargo#16224) - refactor: extract ConfigValue to its own module (rust-lang/cargo#16222) - fix(config): non-mergeable list from cli should take priority (rust-lang/cargo#16220) - fix(compile): build.warnings=deny shouldn't block hard warnings (rust-lang/cargo#16213) - fix: display absolute path in the `missing in PATH` warning (rust-lang/cargo#16125) - fix: non-mergeable list from config cli merge the same way (rust-lang/cargo#16219) - docs(contrib): Link out to rustc diagnostic style guide (rust-lang/cargo#16216) - fix: Remove build-plan (rust-lang/cargo#16212) - Add native completions for `--package` on various commands (rust-lang/cargo#16210) - fix(completions): don't wrap completion item help in parenthesis (rust-lang/cargo#16215) - refactor(locking): Make disabling locking on NFS mounts explicit (rust-lang/cargo#16177) - docs(unstable): Move compile-time-deps out of Stabilized section (rust-lang/cargo#16211) - docs(ref): Rename DEP_NAME_KEY to DEP_LINKS_KEY (rust-lang/cargo#16205) - feat(build-analysis): emit rebuild reason log entry (rust-lang/cargo#16203) - chore: Update dependencies (rust-lang/cargo#16200) - chore(deps): update cargo-semver-checks to v0.45.0 (rust-lang/cargo#16190) - chore(deps): update msrv (rust-lang/cargo#16178) - refactor: embed deserialize validation logic in ProgressConfig (rust-lang/cargo#16194) - refactor(gctx): extract config schema to a module (rust-lang/cargo#16195) - chore: bump to 0.94.0; update changelog (rust-lang/cargo#16191) - chore(deps): update rust crate gix to 0.74.0 (rust-lang/cargo#16186) r? ghost
Update cargo submodule 22 commits in 6368002885a04cbeae39a82cf5118f941559a40a..445fe4a68f469bf936b2fd81de2c503b233a7f4f 2025-10-31 14:31:52 +0000 to 2025-11-07 18:08:19 +0000 - fix(depinfo): prevent invalid trailing backslash on Windows (rust-lang/cargo#16223) - refactor: Remove lazycell (rust-lang/cargo#16224) - refactor: extract ConfigValue to its own module (rust-lang/cargo#16222) - fix(config): non-mergeable list from cli should take priority (rust-lang/cargo#16220) - fix(compile): build.warnings=deny shouldn't block hard warnings (rust-lang/cargo#16213) - fix: display absolute path in the `missing in PATH` warning (rust-lang/cargo#16125) - fix: non-mergeable list from config cli merge the same way (rust-lang/cargo#16219) - docs(contrib): Link out to rustc diagnostic style guide (rust-lang/cargo#16216) - fix: Remove build-plan (rust-lang/cargo#16212) - Add native completions for `--package` on various commands (rust-lang/cargo#16210) - fix(completions): don't wrap completion item help in parenthesis (rust-lang/cargo#16215) - refactor(locking): Make disabling locking on NFS mounts explicit (rust-lang/cargo#16177) - docs(unstable): Move compile-time-deps out of Stabilized section (rust-lang/cargo#16211) - docs(ref): Rename DEP_NAME_KEY to DEP_LINKS_KEY (rust-lang/cargo#16205) - feat(build-analysis): emit rebuild reason log entry (rust-lang/cargo#16203) - chore: Update dependencies (rust-lang/cargo#16200) - chore(deps): update cargo-semver-checks to v0.45.0 (rust-lang/cargo#16190) - chore(deps): update msrv (rust-lang/cargo#16178) - refactor: embed deserialize validation logic in ProgressConfig (rust-lang/cargo#16194) - refactor(gctx): extract config schema to a module (rust-lang/cargo#16195) - chore: bump to 0.94.0; update changelog (rust-lang/cargo#16191) - chore(deps): update rust crate gix to 0.74.0 (rust-lang/cargo#16186) r? ghost
What does this PR try to resolve?
This PR introduces aLockingStrategystruct andLockingModeenum to allow more control over the locking strategy used during compilation.This work is done in preparation to enable fine grain locking.
The motivation is to move logic to determine if we should disable locking outside of
try_acquire()targetdirectory #16155Notes:
try_acquire()as the registry cache still relies on that check.targetdirectory #16155 there was an oversight which did not consider if artifact-dir was on an nfs mount but not build-dir. This is now taken into consideration byLockingStrategyin this PR.How to test and review this PR?
I created a local nfs mount over localhost and mounted it at
/mnt/nfs_test, then setCARGO_BUILD_BUILD_DIRto a directory in that mount.after build I verified no
.cargo-lockexists in the build-dirNot sure if there is an easy way to test this in CI and I am unsure if building in network filesystem mounts are a common enough usecase to warrant adding that complexity to the test CI.
Other observation during testing
I noticed that
is_on_nfs_mount()will returnfalseif the directory does not exist but will be nested with in an NFS mount. After the directory is created by a previous cargo invocation it will begin returningtrue. I believe this is a bug, though its probably low priority given that this is a probably niche usecase. I did not attempt to fix this in this PR.