Skip to content

Commit 4ddae3a

Browse files
committed
librbd: Modify locks and atomics in AioCompletion to improve performance
Signed-off-by: Adam Lyon-Jones <[email protected]>
1 parent d557013 commit 4ddae3a

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

src/librbd/io/AioCompletion.cc

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ namespace io {
3333

3434
int AioCompletion::wait_for_complete() {
3535
tracepoint(librbd, aio_wait_for_complete_enter, this);
36-
{
37-
std::unique_lock<std::mutex> locker(lock);
38-
while (state != AIO_STATE_COMPLETE) {
39-
cond.wait(locker);
40-
}
41-
}
36+
completed.wait(false, std::memory_order_acquire);
4237
tracepoint(librbd, aio_wait_for_complete_exit, 0);
4338
return 0;
4439
}
@@ -237,7 +232,7 @@ void AioCompletion::complete_request(ssize_t r)
237232

238233
bool AioCompletion::is_complete() {
239234
tracepoint(librbd, aio_is_complete_enter, this);
240-
bool done = (this->state == AIO_STATE_COMPLETE);
235+
bool done = completed.load(std::memory_order_acquire);
241236
tracepoint(librbd, aio_is_complete_exit, done);
242237
return done;
243238
}
@@ -262,17 +257,14 @@ void AioCompletion::complete_external_callback() {
262257
}
263258

264259
void AioCompletion::mark_complete_and_notify() {
265-
state = AIO_STATE_COMPLETE;
260+
completed.store(true, std::memory_order_release);
266261

267262
if (ictx != nullptr && event_notify && ictx->event_socket.is_valid()) {
268263
ictx->event_socket_completions.push(this);
269264
ictx->event_socket.notify();
270265
}
271266

272-
{
273-
std::unique_lock<std::mutex> locker(lock);
274-
cond.notify_all();
275-
}
267+
completed.notify_all();
276268

277269
if (image_dispatcher_ctx != nullptr) {
278270
image_dispatcher_ctx->complete(rval);

src/librbd/io/AioCompletion.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,13 @@ namespace io {
3838
* context or via a thread pool context for cache read hits).
3939
*/
4040
struct AioCompletion {
41-
typedef enum {
42-
AIO_STATE_PENDING = 0,
43-
AIO_STATE_COMPLETE,
44-
} aio_state_t;
45-
4641
mutable std::mutex lock;
47-
std::condition_variable cond;
4842

4943
callback_t complete_cb = nullptr;
5044
void *complete_arg = nullptr;
5145
rbd_completion_t rbd_comp = nullptr;
5246

53-
/// note: only using atomic for built-in memory barrier
54-
std::atomic<aio_state_t> state{AIO_STATE_PENDING};
47+
std::atomic<bool> completed{false};
5548

5649
std::atomic<ssize_t> rval{0};
5750
std::atomic<int> error_rval{0};

0 commit comments

Comments
 (0)