s/Mutex/ceph::mutex/ and Mutex::is_locked_by_me()
hi Patrick and list, i am trying replace Mutex with ceph::mutex in Ceph. the goal is to deprecate and then remove Mutex and Cond from our project. as we have already ceph::mutex and ceph::condition_variable. it's confusing and, in the long run, i think, it will hurt us as a technical debt. most of the refactory work is quite straightforward, and we can always replace Mutex::is_locked_by_me() with ceph_mutex_is_locked_by_me(). this macro will be expanded to `true` in release build. as we think it will be used only by `ceph_assert()` and `assert()`. but i realized that we are also using Mutex::is_locked_by_me() in functional code which won't be optimised out. for instance, in MDSRank::MDSRank() we check "mds_lock.is_locked_by_me()", if it's true, we just `handle_write_error(r)` without acquiring the lock, otherwise, we will call this function within `mds_lock`. the same applies to `MDSDaemon::handle_conf_change()`. so i am wondering if it's okay to change `mds_lock` to a recursive lock, so we don't need to query this information from the mutex. what do you think? -- Regards Kefu Chai
On 08/07/2019, kefu chai wrote: [snip]
hi Patrick and list, but i realized that we are also using Mutex::is_locked_by_me() in functional code which won't be optimised out. for instance, in MDSRank::MDSRank() we check "mds_lock.is_locked_by_me()", if it's true, we just `handle_write_error(r)` without acquiring the lock, otherwise, we will call this function within `mds_lock`. the same applies to `MDSDaemon::handle_conf_change()`. so i am wondering if it's okay to change `mds_lock` to a recursive lock, so we don't need to query this information from the mutex. [snip]
When I've converted code doing that, I've passed in a std::unique_lock reference in to the function so it could inspect/modify the hold the caller has on the lock. I'd use a recurisve mutex if there's likely to be a lot of functions called between where the mutex is acquired and where we care about whether it has been acquired to avoid having to pass them around between lots of unrelated functions, though. -- Adam C. Emerson https://people.redhat.com/~aemerson/ Senior Software Engineer, Red Hat Storage they/them/their aemerson@redhat.com IRC: Aemerson{RedHat,OFTC}, Actinic@Freenode 0x80F7544B90EDBFB9 E707 86BA 0C1B 62CC 152C 7C12 80F7 544B 90ED BFB9
On Sun, Jul 7, 2019 at 11:32 PM kefu chai <tchaikov@gmail.com> wrote:
hi Patrick and list,
i am trying replace Mutex with ceph::mutex in Ceph. the goal is to deprecate and then remove Mutex and Cond from our project. as we have already ceph::mutex and ceph::condition_variable. it's confusing and, in the long run, i think, it will hurt us as a technical debt.
most of the refactory work is quite straightforward, and we can always replace Mutex::is_locked_by_me() with ceph_mutex_is_locked_by_me(). this macro will be expanded to `true` in release build. as we think it will be used only by `ceph_assert()` and `assert()`.
but i realized that we are also using Mutex::is_locked_by_me() in functional code which won't be optimised out. for instance, in MDSRank::MDSRank() we check "mds_lock.is_locked_by_me()", if it's true, we just `handle_write_error(r)` without acquiring the lock, otherwise, we will call this function within `mds_lock`. the same applies to `MDSDaemon::handle_conf_change()`. so i am wondering if it's okay to change `mds_lock` to a recursive lock, so we don't need to query this information from the mutex.
what do you think?
handle_conf_change should be easy enough to fix by using a finisher context like we do for the Monitor. handle_write_error() is trickier because we can't easily pass the locker down the stack since it's a callback from the osdc/Journaler. I think we can find a way to avoid this issue via some reworking; a recursive mutex is not really desirable to resolve this one edge-case. I'll create a tracker for this. -- Patrick Donnelly, Ph.D. He / Him / His Senior Software Engineer Red Hat Sunnyvale, CA GPG: 19F28A586F808C2402351B93C3301A3E258DD79D
On Mon, Jul 8, 2019 at 9:49 AM Patrick Donnelly <pdonnell@redhat.com> wrote:
I'll create a tracker for this.
https://tracker.ceph.com/issues/40695 https://tracker.ceph.com/issues/40694 Nearly done working on 40694. -- Patrick Donnelly, Ph.D. He / Him / His Senior Software Engineer Red Hat Sunnyvale, CA GPG: 19F28A586F808C2402351B93C3301A3E258DD79D
On Wed, Jul 10, 2019 at 4:03 AM Patrick Donnelly <pdonnell@redhat.com> wrote:
On Mon, Jul 8, 2019 at 9:49 AM Patrick Donnelly <pdonnell@redhat.com> wrote:
I'll create a tracker for this.
https://tracker.ceph.com/issues/40695 https://tracker.ceph.com/issues/40694
Nearly done working on 40694.
thank you for your help Patrick! will rebase my huge patch against Venky's and your changes once they're finished.
-- Patrick Donnelly, Ph.D. He / Him / His Senior Software Engineer Red Hat Sunnyvale, CA GPG: 19F28A586F808C2402351B93C3301A3E258DD79D
-- Regards Kefu Chai
On Tue, Jul 9, 2019 at 8:23 PM kefu chai <tchaikov@gmail.com> wrote:
On Wed, Jul 10, 2019 at 4:03 AM Patrick Donnelly <pdonnell@redhat.com> wrote:
On Mon, Jul 8, 2019 at 9:49 AM Patrick Donnelly <pdonnell@redhat.com> wrote:
I'll create a tracker for this.
https://tracker.ceph.com/issues/40695 https://tracker.ceph.com/issues/40694
Nearly done working on 40694.
thank you for your help Patrick! will rebase my huge patch against Venky's and your changes once they're finished.
i40694 is resolved. Zheng is working on i40695. (Venky is on PTO.) -- Patrick Donnelly, Ph.D. He / Him / His Senior Software Engineer Red Hat Sunnyvale, CA GPG: 19F28A586F808C2402351B93C3301A3E258DD79D
On Mon, Jul 15, 2019 at 10:05 PM Patrick Donnelly <pdonnell@redhat.com> wrote:
On Tue, Jul 9, 2019 at 8:23 PM kefu chai <tchaikov@gmail.com> wrote:
On Wed, Jul 10, 2019 at 4:03 AM Patrick Donnelly <pdonnell@redhat.com> wrote:
On Mon, Jul 8, 2019 at 9:49 AM Patrick Donnelly <pdonnell@redhat.com> wrote:
I'll create a tracker for this.
https://tracker.ceph.com/issues/40695 https://tracker.ceph.com/issues/40694
Nearly done working on 40694.
thank you for your help Patrick! will rebase my huge patch against Venky's and your changes once they're finished.
i40694 is resolved. Zheng is working on i40695. (Venky is on PTO.)
Thanks Patrick!! will send out the s/Mutex/ceph::mutex/ change for review next week.
-- Patrick Donnelly, Ph.D. He / Him / His Senior Software Engineer Red Hat Sunnyvale, CA GPG: 19F28A586F808C2402351B93C3301A3E258DD79D
-- Regards Kefu Chai
participants (3)
-
Adam C. Emerson
-
kefu chai
-
Patrick Donnelly