Skip to content

mgr, mon, osdc: pass complex parameters by rvalue reference#65014

Merged
MaxKellermann merged 1 commit intoceph:mainfrom
MaxKellermann:mgr_mon_osdc__references
Nov 10, 2025
Merged

mgr, mon, osdc: pass complex parameters by rvalue reference#65014
MaxKellermann merged 1 commit intoceph:mainfrom
MaxKellermann:mgr_mon_osdc__references

Conversation

@MaxKellermann
Copy link
Member

A non-trivial type is always passed by reference, even if the parameter is declared as a value; in that case, the compiler must allocate stack space and move the value there, and then really passes a reference to this stack allocation. This only adds overhead for no reason.

A side effect of this API change is that all callers that accidently created temporary copies are now revealed by throwing a compiler error. This commit fixes all callers and reduces a good amount of useless overhead by wrapping those parameters in std::move() instead of copying temporaries.

More temporaries are avoided by emplacing the std::string&& into the std::vector.

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

@MaxKellermann
Copy link
Member Author

jenkins test make check arm64

1 similar comment
@MaxKellermann
Copy link
Member Author

jenkins test make check arm64

@MaxKellermann
Copy link
Member Author

arm64 keeps crashing with SIGBUS, but I don't think that's related.... so I keep repeating the test run! Sigh.

@MaxKellermann
Copy link
Member Author

jenkins test make check arm64

1 similar comment
@MaxKellermann
Copy link
Member Author

jenkins test make check arm64

@MaxKellermann
Copy link
Member Author

so I keep repeating the test run!

That strategy has worked, yet again.

@adamemerson adamemerson self-assigned this Aug 15, 2025
@github-actions
Copy link

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

