]> git.apps.os.sepia.ceph.com Git - ceph.git/commit
mds: switch mds_lock to fair mutex 43148/head
authorXiubo Li <xiubli@redhat.com>
Mon, 2 Aug 2021 03:53:37 +0000 (11:53 +0800)
committerXiubo Li <xiubli@redhat.com>
Mon, 13 Sep 2021 06:30:56 +0000 (14:30 +0800)
commit140c35ab20a54d67c8090f15709c1944e30d110f
tree9e328b76d6ad65d0ed84c1039c2fbd103332f849
parentd38d68f39a4a757e31847e710649f7e3c31ba0d8
mds: switch mds_lock to fair mutex

The implementations of the Mutex (e.g. std::mutex in C++) do not
guarantee fairness, they do not guarantee that the lock will be
acquired by threads in the order that they called the lock().

In most case this works well, but in corner case in the Finisher
thread in mds daemon, which may call more than one complete()s
once the mdlog flushing succeeds, after the mdlog flushing is done
it will call the queued complete callbacks and the Finisher thread
could always successfully acquire the mds_lock in successive
complete callbakcs even there may have other threads already being
stuck waiting the mds_lock. This will make the other threads starve
and if they are client's requests, it will cause several or even
tens of seconds long delay for user's operations.

This will switch the mds_lock to fair mutex and it could make sure
that the all the mds_lock waiters are in FIFO order and the Finisher
thread won't hold the mds_lock that long.

At the same time, if the finisher thread has many completes needed
to run the fair mutex could guarantee that the finisher won't be
scheduled out due to fair mutex unlock() if no any other mds_lock
waiter queued.

Fixes: https://tracker.ceph.com/issues/51722
Signed-off-by: Xiubo Li <xiubli@redhat.com>
(cherry picked from commit 5ade254c15d0b9f96cdd5cd2d5f7861ef2232812)

 Conflicts:
src/mds/MDSRank.cc
src/mds/MDSRank.h
src/mds/MDSDaemon.h
src/mds/MDSRank.cc
src/mds/MDSRank.h