Skip to content

osd: use std::vector rather than set/map if appropriate - #63216

Closed
gardran wants to merge 6 commits into
ceph:mainfrom
gardran:wip-gardran-snapmapper-and-around0
Closed

gardran wants to merge 6 commits into
ceph:mainfrom
gardran:wip-gardran-snapmapper-and-around0

Conversation

@gardran

@gardran gardran commented May 10, 2025 •

Copy link
Copy Markdown
Contributor

We don't care about strong ordering in the affected cases while insertions/appends to vector (particularly preallocated one) are more efficient.
Some redundant data clonings and lookup have been eliminated too.

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

gardran added 6 commits May 9, 2025 16:38
This should be more efficient as building std::set implies multiple
allocations and rebalancing.

Signed-off-by: Garry Drankovich <[email protected]>
Using vector is apparently more efficient as std::set implies more complicated insertion/removal
ops (e.g. multiple allocations are required) comparing to vector while the need for keys uniqueness/ordering
is pretty rare.
Additionally some redundant copyings have been removed as well.

Signed-off-by: Garry Drankovich <[email protected]>
@gardran
gardran requested a review from a team as a code owner May 10, 2025 07:49
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@ronen-fr ronen-fr 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.

Please separate into multiple PRs, as the following should be discussed & verified for each group of changes:

  • is there indeed a performance benefit?

  • are we sure there is no implicit assumption of uniqueness (which is guaranteed when using set/map)?

  • the 'no order is required';

  • performance benefit vs. interface complexity.

I would guess that most of the changes suggested can pass these questions - but they must be discussed.

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

I agree with @ronen-fr it would be easier to review / merge if we split the PR.

Comment thread src/osd/PrimaryLogPG.cc
return;
}
proxyread_ops.erase(tid);
proxyread_ops.erase(p);

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 is in the cache tiering code. Please note it has been deprecated long time ago and we're in the process of removing its tests, so I would prefer to leave it alone.

Comment thread src/osd/PrimaryLogPG.cc
pg->snap_trimq.erase(snap_to_trim);

if (pg->snap_trimq_repeat.count(snap_to_trim)) {
auto it = pg->snap_trimq_repeat.find(snap_to_trim);

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.

nit: better to use the recent C++ feature and put the initialization statement within if (e.g. if (auto it = ...; the check). That way we would limit the scope of it and potentially avoid use-after-invalidate in the future.

Comment thread src/osd/PrimaryLogPG.cc
if (it != pg->snap_trimq_repeat.end()) {
ldout(pg->cct, 10) << " removing from snap_trimq_repeat" << dendl;
pg->snap_trimq_repeat.erase(snap_to_trim);
pg->snap_trimq_repeat.erase(it);

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, this commit probably makes sense.

Comment thread src/os/Transaction.h
void omap_rmkeys(
const coll_t &cid, ///< [in] Collection containing oid
const ghobject_t &oid, ///< [in] Object from which to remove the omap
const std::vector<std::string> &keys ///< [in] Keys to clear

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.

Oh, a new overload.

Comment thread src/os/Transaction.h Outdated
_op->op = OP_OMAP_RMKEYS;
_op->cid = _get_coll_id(cid);
_op->oid = _get_object_id(oid);
encode(keys, data_bl);

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.

Although there is some compatibility in marshaling between the types, what needs further checking is:

  • dealing with duplicates,
  • whether OP_OMAP_RMKEYS is truly indifferent towards the key order.

Comment thread src/osd/SnapMapper.cc
set<string> to_remove;
to_remove.insert(to_object_key(oid));
vector<string> to_remove;
to_remove.emplace_back(to_object_key(oid));

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.

Perhaps still worth reserving.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions Bot added the stale label Jul 21, 2025
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no activity for 90 days. Please feel free to reopen this pull request (or open a new one) if the proposed change is still appropriate. Thank you for your contribution!

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.

5 participants