-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
use RWlock when accessing os::env #81850
Conversation
This comment has been minimized.
This comment has been minimized.
Is the common use case really massive read contention on the process environment? A mutex will be faster than an rwlock when uncontended. |
At least with glibc a lock or unlock is a single atomic RMW instruction as long as it is in read mode. A mutex can't do much better than that. That said, the contention I have observed is relatively small. It's the cause of about 1.9% of sampled context switches, which translates to an even smaller impact on wall time. |
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!
Can you split the guard type into two types as well? Then the enum is also no longer needed.
(I was also about to comment on the names of the methods ( |
The enum is private though. Is there any reason to expose two different guards? |
It simplifies the code, and it's also what we do for |
This comment has been minimized.
This comment has been minimized.
Thanks! @bors r+ |
📌 Commit 4fc181d has been approved by |
use RWlock when accessing os::env Multiple threads modifying the current process environment is fairly uncommon. Optimize for the more common read case. r? ``@m-ou-se``
use RWlock when accessing os::env Multiple threads modifying the current process environment is fairly uncommon. Optimize for the more common read case. r? ```@m-ou-se```
Rollup of 10 pull requests Successful merges: - rust-lang#79775 (Fix injected errors when running doctests on a crate named after a keyword) - rust-lang#81012 (Stabilize the partition_point feature) - rust-lang#81479 (Allow casting mut array ref to mut ptr) - rust-lang#81506 (HWAddressSanitizer support) - rust-lang#81741 (Increment `self.index` before calling `Iterator::self.a.__iterator_ge…) - rust-lang#81850 (use RWlock when accessing os::env) - rust-lang#81911 (GAT/const_generics: Allow with_opt_const_param to return GAT param def_id) - rust-lang#82022 (Push a `char` instead of a `str` with len one into a String) - rust-lang#82023 (Remove unnecessary lint allow attrs on example) - rust-lang#82030 (Use `Iterator::all` instead of open-coding it) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Revert switch of env locking to rwlock, to fix deadlock in process spawning This reverts commit 354f19c, reversing changes made to 0cfba2f. PR rust-lang#81850 switched the environment lock from a mutex to an rwlock. However, process spawning (when not able to use `posix_spawn`) locks the environment before forking, and unlocks it after forking (in both the parent and the child). With a mutex, this works (although probably not correct even with a mutex). With an rwlock, on at least some targets, unlocking in the child does not work correctly, resulting in a deadlock. This has manifested as CI hangs on i686 Linux; that target doesn't use `posix_spawn` in the CI environment due to the age of the installed C library (currently glibc 2.23). (Switching to `posix_spawn` would just mask this issue, though, which would still arise in any case that can't use `posix_spawn`.) Some additional cleanup of environment handling around process spawning may help, but for now, revert the PR and go back to a standard mutex. Fixes rust-lang#82221
This reverts commit acdca31.
use RWlock when accessing os::env (take 2) This reverts commit acdca31 (rust-lang#82877) i.e. redoes rust-lang#81850 since the invalid unlock attempts in the child process have been fixed in rust-lang#82949 r? `@joshtriplett`
Multiple threads modifying the current process environment is fairly uncommon. Optimize for the more common read case.
r? @m-ou-se