Skip to content

crimson/os/seastore: OP_CLONERANGE2 support ---- another approach - #65134

Merged
athanatos merged 9 commits into
ceph:mainfrom
xxhdx1985126:wip-seastore-clone-range-latest
Sep 30, 2025
Merged

athanatos merged 9 commits into
ceph:mainfrom
xxhdx1985126:wip-seastore-clone-range-latest

Conversation

@xxhdx1985126

@xxhdx1985126 xxhdx1985126 commented Aug 20, 2025 •

Copy link
Copy Markdown
Member

This is another approach in implementing OP_CLONERANGE2 support in SeaStore than #57735 .

Before this PR, we have implemented the support for OP_CLONE and OP_CLONERANGE2 in a way which requires maintaining strict symmetric indirect lba mapping relations at any time. This means we have to create two sets of indirect lba mappings when dealing with OP_CLONE and move the direct mapping out when dealing with OP_CLONERANGE2, which makes the mechanism of clone and clone_range very complex, error prone and inefficient in terms of performance.

This PR takes another approach, which also ensures that modifications to any clone won't affect other clones that are sharing data with it, but doesn't require strict symmetric indirect lba mapping relations at any time, only at the time when those modifications actually happens.

Specifically, when dealing with OP_CLONE and OP_CLONERANGE2, this PR record a boolean value, needs_cow, in the onode layout, and set it to true if there's any direct lba mapping that's shared with other clones. When doing modifications to object data, we do another clone if the onode's needs_cow is true. With this approach, we only need to create one set of indirect lba mappings when dealing with OP_CLONE and OP_CLONERANGE2, and no direct lba mapping move is needed.

Basically, this PR's approach is to implement a COW mechinary of SeaStore itself and makes the mechanism behind OP_CLONE and OP_CLONERANGE2 processing much simpler and more performant.

Signed-off-by: Xuehan Xu [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

@xxhdx1985126
xxhdx1985126 requested a review from a team as a code owner August 20, 2025 02:35
@Matan-B Matan-B added this to Crimson Aug 20, 2025
@Matan-B Matan-B moved this to Awaits review in Crimson Aug 20, 2025

@Matan-B Matan-B 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.

This seems more elegant approach than #57735. I will have to take a take a deeper look in order to provide less high level review.
If agreed to proceed, it could be nice to explain the design proposed here in seastore.rst

}
return fut.discard_result().handle_error_interruptible(
ObjectDataHandler::write_iertr::pass_further{},
crimson::ct_error::assert_all{"unexpected error"}

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 could be a good opportunity to introduce new logic with coroutines, although we can probably address it later (If agreed to this approach).
However, I think we should try to avoid unexpected error messages in new code as they don't provide any information when debugging backtraces.
e.g 7207975

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.

Definitely +1 to coroutines.

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.

This could be a good opportunity to introduce new logic with coroutines, although we can probably address it later (If agreed to this approach). However, I think we should try to avoid unexpected error messages in new code as they don't provide any information when debugging backtraces. e.g 7207975

Yeah, will change to code:-)

@Matan-B
Matan-B requested a review from jdurgin August 20, 2025 11:30

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

I think the concept is reasonable. I'd really like any new or heavily modified code to use coroutines -- makes the logic vastly more readable.

Question: needs_cow gets set on the target onode, right? So even the target of a small clone_range would have its entire lba range indirected in copy_on_write?

