Skip to content

crimson/common/tri_mutex: make locking/promotion atomic if possible - #56844

Merged
cyx1231st merged 4 commits into
ceph:mainfrom
cyx1231st:wip-crimson-fix-tri-mutex
Apr 26, 2024
Merged

cyx1231st merged 4 commits into
ceph:mainfrom
cyx1231st:wip-crimson-fix-tri-mutex

Conversation

@cyx1231st

@cyx1231st cyx1231st commented Apr 12, 2024 •

Copy link
Copy Markdown
Member

Fixes: https://tracker.ceph.com/issues/65451
Signed-off-by: Yingxin Cheng [email protected]

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

@cyx1231st
cyx1231st requested a review from a team as a code owner April 12, 2024 02:18
Comment thread src/crimson/osd/object_context.h Outdated

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.

the commit message is missing the problem description, the root cause analysis, and the summary of this change. could you please elaborate a little bit on the root cause of

tri_mutex::promote_from_read(): Assertion `readers == 1' failed.

and how this change addresses this problem?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

My understanding see #55488 (comment) that caused writers == 1 failure.

I think the issue is similar that func (to promote and load-obc) isn't called immediately upon the 1st locked. The returned future allows the 2nd reader enter and lock (causing readers > 1) even the future is available, before func is called.

Making lock() to return nullopt instead of a ready future in this change makes the 1st locking and calling func atomic.

Note that we have fixed several issues related to out-of-order and ready future.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added more information in the commit message.

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.

I don't see how this actually helps. The bulk of the changes here allow for the various lock invocations to dynamically return std::nullopt allowing us to take the else branch of the if statement above

      return seastar::futurize_invoke(func
      ).finally([&lock, obc] {
        lock.unlock();
      });

That only solves the atomicity problem it if actually happens to return std::nullopt, though. For this to be an actual solution, we'd have to know statically that it really will. In that case, why allow the function to return a non-ready future at all?

I think this is essentially symmetric to the other similar PR that attempted to return a std::optional<future<>> -- the right solution is to identify why we are confident that a particular pathway doesn't need to block and directly call a variant that will never block.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I see, if my understanding is correct above, we should be able to convert read/write promotion to a non-block version, will try.

BTW, the test with the current change looks passing, see #56912 (comment)

@cyx1231st cyx1231st Apr 17, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The original promotion is already synchronous, so spcialize _with_promotion() to make sure the function is always called atomically instead of optional.

Proceed to tests.

Comment thread src/crimson/common/tri_mutex.h Resolved
@cyx1231st
cyx1231st force-pushed the wip-crimson-fix-tri-mutex branch 2 times, most recently from 99b35f8 to b47381d Compare April 15, 2024 03:41
@cyx1231st

Copy link
Copy Markdown
Member Author

jenkins test api

@cyx1231st

Copy link
Copy Markdown
Member Author

jenkins test api

@cyx1231st
cyx1231st force-pushed the wip-crimson-fix-tri-mutex branch from b47381d to eb9fead Compare April 17, 2024 08:50

@athanatos athanatos 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.

Yeah, that's simpler.

@cyx1231st

Copy link
Copy Markdown
Member Author

jenkins retest this please

Comment thread src/crimson/common/tri_mutex.h Resolved
Comment thread src/crimson/common/tri_mutex.h Resolved
@cyx1231st
cyx1231st force-pushed the wip-crimson-fix-tri-mutex branch from eb9fead to c819baf Compare April 19, 2024 03:38
Comment thread src/crimson/common/tri_mutex.cc Outdated

@tchaikov tchaikov Apr 19, 2024 •

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.

why are we including this header?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's for seastar::now().

Comment thread src/crimson/common/tri_mutex.cc Outdated

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.

this change does not belong to this commit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

splitted

Comment thread src/crimson/osd/object_context.h Outdated

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.

i understand that we've been putting & near the variable. but & is part of the type, see https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines for more examples, so..

Comment thread src/crimson/osd/object_context.h Outdated
Comment on lines 136 to 140

@tchaikov tchaikov Apr 19, 2024 •

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.

probably could put something like

template <typename Mutex, typename Func>
auto _with_lock(Mutex& mutex, Func&& func) {
    Ref obc{this};
    const std::lock_guard<Mutex> lock{mutex};
    co_return co_await seastar::futurize_invoke(func);
}

?
IMHO, no need to use the concept for enforcing the type constraints. because future<> cannot be discarded with [[nodiscard]] attribute. i think SFINAE should work here, so no need to use a new name, unless we need to make it more visible. but for what reason?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Seems not working directly:

/root/ceph/src/crimson/osd/object_context.h:138:15: error: ‘co_await’ cannot be used in a function with a deduced return type
  138 |     co_return co_await seastar::futurize_invoke(func);
      |               ^~~~~~~~
/root/ceph/src/crimson/osd/object_context.h:135:8: error: unable to find the promise type for this coroutine
  135 |   auto _with_promoted_lock(Mutex& mutex, Func&& func) {

Will fallback to the original version.

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.

thanks. will try to come up with a followup.

Comment thread src/crimson/common/tri_mutex.h Outdated
Comment on lines 11 to 13

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.

if we have to add a concept for BasicLockable. might want to put something like:

template<typename Mutex>
concept basic_lockable = requires(Mutex m) {
    { m.lock()   } -> std::same_as<void>;
    { m.unlock() } -> std::same_as<void>;
};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Discarded the concept.

@tchaikov

tchaikov commented Apr 19, 2024 •

Copy link
Copy Markdown
Contributor

left a couple comment. also, could s/if available/if possible/ or s/if available/when appropriate/ in the title of this PR.

@cyx1231st cyx1231st changed the title crimson/common/tri_mutex: make locking/promotion atomic if available crimson/common/tri_mutex: make locking/promotion atomic if possible Apr 19, 2024
@cyx1231st
cyx1231st force-pushed the wip-crimson-fix-tri-mutex branch 2 times, most recently from 4136c2d to caf8983 Compare April 19, 2024 06:59
Specifically, make promotion atomic with load-obc to fix
assert(readers/writers == 1) failures.

Fixes: https://tracker.ceph.com/issues/65451
Signed-off-by: Yingxin Cheng <[email protected]>
@cyx1231st
cyx1231st force-pushed the wip-crimson-fix-tri-mutex branch from caf8983 to 676947e Compare April 19, 2024 07:02
@cyx1231st

Copy link
Copy Markdown
Member Author

jenkins test api

@tchaikov tchaikov 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

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