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

Prevent segmentation fault in sync and future caches, and also upgrade crossbeam-epoch to v0.9.9 #157

Merged
merged 6 commits into from
Jul 19, 2022

Conversation

tatsuya6502
Copy link
Member

@tatsuya6502 tatsuya6502 commented Jun 28, 2022

(Rewritten on July 19, 2022)

Changes

Prevent segmentation fault (use-after-free) in sync and future caches. (Fixes #34):

  • It was caused by race-conditions when many threads are concurrently rehashing (extending or shrinking) an internal hash table moka::cht:
    • Although the creator of the original cht designed the rehashing to work fine in such situation, it is not working as expected.
    • To fix it, add a lock to the rehash function to ensure only one thread can participate rehashing at a time.
  • To prevent potential inconsistency issues in non x86 based systems, strengthen the memory ordering used for compare_exchange_weak.
    • Before: Ordering::Release, meaning read: relaxed, write: release.
    • After: Ordering::AcqRel, meaning read: acquire, write: release.

Upgrade crossbeam-epoch from v0.8.2 to v0.9.9:

  • Upgrade crossbeam-epoch dependency in Cargo.toml from v0.8.2 to v0.9.9.
  • Replace deprecated compare_and_set_weak with compare_exchange_weak.

Testing

Ran mokabench with the following arguments several times and no segmentation fault occurred.

$ cargo run --release -- --insert-once --repeat 20

Notes:

  • For testing purpose, Modified Moka's code to reduce the number of internal segments of cht from 64 to 1.
    • This will make segfault to occur more often. e.g., without the fix, it occurred within 30 seconds on the Linux x86_64 environment below.
    • The above test took about 30 minutes on the same Linux x86_64 environment, and it no longer occurred after the fix.

Testing environment:

  • Linux x86_64 (WSL 2) on Intel Core i7-12700F CPU (20 logical cores)
  • macOS arm64 on Apple M1 chip (8 cores)

- Add a lock to the rehash function of the concurrent hash table (`moka::cht`) to
  ensure only one thread can participate rehashing at a time.
- To prevent potential inconsistency issues in non x86 based systems, strengthen the
  memory ordering used for `compare_exchange_weak` (`Release` to `AcqRel`).
@tatsuya6502 tatsuya6502 modified the milestones: v0.8.7, v0.9.2 Jul 19, 2022
@tatsuya6502 tatsuya6502 added the bug Something isn't working label Jul 19, 2022
@tatsuya6502 tatsuya6502 changed the title Upgrade crossbeam-epoch to v0.9.9 Prevent segmentation fault in sync and future caches, and also upgrade crossbeam-epoch to v0.9.9 Jul 19, 2022
@tatsuya6502
Copy link
Member Author

I added commit fc044d6, and it should solve #34 (segmentation faults).

To reflect the commit, I rewrote the summary and description of this PR.

@tatsuya6502 tatsuya6502 marked this pull request as ready for review July 19, 2022 10:32
Copy link
Member Author

@tatsuya6502 tatsuya6502 left a comment

Choose a reason for hiding this comment

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

Merging.

@tatsuya6502 tatsuya6502 merged commit 5240b94 into master Jul 19, 2022
@tatsuya6502 tatsuya6502 deleted the crossbeam-epoch-0.9 branch July 19, 2022 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation faults in moka-cht under heavy workloads on a many-core machine
1 participant