dout(10) << __func__ << " Removing Key: " << *key
<< " for " << osd << " from Mon db" << dendl;
monc->start_mon_command(vcmd, {}, nullptr, nullptr, nullptr);
monc->start_mon_command({std::move(cmd)}, {}, nullptr, nullptr, nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't you changing more than the value category here (i.e. by moving from a vector to a single string)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand. What do you think is changed here? What is a "value category"?

Copy link
Contributor

Choose a reason for hiding this comment

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

(value category: lvalue, rvalue, etc.)
I was ref'ing the change that replaced the vector of strings with one string (which seemed to be unrelated)

Copy link
Contributor

Choose a reason for hiding this comment

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

And - a general question: as you are changing some 'const A&' to 'A&': did you run a static analyzer to verify that no 'use after move' instances were created?

Copy link
Member Author

Choose a reason for hiding this comment

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

that replaced the vector of strings with one string (which seemed to be unrelated)

I did not replace a vector or strings with one string. Maybe you missed the curly braces?

Copy link
Member Author

Choose a reason for hiding this comment

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

And - a general question: as you are changing some 'const A&' to 'A&': did you run a static analyzer to verify that no 'use after move' instances were created?

No, I don't have a static analyzer. But I did not change const A& to A&, but const A& to A&&.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I don't have a static analyzer. But I did not change const A& to A&, but const A& to A&&.

Sure - that's what I meant. Sorry. The question is this: the original signature of a function such as that had guaranteed that the argument won't be changed. Now - it was moved-from. Are you sure there are no cases where the client did use the argument? I tried to follow some of the cases, but a static analyzer is better at that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I did not replace a vector or strings with one string. Maybe you missed the curly braces?

Yes - I did miss that, but now I wonder what will happen there. Going to check.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you sure there are no cases where the client did use the argument?

I checked all changes (by code review, not by running them - I don't have any Ceph installation that I can use to test this), and I'm confident that they are correct. Minus human mistakes, as always.

Copy link
Contributor

Choose a reason for hiding this comment

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

(I assume you have this working, but - if you need help running a vstart configuration - let me know)

@ronen-fr
Copy link
Contributor

a final comment for now: as it is now, this PR spans 3 teams, which might make its approval into a lengthy process.

@MaxKellermann
Copy link
Member Author

a final comment for now: as it is now, this PR spans 3 teams, which might make its approval into a lengthy process.

Everything with Ceph is a lengthy process! At the current rate, it will take a decade or two until all my finished patches are merged. I have hundreds on my stgit stack, only waiting for dependent PRs to get merged.

@github-actions
Copy link

github-actions bot commented Sep 8, 2025

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@MaxKellermann
Copy link
Member Author

Thanks @anrao19 - there are now conflicts with newly merged commits. I can rebase & force-push - do you want me to?

@adamemerson
Copy link
Contributor

want me to

Yes, please.

@adamemerson
Copy link
Contributor

@ljflores Would you be willing to have someone schedule RADOS QA?

@MaxKellermann MaxKellermann force-pushed the mgr_mon_osdc__references branch from 5203141 to e3cbd0a Compare September 19, 2025 19:52
@MaxKellermann
Copy link
Member Author

Yes, please.

done

@github-actions
Copy link

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@MaxKellermann
Copy link
Member Author

Rebased again to fix conflict with newly merged PRs.

@MaxKellermann
Copy link
Member Author

jenkins test make check arm64

@github-actions
Copy link

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

A non-trivial type is always passed by reference, even if the
parameter is declared as a value; in that case, the compiler must
allocate stack space and move the value there, and then really passes
a reference to this stack allocation.  This only adds overhead for no
reason.

A side effect of this API change is that all callers that accidently
created temporary copies are now revealed by throwing a compiler
error.  This commit fixes all callers and reduces a good amount of
useless overhead by wrapping those parameters in std::move() instead
of copying temporaries.

More temporaries are avoided by emplacing the std::string&& into the
std::vector.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
@anrao19
Copy link
Contributor

anrao19 commented Oct 30, 2025

RGW PR testing completed and approved by @ivancich. Details : https://tracker.ceph.com/issues/73623

@MaxKellermann MaxKellermann merged commit a9b8933 into ceph:main Nov 10, 2025
13 checks passed
@MaxKellermann MaxKellermann deleted the mgr_mon_osdc__references branch November 10, 2025 17:49
NitzanMordhai added a commit to NitzanMordhai/ceph that referenced this pull request Nov 17, 2025
… rvalue refs

PR ceph#65014 added std::move() inside the while loop, which required
recreating the command string on each iteration.

Add const std::string& overload that forwards to the existing
std::string&& version, allowing the command to be declared outside
the loop for better efficiency.

Fixes: https://tracker.ceph.com/issues/73838
Signed-off-by: Nitzan Mordechai <nmordech@ibm.com>
NitzanMordhai added a commit to NitzanMordhai/ceph that referenced this pull request Nov 18, 2025
… rvalue refs

PR ceph#65014 added std::move() inside the while loop, which required
recreating the command string on each iteration.

Add const std::string& overload that forwards to the existing
std::string&& version, allowing the command to be declared outside
the loop for better efficiency.

Fixes: https://tracker.ceph.com/issues/73838
Signed-off-by: Nitzan Mordechai <nmordech@ibm.com>
NitzanMordhai added a commit to NitzanMordhai/ceph that referenced this pull request Jan 1, 2026
… rvalue refs

PR ceph#65014 added std::move() inside the while loop, which required
recreating the command string on each iteration.

Add const std::string& overload that forwards to the existing
std::string&& version, allowing the command to be declared outside
the loop for better efficiency.

Fixes: https://tracker.ceph.com/issues/73838
Signed-off-by: Nitzan Mordechai <nmordech@ibm.com>
(cherry picked from commit 3e107ec)
JoshuaGabriel pushed a commit to JoshuaGabriel/ceph that referenced this pull request Jan 7, 2026
… rvalue refs

PR ceph#65014 added std::move() inside the while loop, which required
recreating the command string on each iteration.

Add const std::string& overload that forwards to the existing
std::string&& version, allowing the command to be declared outside
the loop for better efficiency.

Fixes: https://tracker.ceph.com/issues/73838
Signed-off-by: Nitzan Mordechai <nmordech@ibm.com>
amathuria pushed a commit to amathuria/ceph that referenced this pull request Jan 19, 2026
… rvalue refs

PR ceph#65014 added std::move() inside the while loop, which required
recreating the command string on each iteration.

Add const std::string& overload that forwards to the existing
std::string&& version, allowing the command to be declared outside
the loop for better efficiency.

Fixes: https://tracker.ceph.com/issues/73838
Signed-off-by: Nitzan Mordechai <nmordech@ibm.com>
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