context_t ctx,
object_data_t &object_data,
LBAMapping first_mapping)
{

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.

At this point, I really want all new code to use coroutines if possible. Modifying code that uses explicit continuations with captures is exceedingly error prone.

ObjectDataHandler::clone_ret
ObjectDataHandler::copy_on_write(
context_t ctx)
{

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.

Again, coroutines. Probably also a coroutine appropriate replacement for with_object_data.

).si_then([ctx, this, &object_data](auto mapping) {
auto old_base = object_data.get_reserved_data_base();
auto old_len = object_data.get_reserved_data_len();
return do_clone(ctx, object_data, mapping

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.

Is the result of this that the mappings for the onode become indirect?

}
return fut.discard_result().handle_error_interruptible(
ObjectDataHandler::write_iertr::pass_further{},
crimson::ct_error::assert_all{"unexpected error"}

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.

Definitely +1 to coroutines.

ctx,
object_data,
old_len
).si_then([ctx, &object_data](auto mapping) {

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.

Ok, so mapping is a mapping to a new reserved lba range for this object. The next part redirects that range to the old range completing the redirection. Is that right?

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.

Yes.

@xxhdx1985126

xxhdx1985126 commented Aug 21, 2025 •

Copy link
Copy Markdown
Member Author

I think the concept is reasonable. I'd really like any new or heavily modified code to use coroutines -- makes the logic vastly more readable.

Yeah, will move to use coroutines.

Question: needs_cow gets set on the target onode, right? So even the target of a small clone_range would have its entire lba range indirected in copy_on_write?

I think we can optimize this in such a way that, when doing copy_on_write:

  1. For shared direct mappings, we clone them in the new reserved lba space;
  2. For non-shared direct mappings and other types of mappings, we move them into the new reserved lba space;

With this approach, we can avoid making unnecessary indirections. What do you think? @athanatos @Matan-B

@athanatos

Copy link
Copy Markdown
Contributor

I think the concept is reasonable. I'd really like any new or heavily modified code to use coroutines -- makes the logic vastly more readable.

Yeah, will move to use coroutines.

Question: needs_cow gets set on the target onode, right? So even the target of a small clone_range would have its entire lba range indirected in copy_on_write?

I think we can optimize this in such a way that, when doing copy_on_write:

1. For shared direct mappings, we clone them in the new reserved lba space;

2. For non-shared direct mappings and other types of mappings, we move them into the new reserved lba space;

With this approach, we can avoid making unnecessary indirections. What do you think? @athanatos @Matan-B

Reasonable. Another question -- what happens if an object is the target of a clone many times? We need to reserve a max section of lba space each time, right?

@xxhdx1985126

Copy link
Copy Markdown
Member Author

Reasonable. Another question -- what happens if an object is the target of a clone many times? We need to reserve a max section of lba space each time, right?

Do you mean what if a head object is issued with OP_CLONE many times? If so, I think that's right.

I think maybe we can set needs_cow on OP_CLONE and defer the reservation until the time of real modifications, but given OP_CLONE is always followed by some mutation, this may not provide much improvement?

Are you concerned with the lba space exhaustion or the cpu overhead of the lba space reservation?

@xxhdx1985126

xxhdx1985126 commented Aug 23, 2025 •

Copy link
Copy Markdown
Member Author

Reasonable. Another question -- what happens if an object is the target of a clone many times? We need to reserve a max section of lba space each time, right?

@athanatos Hi, sam, I still don't quite understand the scenario you are considering, especially what you mean by being "the target of a clone many times". Could you please elaborate it a bit more?:-)

@xxhdx1985126
xxhdx1985126 force-pushed the wip-seastore-clone-range-latest branch from 31964d8 to 4f17bce Compare August 23, 2025 14:43
@xxhdx1985126

Copy link
Copy Markdown
Member Author

@athanatos @Matan-B I've just changed the implementation to be based on c++ coroutine as suggested, and added more comments to facilitate the review. Please take a look again, thanks:-)

@xxhdx1985126

xxhdx1985126 commented Aug 24, 2025 •

Copy link
Copy Markdown
Member Author

@athanatos I think I get your point. I've changed the code to always set need_cow to the clone object in cases of OP_CLONE and OP ROLLBACK. So normal head overwrites won't cause COW. Please take a look, thanks:-)

I think, now, it's only when the recovering of some clone causes it to share the head object's direct lba mappings that the head will go through the COW procedure. But, even in this case, the result of this PR is only causing a symmetric indirect lba relation, which is no worse than the main branch's behaviour.

@xxhdx1985126

Copy link
Copy Markdown
Member Author

Question: needs_cow gets set on the target onode, right? So even the target of a small clone_range would have its entire lba range indirected in copy_on_write?

After a second thought, maybe we can tolerate this case, as this is exactly the same as the result of a OP_CLONE. Am I right?

@Matan-B

Matan-B commented Sep 17, 2025

Copy link
Copy Markdown
Contributor

I think this (non-trivial) PR should be separated from smaller ones when testing, what do you think?

@xxhdx1985126

Copy link
Copy Markdown
Member Author

I think this (non-trivial) PR should be separated from smaller ones when testing, what do you think?

Yeah, https://shaman.ceph.com/builds/ceph/wip-seastore-clone-range-latest/

the onode's object data space needs to do clone before modification

At present, it's only when the onode's object data space is sharing its
own direct lba mappings with other onodes that the "need_cow" field
would be true.

Signed-off-by: Xuehan Xu <[email protected]>
symmetric indirect lba relationship at the time of clone

OP_CLONE is done in the following way:
1. First, swap the layout of the head onode and the clone onode, so that
   clone onode's object_data, omap_root, xattr_root and log_root all
   point to the head onode's corresponding fields;
2. Do SeaStore::_clone() from the clone onode to the head onode, which
   is exactly what rollback is done.

This makes the code of ObjectDataHandler::clone() and
ObjectDataHandler::copy_on_write() even simpler, and can facilitate the
clone/rollback scenarios when the "128-bit" lba key layout is involved.

Signed-off-by: Xuehan Xu <[email protected]>
needs it

At present, only clone objects may need COW, as HEAD objects won't be
sharing any direct lba mapping with other objects in non-recovery
scenarios.

Although the HEAD object may share its direct mappings with the temp
object that's going to be recovered and replace it, it won't be
accepting any modifications at that time.

Signed-off-by: Xuehan Xu <[email protected]>
@xxhdx1985126
xxhdx1985126 force-pushed the wip-seastore-clone-range-latest branch from d642e61 to a9fdbb7 Compare September 28, 2025 06:49
@Matan-B

Matan-B commented Sep 28, 2025 •

Copy link
Copy Markdown
Contributor

8508833: https://tracker.ceph.com/issues/72842

@xxhdx1985126, Look related to me - the tracker mentioned isn't relevant here iiuc.

2025-09-18T14:58:39.222 INFO:tasks.rados.rados.0.smithi091.stdout:3998: done (1 left)
2025-09-18T14:58:39.223 INFO:tasks.rados.rados.0.smithi091.stdout:3999: done (0 left)
2025-09-18T14:58:39.224 INFO:tasks.rados.rados.0.smithi091.stderr:0 errors.
2025-09-18T14:58:39.948 INFO:tasks.ceph.ceph_manager.ceph:pg 3.c in trimming, state: active+clean+snaptrim
2025-09-18T14:58:39.948 INFO:tasks.ceph.ceph_manager.ceph:pg 3.b in trimming, state: active+clean+snaptrim
2025-09-18T14:58:39.948 INFO:tasks.ceph.ceph_manager.ceph:pg 3.3 in trimming, state: active+clean+snaptrim

Thrash test finished successfully but trimming has not. What do you think?

@xxhdx1985126

Copy link
Copy Markdown
Member Author

8508833: https://tracker.ceph.com/issues/72842

@xxhdx1985126, Look related to me - the tracker mentioned isn't relevant here iiuc.

2025-09-18T14:58:39.222 INFO:tasks.rados.rados.0.smithi091.stdout:3998: done (1 left)
2025-09-18T14:58:39.223 INFO:tasks.rados.rados.0.smithi091.stdout:3999: done (0 left)
2025-09-18T14:58:39.224 INFO:tasks.rados.rados.0.smithi091.stderr:0 errors.
2025-09-18T14:58:39.948 INFO:tasks.ceph.ceph_manager.ceph:pg 3.c in trimming, state: active+clean+snaptrim
2025-09-18T14:58:39.948 INFO:tasks.ceph.ceph_manager.ceph:pg 3.b in trimming, state: active+clean+snaptrim
2025-09-18T14:58:39.948 INFO:tasks.ceph.ceph_manager.ceph:pg 3.3 in trimming, state: active+clean+snaptrim

Thrash test finished successfully but trimming has not. What do you think?

Oh, I thought the test wouldn't wait for the trimming, sorry.

@xxhdx1985126

xxhdx1985126 commented Sep 29, 2025 •

Copy link
Copy Markdown
Member Author

8508833: https://tracker.ceph.com/issues/72842

@xxhdx1985126, Look related to me - the tracker mentioned isn't relevant here iiuc.

2025-09-18T14:58:39.222 INFO:tasks.rados.rados.0.smithi091.stdout:3998: done (1 left)
2025-09-18T14:58:39.223 INFO:tasks.rados.rados.0.smithi091.stdout:3999: done (0 left)
2025-09-18T14:58:39.224 INFO:tasks.rados.rados.0.smithi091.stderr:0 errors.
2025-09-18T14:58:39.948 INFO:tasks.ceph.ceph_manager.ceph:pg 3.c in trimming, state: active+clean+snaptrim
2025-09-18T14:58:39.948 INFO:tasks.ceph.ceph_manager.ceph:pg 3.b in trimming, state: active+clean+snaptrim
2025-09-18T14:58:39.948 INFO:tasks.ceph.ceph_manager.ceph:pg 3.3 in trimming, state: active+clean+snaptrim

Thrash test finished successfully but trimming has not. What do you think?

Um, I checked the log again, it looks that, at 2025-09-18T14:58:50.358, PGs' snaptrims finished and are all active+clean, so I think this is still a graceful shutdown issue, what do you think? @Matan-B Sorry, it's not, still investigating.

@athanatos
athanatos self-requested a review September 29, 2025 16:13

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

(Sorry! Meant to look at this last week but got side tracked) LGTM once you're happy with the tests.

@Matan-B Matan-B moved this from Awaits review to Needs QA in Crimson Sep 29, 2025
@Matan-B

Matan-B commented Sep 30, 2025

Copy link
Copy Markdown
Contributor

Failures: 8508808: https://tracker.ceph.com/issues/72701 8508833: https://tracker.ceph.com/issues/73317 8508838: https://tracker.ceph.com/issues/73159 8508858, 8508860, 8508869 : https://tracker.ceph.com/issues/73070
All failures seems unrelevant, will test it again, since some of the above issues have been resolved.

8508833: https://tracker.ceph.com/issues/73317

All failures are confirmed.

@xxhdx1985126, Most of the issues reported are now resolved and iiuc the PR is not rebased on top of them. The test results do look ok to me (!) - though I would prefer to re run the tests after rebasing on top of latest main + one of the fixes #65726.
I'm open to be also not wait for a rerun if you feel otherwise - please let me know :)

Note: It would be really interesting to enable seastore recovery test once this PR is merged as it was one of the blockers to enabling them.

@xxhdx1985126

Copy link
Copy Markdown
Member Author

Failures: 8508808: https://tracker.ceph.com/issues/72701 8508833: https://tracker.ceph.com/issues/73317 8508838: https://tracker.ceph.com/issues/73159 8508858, 8508860, 8508869 : https://tracker.ceph.com/issues/73070
All failures seems unrelevant, will test it again, since some of the above issues have been resolved.

8508833: https://tracker.ceph.com/issues/73317
All failures are confirmed.

@xxhdx1985126, Most of the issues reported are now resolved and iiuc the PR is not rebased on top of them. The test results do look ok to me (!) - though I would prefer to re run the tests after rebasing on top of latest main + one of the fixes #65726. I'm open to be also not wait for a rerun if you feel otherwise - please let me know :)

Note: It would be really interesting to enable seastore recovery test once this PR is merged as it was one of the blockers to enabling them.

Please feel free to rerun the tests, thanks:-)

@athanatos
athanatos merged commit 8c635f5 into ceph:main Sep 30, 2025
@Matan-B Matan-B moved this from Needs QA to Merged (Main) in Crimson Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Merged (Pre Umbrella cutoff)

Development

Successfully merging this pull request may close these issues.

3 participants