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

Hazard Pointer Reclamation - Unlock Tagged list faster #2106

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

instw
Copy link

@instw instw commented Nov 30, 2023

Summary:
PROBLEM
During reclamation of tagged objects, we obtain a lock within the hazard pointer domain's tagged list. This list supports always pushing objects, but only allows popping when there is a lock (for tagged_).
There is opportunity to improve the performance of reclamation, by keeping the tagged_ list locked for a smaller amount of time.

SOLUTION
The list is locked to prevent multiple threads from reclaiming the same objects. During reclamation, we take all objects that are potentially cleaned up, and divide them into 2 parts: Those that must be reclaimed, and those that must not. The ones that are not are pushed back to the tagged_ list, and the list is unlocked. The objects to be reclaimed are freed - by pushing to the cohort.
The locking of list is to guard against the tagged_ list itself, and hence when we push the not-to-be-reclaimed elements back, we could theoretically release the lock without waiting for the reclaimed objects to finish being processed.
Also validated that the nomatch handling is thread-safe - The cohort's push_safe_obj uses as CAS loop to safely add to the top of the list.

Differential Revision: D51638674

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51638674

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51638674

instw pushed a commit to instw/folly that referenced this pull request Jan 22, 2024
Summary:

PROBLEM
During reclamation of tagged objects, we obtain a lock within the hazard pointer domain's tagged list. This list supports always pushing objects, but only allows popping when there is a lock (for `tagged_`).
There is opportunity to improve the performance of reclamation, by keeping the `tagged_` list locked for a smaller amount of time.

SOLUTION
The list is locked to prevent multiple threads from reclaiming the same objects. During reclamation, we take all objects that are potentially cleaned up, and divide them into 2 parts: Those that must be reclaimed, and those that must not. The ones that are not are pushed back to the `tagged_` list, and the list is unlocked. The objects to be reclaimed are freed - by pushing to the cohort.
The locking of list is to guard against the `tagged_` list itself, and hence when we push the not-to-be-reclaimed elements back, we could theoretically release the lock without waiting for the reclaimed objects to finish being processed.
Also validated that the `nomatch` handling is thread-safe - The cohort's `push_safe_obj` uses as CAS loop to safely add to the top of the list.
Would multiple copies of an object be pushed into a cohort? No - An object is either in the retirement list (i.e. list) in the cohort, or it's been processed for reclamation. This guarantee already exists (the diff doesn't change that). This means the only way multiple copies of an object can be pushed back to the safe list is if we end up clearing the `tagged_` list within the domain - which is the synchronization / shared memory point. Since we do dequeue and enqueue of that list under a lock, an object should would never appear on that list. The only (shared object) change is around addition to the cohort's safe list, which is meant to be thread-safe.

Reviewed By: yfeldblum

Differential Revision: D51638674
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51638674

1 similar comment
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51638674

instw pushed a commit to instw/folly that referenced this pull request Jan 23, 2024
Summary:

PROBLEM
During reclamation of tagged objects, we obtain a lock within the hazard pointer domain's tagged list. This list supports always pushing objects, but only allows popping when there is a lock (for `tagged_`).
There is opportunity to improve the performance of reclamation, by keeping the `tagged_` list locked for a smaller amount of time.

SOLUTION
The list is locked to prevent multiple threads from reclaiming the same objects. During reclamation, we take all objects that are potentially cleaned up, and divide them into 2 parts: Those that must be reclaimed, and those that must not. The ones that are not are pushed back to the `tagged_` list, and the list is unlocked. The objects to be reclaimed are freed - by pushing to the cohort.
The locking of list is to guard against the `tagged_` list itself, and hence when we push the not-to-be-reclaimed elements back, we could theoretically release the lock without waiting for the reclaimed objects to finish being processed.
Also validated that the `nomatch` handling is thread-safe - The cohort's `push_safe_obj` uses as CAS loop to safely add to the top of the list.
Would multiple copies of an object be pushed into a cohort? No - An object is either in the retirement list (i.e. list) in the cohort, or it's been processed for reclamation. This guarantee already exists (the diff doesn't change that). This means the only way multiple copies of an object can be pushed back to the safe list is if we end up clearing the `tagged_` list within the domain - which is the synchronization / shared memory point. Since we do dequeue and enqueue of that list under a lock, an object should would never appear on that list. The only (shared object) change is around addition to the cohort's safe list, which is meant to be thread-safe.

Reviewed By: yfeldblum

Differential Revision: D51638674
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51638674

Summary:
Pull Request resolved: facebook#2106

PROBLEM
During reclamation of tagged objects, we obtain a lock within the hazard pointer domain's tagged list. This list supports always pushing objects, but only allows popping when there is a lock (for `tagged_`).
There is opportunity to improve the performance of reclamation, by keeping the `tagged_` list locked for a smaller amount of time.

SOLUTION
The list is locked to prevent multiple threads from reclaiming the same objects. During reclamation, we take all objects that are potentially cleaned up, and divide them into 2 parts: Those that must be reclaimed, and those that must not. The ones that are not are pushed back to the `tagged_` list, and the list is unlocked. The objects to be reclaimed are freed - by pushing to the cohort.
The locking of list is to guard against the `tagged_` list itself, and hence when we push the not-to-be-reclaimed elements back, we could theoretically release the lock without waiting for the reclaimed objects to finish being processed.
Also validated that the `nomatch` handling is thread-safe - The cohort's `push_safe_obj` uses as CAS loop to safely add to the top of the list.
Would multiple copies of an object be pushed into a cohort? No - An object is either in the retirement list (i.e. list) in the cohort, or it's been processed for reclamation. This guarantee already exists (the diff doesn't change that). This means the only way multiple copies of an object can be pushed back to the safe list is if we end up clearing the `tagged_` list within the domain - which is the synchronization / shared memory point. Since we do dequeue and enqueue of that list under a lock, an object should would never appear on that list. The only (shared object) change is around addition to the cohort's safe list, which is meant to be thread-safe.

Reviewed By: yfeldblum

Differential Revision: D51638674
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51638674

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants