-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Investigate avoiding lifecycle_lock traffic in task::unkillable() #3213
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
Comments
Actually, I don't believe we should have to bounce off the lock at all in the proposed fix. The reason is because |
The other things to consider would be yield() / wait_event(), which are where else the disallow_kill flag gets accessed. But all those functions are always run by the same task, so there would be no race among them. |
I ran the tests. On http://bblum.net/images/perf-removing-lifecycle-lock/100-generations.svg Electing to go ahead with the change. |
In honesty, the dubious change (i.e. removing it around inhibit_kill/allow_kill) is probably responsible for half the speedup. The rest is from inhibit_yield/allow_yield, which never even looked like they needed the locks in the first place. |
Also see 5ba7434. Removing the locks in yield() may be possible. |
…s, r=RalfJung remove unnecesary `-Zunstable-options` AFAIK `-Zunstable-options` is for `cargo --config` CLI, which was stabilized in 1.63 https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#config-cli
task::unkillable
is used a bunch in task, some in sync, and I suspect it really should be used in other places where we have unsafe code, like pipes.Currently it hammers on lifecycle_lock every time:
The reason is to protect it from racing a killer (this code is approximate):
If we just removed the lock in inhibit_kill, the race could be that at point A, the unkillable task increments its flag and promptly goes to sleep, only to get punted awake from what it thought was an unkillable sleep.
If we removed the lock in allow_kill, the race would be that the killer sees the task is not killable, and at point A it then becomes killable and goes to sleep, but the killer doesn't punt it awake, and it blocks forever.
I believe the following version should be safe (though not helgrind-clean), and reduce traffic on lifecycle_lock:
Try this and see what it does to task and sync performance. This is pretty fragile code (i.e. might start racing if something changes elsewhere), so only actually use it if it's a clear win.
The text was updated successfully, but these errors were encountered: