Skip to content

common: fix races when visiting a TrackedOp. - #22877

Merged
liewegas merged 1 commit into
ceph:masterfrom
rzarzynski:wip-bug-24664-2
Jul 12, 2018
Merged

liewegas merged 1 commit into
ceph:masterfrom
rzarzynski:wip-bug-24664-2

Conversation

@rzarzynski

Copy link
Copy Markdown
Contributor

@rzarzynski
rzarzynski requested a review from badone July 5, 2018 14:41
@rzarzynski
rzarzynski force-pushed the wip-bug-24664-2 branch 2 times, most recently from 6198545 to 4caa945 Compare July 5, 2018 15:09

@badone badone left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@rzarzynski
rzarzynski requested a review from liewegas July 6, 2018 14:39
@rzarzynski

Copy link
Copy Markdown
Contributor Author

The alternative patch I'm not satisfied with is: rzarzynski@6e98f7c.

Comment thread src/common/TrackedOp.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of this mess of changes to unregister_inflight_op(), can we just move everything from if (!tracking_enabled) into the caller? There is only one caller, and having this inside the function makes its name misleading (it's not just unregistering but conditionally either deleting or reregistering elsewhere). I find it very unsettling to have a ref to the object (ri at the top) and also detach+delete.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, having delete and the re-registration part is uncomfortable at best even without the extra complexity of Ref. I'm going to make a small clean-up in a separated commit for the sake of backportability.

@liewegas

liewegas commented Jul 6, 2018

Copy link
Copy Markdown
Member

I'm not sure I understand the race. I thought it was between the visitor and the nref changing from 1 -> 0 -> 1, but the visitor holds the shard lock the whole time. So, it could see an op that when from 1 -> 0 and hasn't been deregistered yet, and skip it--that's fine. But I don't see a problem with going from 0 -> 1 because it would have already been removed from the shard's list...

@rzarzynski

Copy link
Copy Markdown
Contributor Author

@liewegas: I considered following nasty scenario:

A           : OpTracker::visit_ops_in_flight(..., callable leaking TrackedOpRef outside)
A           : Mutex::Locker::Locker(sdata->ops_in_flight_lock_sharded)
A with lock : (nref > 0) == true

B           : TrackedOp::put(), nref := 0 // updating the counter is done without the lock
B           : OpTracker::unregister_inflight_op()
B           : Mutex::Locker::Locker(sdata->ops_in_flight_lock_sharded)

A with lock : visit() -> TrackedOp::get(), nref := 1
A with lock : Mutex::Locker::~Locker()

B with lock : boost::intrusive::list::iterator_to(op)
B with lock : boost::intrusive::list::erase(iter)
B with lock : Mutex::Locker::~Locker()

A           : TrackedOp::put(), nref := 0
A           : OpTracker::unregister_inflight_op()
A           : Mutex::Locker::Locker(sdata->ops_in_flight_lock_sharded)
A with lock : boost::intrusive::list::iterator_to(op) // oops as op doesn't belong to the list anymore

@rzarzynski
rzarzynski force-pushed the wip-bug-24664-2 branch 2 times, most recently from 3bb87f2 to 21f0496 Compare July 9, 2018 14:47
@rzarzynski

Copy link
Copy Markdown
Contributor Author

@liewegas: just squashed.

@liewegas liewegas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good to me!

@liewegas

Copy link
Copy Markdown
Member
    -2> 2018-07-10 02:39:01.628 7fa7414918c0 -1 /build/ceph-14.0.0-1224-g0087bf8/src/common/TrackedOp.cc: In function 'OpTracker::~OpTracker()' thread 7fa7414918c0 time 2018-07-10 02:39:01.634029
/build/ceph-14.0.0-1224-g0087bf8/src/common/TrackedOp.cc: 163: FAILED assert((sharded_in_flight_list.back())->ops_in_flight_sharded.empty())

 ceph version 14.0.0-1224-g0087bf8 (0087bf835dfd0670408c4d798f595d99ff3cbe26) nautilus (dev)
 1: (ceph::__ceph_assert_fail(char const*, char const*, int, char const*)+0x14e) [0x56268cbca22e]
 2: (()+0xaea3b7) [0x56268cbca3b7]
 3: (()+0x7c65eb) [0x56268c8a65eb]
 4: (OSD::~OSD()+0x513) [0x56268c65af53]
 5: (OSD::~OSD()+0x9) [0x56268c65b419]

in /a/sage-2018-07-10_00:40:55-rados-wip-sage3-testing-2018-07-09-1727-distro-basic-smithi/2759788

Comment thread src/common/TrackedOp.h Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is a race between the load() and --nref in the new else clause. Need to recheck in a loop.

Before the commit following race can happen:
  ```
  A           : OpTracker::visit_ops_in_flight(..., callable leaking TrackedOpRef outside)
  A           : Mutex::Locker::Locker(sdata->ops_in_flight_lock_sharded)
  A with lock : (nref > 0) == true

  B           : TrackedOp::put(), nref := 0 // updating the counter is done without the lock
  B           : OpTracker::unregister_inflight_op()
  B           : Mutex::Locker::Locker(sdata->ops_in_flight_lock_sharded)

  A with lock : visit() -> TrackedOp::get(), nref := 1
  A with lock : Mutex::Locker::~Locker()

  B with lock : boost::intrusive::list::iterator_to(op)
  B with lock : boost::intrusive::list::erase(iter)
  B with lock : Mutex::Locker::~Locker()

  A           : TrackedOp::put(), nref := 0
  A           : OpTracker::unregister_inflight_op()
  A           : Mutex::Locker::Locker(sdata->ops_in_flight_lock_sharded)
  A with lock : boost::intrusive::list::iterator_to(op) // oops as op doesn't belong to the list anymore
  ```

Fixes: https://tracker.ceph.com/issues/24664
Related-To: https://tracker.ceph.com/issues/24037
Signed-off-by: Radoslaw Zarzynski <[email protected]>

@gregsfortytwo gregsfortytwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed-by: Greg Farnum [email protected]

@liewegas
liewegas merged commit 871cbf0 into ceph:master Jul 12, 2018
liewegas added a commit that referenced this pull request Jul 12, 2018
* refs/pull/22877/head:
	common: fix races when visiting a TrackedOp.

Reviewed-by: Brad Hubbard <[email protected]>
Reviewed-by: Sage Weil <[email protected]>
Reviewed-by: Gregory Farnum <[email protected]>
Reviewed-by: Greg Farnum <[email protected]>
@rzarzynski

Copy link
Copy Markdown
Contributor Author

Performance comparison

All tests have been conducted on the incerta07 node in 5 rounds. The result for each round is sum of bandwidth 4 separated FIO-librbd clients get from a cluster consisted of 3 OSDs . CBT has been used for deployment and orchestration. Values are in KBps.

On average for 4 KiB and 64 KiB randreads respectively:

>>> (377443. + 380011 + 382396 + 375046 +  382870)/(376844 + 375004 + 375534 + 382742 + 378275) * 100
100.49602864648837
>>> (3635133 + 3580268 + 3568959 + 3540768 + 3558203.)/(3565172 + 3554422 + 3569961 + 3354016 + 3638335) * 100
101.13915886669685

The reference point: 910f3ae

randread,  4 KiB:  376844,  375004,  375534,  382742,  378275
randread, 64 KiB: 3565172, 3554422, 3569961, 3354016, 3638335

The merge point: 360211e

randread,  4 KiB:  377443,  380011,  382396,  375046,  382870
randread, 64 KiB: 3635133, 3580268, 3568959, 3540768, 3558203

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.

4 participants