facebook / facebook/rocksdb

WriteThread::AwaitState PAUSE spin-loop needs investigation

Open
#4,086 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
32.1k
Forks
6.9k
Avg merge
32m
Merged PRs (30d)
1

Description

[`WriteThread::AwaitState`](https://github.com/facebook/rocksdb/blob/master/db/write_thread.cc#L61-L75) contains the following block of code:

```c++
// 1. Busy loop using "pause" for 1 micro sec
// 2. Else SOMETIMES busy loop using "yield" for 100 micro sec (default)
// 3. Else blocking wait

// On a modern Xeon each loop takes about 7 nanoseconds (most of which
// is the effect of the pause instruction), so 200 iterations is a bit
// more than a microsecond. This is long enough that waits longer than
// this can amortize the cost of accessing the clock and yielding.
for (uint32_t tries = 0; tries < 200; ++tries) {
state = w->state.load(std::memory_order_acquire);
if ((state & goal_mask) != 0) {
return state;
}
port::AsmVolatilePause();
}
```

The comment about the duration of each loop iteration is incorrect on recent Intel microarchitectures. The pause instruction changed from taking single-digit nanoseconds to 43 nanoseconds. See [this blog post](https://aloiskraus.wordpress.com/2018/06/16/why-skylakex-cpus-are-sometimes-50-slower-how-intel-has-broken-existing-code/) for more details.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.