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

Fix TSAN warnings with AtomicFreeList #8270

Merged
merged 1 commit into from
Nov 14, 2024
Merged

Fix TSAN warnings with AtomicFreeList #8270

merged 1 commit into from
Nov 14, 2024

Conversation

pixelflinger
Copy link
Collaborator

I do not think there was an actual error with AtomicFreeList, however TSAN detected a data race when concurrent pop() happened. In that case, there is indeed a race, where we can end-up reading data that is already corrupted by the concurrent pop. However, that situation is corrected by the following CAS. Somehow TSAN didn't see that. The fix is strange and consists in replacing:

auto pNext = storage[offset].next;

with

auto s = storage[offset];
auto pNext = s.next;

In this PR we also adjust the memory ordering to be less strong. i.e. we do not need memory_order_seq_cst, only the appropriate acquire or release semantic.

In addition we also make Node* next a non-atomic variable again. It should have been, but was change to placate an older version of TSAN.

BUGS=[377369108]

I do not think there was an actual error with AtomicFreeList, however
TSAN detected a data race when concurrent pop() happened. In that case,
there is indeed a race, where we can end-up reading data that is
already corrupted by the concurrent pop. However, that situation is
corrected by the following CAS. Somehow TSAN didn't see that.
The fix is strange and consists in replacing:
```
auto pNext = storage[offset].next;
```

with

```
auto s = storage[offset];
auto pNext = s.next;
```

In this PR we also adjust the memory ordering to be less strong. i.e.
we do not need `memory_order_seq_cst`, only the appropriate acquire or
release semantic.

In addition we also make `Node* next` a non-atomic variable again. It
should have been, but was change to placate an older version of TSAN.

BUGS=[377369108]
@pixelflinger pixelflinger added the internal Issue/PR does not affect clients label Nov 12, 2024
@pixelflinger pixelflinger merged commit d075a87 into main Nov 14, 2024
13 checks passed
@pixelflinger pixelflinger deleted the ma/tsan-fix branch November 14, 2024 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Issue/PR does not affect clients
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants