Skip to content

Priority inversion avoidance in Actor Runtime #41362

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

Merged
merged 4 commits into from
Feb 17, 2022

Conversation

rokhinip
Copy link
Contributor

@rokhinip rokhinip commented Feb 13, 2022

This PR comes in 3 parts:

  1. A refactor of the actor runtime. This involves creating an ActiveActorStatus to isolate the status manipulations to its own class. In addition, the API surface of the actor runtime has been been simplified to remove extra bookkeeping that is not needed.
  2. Tracking the drainer identity in the ActiveActorStatus when the actor starts and stops running
  3. Priority escalation of thread when contention is observed in the actor runtime.

Rdar: rdar://86100521

@rokhinip rokhinip requested review from mikeash and rjmccall February 13, 2022 21:17
@rokhinip
Copy link
Contributor Author

@swift-ci please test


bool wasInlineJob() const {
return Kind == Inline;
}

static RunningJobInfo forOther(JobPriority priority) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since JobPriority of the processing job does not necessarily correlate to the priority of the actor we're processing, or the priority of the thread running that job (as a result of priority escalation that can happen asynchronously or as a result of self-overrides), I decided to remove it from this structured, since we can't make scheduling decisions based on this information.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 84a8e5f

@shahmishal
Copy link
Member

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 84a8e5f

job = new (&JobStorage) ProcessInlineJob(priority);
} else {
assert(false && "Should not be here - we don't have support for any OOL actor process jobs yet");
// TODO (rokhinip): Don't we need to take a +1 per ref count rules specified?
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds right. A comment pointing to the corresponding release would be handy.

currentActor->giveUpThread(runner);
}

// We are eliminating a processing job for the original actor, release it.
swift_release(actor);
Copy link
Contributor Author

@rokhinip rokhinip Feb 14, 2022

Choose a reason for hiding this comment

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

I'm actually about 80% certain that this is wrong to be here since we're only scheduling with inline jobs and we don't ever take extra ref counts on the actor since we don't create extra processing jobs.

Edit: Turns out we take a retain in ProcessInlineJob::process and ProcessOutOfLineJob::process so we need this release. But why do we need to take the retain there @rjmccall? Per your ownership rules, if anything it seems like we should be taking the retain at the time of scheduling the extra processing jobs?

@rokhinip rokhinip force-pushed the rokhinip/86100521-actor-runtime-escalation branch from 84a8e5f to 72d15f6 Compare February 15, 2022 00:30
@rokhinip
Copy link
Contributor Author

@swift-ci please test

@rokhinip rokhinip marked this pull request as ready for review February 15, 2022 00:40
@rokhinip rokhinip force-pushed the rokhinip/86100521-actor-runtime-escalation branch from 72d15f6 to 3865ae6 Compare February 16, 2022 02:16
@rokhinip
Copy link
Contributor Author

@swift-ci please test

@rokhinip rokhinip requested a review from mikeash February 16, 2022 02:17
}

// Only for static assert use below, not for actual use otherwise
static constexpr size_t offsetOfActiveActorStatus() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only way I could think of doing this since the class members are private and so the static_assert() was unhappy.

state of the actor similar to the ActiveTaskStatus. Refactor the default
actor runtime implementation to set us up for priority escalation
support

Radar-Id: rdar://problem/86100521
ActiveActorStatus

Radar-Id: rdar://problem/86100521
@rokhinip rokhinip force-pushed the rokhinip/86100521-actor-runtime-escalation branch from 3865ae6 to a3e3c3f Compare February 16, 2022 18:22
@rokhinip
Copy link
Contributor Author

@swift-ci please test

@rokhinip rokhinip merged commit 32e02fa into main Feb 17, 2022
@rokhinip rokhinip deleted the rokhinip/86100521-actor-runtime-escalation branch February 17, 2022 01:10
@rokhinip rokhinip restored the rokhinip/86100521-actor-runtime-escalation branch February 17, 2022 01:53
@compnerd compnerd deleted the rokhinip/86100521-actor-runtime-escalation branch May 31, 2025 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants