From 5b94fbc4eab347f8502d976fcbe54773672f82a2 Mon Sep 17 00:00:00 2001 From: Wang Hongxu Date: Tue, 28 Aug 2018 14:51:58 +0800 Subject: [PATCH] BlueStore: Fix concurrency conflicts When the last two IOs of the same Context return at the same time, their num_running may be 2 at the same time, causing the thread to not be woken up, eventually resulting in a timeout. Signed-off-by: Wang Hongxu --- src/os/bluestore/BlockDevice.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/os/bluestore/BlockDevice.h b/src/os/bluestore/BlockDevice.h index 262619919c48..c34fde385854 100644 --- a/src/os/bluestore/BlockDevice.h +++ b/src/os/bluestore/BlockDevice.h @@ -77,7 +77,8 @@ public: uint64_t get_num_ios() const; void try_aio_wake() { - if (num_running == 1) { + assert(num_running >= 1); + if (num_running.fetch_sub(1) == 1) { // we might have some pending IOs submitted after the check // as there is no lock protection for aio_submit. @@ -85,10 +86,6 @@ public: // aio_wait has to handle that hence do not care here. std::lock_guard l(lock); cond.notify_all(); - --num_running; - ceph_assert(num_running >= 0); - } else { - --num_running; } } -- 2.47.3