Skip to content

Commit

Permalink
Hazard Pointer Reclamation - Unlock Tagged list faster
Browse files Browse the repository at this point in the history
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
  • Loading branch information
instw authored and facebook-github-bot committed Nov 30, 2023
1 parent 545179b commit 18a1822
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions folly/synchronization/HazptrDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,15 @@ class hazptr_domain {
int count = 0;
for (int s = 0; s < kNumShards; ++s) {
if (tagged[s]) {
ObjList match, nomatch;
list_match_condition(tagged[s], match, nomatch, [&](Obj* o) {
return hs.count(o->raw_ptr()) > 0;
});
ObjList nomatch;
{
ObjList match;
list_match_condition(tagged[s], match, nomatch, [&](Obj* o) {
return hs.count(o->raw_ptr()) > 0;
});
List l(match.head(), match.tail());
tagged_[s].push_unlock(l);
}
count += nomatch.count();
auto obj = nomatch.head();
while (obj) {
Expand All @@ -480,8 +485,6 @@ class hazptr_domain {
cohort->push_safe_obj(obj);
obj = next;
}
List l(match.head(), match.tail());
tagged_[s].push_unlock(l);
}
}
return count;
Expand Down

0 comments on commit 18a1822

Please sign in to comment.