Skip to content
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

Work Stealing #48

Merged
merged 7 commits into from
Nov 21, 2024
Merged

Work Stealing #48

merged 7 commits into from
Nov 21, 2024

Conversation

mjp41
Copy link
Member

@mjp41 mjp41 commented Sep 6, 2024

During @vishalgupta97 internship we observed problems with the work stealing algorithm that if all the work was generated by a single scheduler thread, then the other threads had heavy contention in the stealing code. This is due to the stealing code only stealing a single item at a time.

There are a few papers that suggest stealing in larger units than single work items:

The suggestions is that stealing at most half of the work is sensible.

This PR changes the implementation of the scheduler queues to support a steal all operation. By providing N (N=4 in the PR) queues per scheduler thread, then we are able to steal approximately 1/4 of the work on a scheduler thread.

The PR adds a very simple benchmark where a single behaviour generates all the work in the system. Configured with 4 cores, we get

Before this PR:

Scheduled all work took:
        317 ms
Elapsed:
        606 ms

While with his PR:

Scheduled all work took:
        234 ms
Elapsed:
        251 ms

This is running on my laptop with just four cores, so bigger experiments should be undertaken.

There is also a lot of opportunity for further investigations, in terms of different strategies for stealing and scheduling work. This PR represents a simple position that improves the state of the system.

@mjp41
Copy link
Member Author

mjp41 commented Nov 20, 2024

@SchrodingerZhu I thought you might be interested in this PR. It is similar to things you have commented on for snmalloc.

This replaces the existing queue implementation with a new version that supports dequeue_all.

The dequeue_all will be used in a subsequent PR, which will implement a better work stealing algorithm.
This adds a fixed set of queues per core that are used in a round-robin fashion.  This allows more efficient stealing, which will be part of the next commit.
The new stealing mechanism can work with fairness, but works less well.  It is more likely that a steal will take the fairness token, and hence we get some less good behaviour.
@mjp41 mjp41 merged commit 7deb587 into microsoft:main Nov 21, 2024
8 checks passed
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.

1 participant