Skip to content

Conversation

@fcostaoliveira
Copy link
Collaborator

This PR adds ThreadSanitizer (TSAN) support to memtier_benchmark for detecting and preventing data races in multi-threaded code.

Changes

Build System

  • Added --enable-thread-sanitizer configure option
  • Mutually exclusive with --enable-sanitizers (ASAN/LSAN)
  • Automatically applies TSAN compiler flags: -fsanitize=thread -fno-omit-frame-pointer -O1

CI Integration

  • New GitHub Actions workflow (.github/workflows/tsan.yml)
  • Runs on all pushes and pull requests
  • Uses setarch -R to disable ASLR (required for TSAN on kernel 6.6+)
  • Tests OSS TCP, OSS TCP TLS, and OSS-CLUSTER configurations

Bug Fixes

  • Fixed data race on m_finished flag using std::atomic<bool>
  • Fixed data race on m_last_error in server_addr using std::atomic<int>
  • Both fixes have zero performance overhead on x86/x64

Suppressions

  • Added tsan_suppressions.txt for known benign data races
  • Suppresses races on stats counters used only for progress display
  • Final benchmark results remain race-free (collected after pthread_join)

Documentation

  • Updated README with TSAN build and test instructions
  • Documented suppression file usage
  • Added code comments explaining benign races

Testing

Build with TSAN:

./configure --enable-thread-sanitizer
make

Run tests with TSAN:

TSAN_OPTIONS="suppressions=$(pwd)/tsan_suppressions.txt" setarch `uname -m` -R ./tests/run_tests.sh

- Added --enable-thread-sanitizer configure option
- Added TSAN CI workflow with ASLR workaround for kernel 6.6+
- Fixed data race on m_finished flag using std::atomic<bool>
- Fixed data race on m_last_error using std::atomic<int>
- Added tsan_suppressions.txt for benign stats counter races
- Updated README with TSAN build and test instructions
paulorsousa
paulorsousa previously approved these changes Nov 17, 2025
Co-authored-by: Paulo Sousa <paulo.sousa@redis.com>
@fcostaoliveira fcostaoliveira merged commit 045f75b into RedisLabs:master Nov 17, 2025
15 checks passed
@fcostaoliveira fcostaoliveira deleted the tsan branch November 17, 2025 10:00
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