Skip to content

librbd: improve rbd_diff_iterate2() performance in fast-diff mode - #55127

Merged
idryomov merged 19 commits into
ceph:mainfrom
idryomov:wip-63341
Jan 20, 2024
Merged

idryomov merged 19 commits into
ceph:mainfrom
idryomov:wip-63341

Conversation

@idryomov

Copy link
Copy Markdown
Contributor

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

@idryomov

Copy link
Copy Markdown
Contributor Author

jenkins test make check

1 similar comment
@idryomov

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@idryomov
idryomov force-pushed the wip-63341 branch 10 times, most recently from d612374 to 81e0b4a Compare January 11, 2024 17:03
@idryomov
idryomov marked this pull request as ready for review January 11, 2024 21:28
@idryomov
idryomov requested a review from a team as a code owner January 11, 2024 21:28
@idryomov

Copy link
Copy Markdown
Contributor Author

cc @baergj

@idryomov

Copy link
Copy Markdown
Contributor Author

jenkins test api

@sunilangadi2

sunilangadi2 commented Jan 12, 2024 •

Copy link
Copy Markdown

@idryomov Do we have any tracker for it?
can you please add test performance difference in this PR.

@idryomov

Copy link
Copy Markdown
Contributor Author

@idryomov Do we have any tracker for it?

https://tracker.ceph.com/issues/63341 is linked in the respective commits. There is a (somewhat contrived) reproducer in https://gitlab.com/qemu-project/qemu/-/issues/1026.

@idryomov

Copy link
Copy Markdown
Contributor Author

@trociny We are trying to close out 16.2.15 (the last Pacific release) and I want this PR there. Would you have time for a review in the coming days?

@trociny

trociny commented Jan 17, 2024 •

Copy link
Copy Markdown
Contributor

@trociny We are trying to close out 16.2.15 (the last Pacific release) and I want this PR there. Would you have time for a review in the coming days?

@idryomov I got cold and I am still recovering. I hope I will be able to review (by) tomorrow.

@trociny trociny 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 though I could miss something (diff iterate code is not easy for review for me). But the good test coverage for the changed code allows to have a confidence the code is correct.

Comment thread src/librbd/object_map/DiffRequest.cc Resolved
Use a range where only snap_id_start is invalid.

Signed-off-by: Ilya Dryomov <[email protected]>
In preparation for multiple similarly configured MockTestImageCtx
objects being used in a single test, centralize their creation and add
a couple of helpers for setting expectations from a callback.

Signed-off-by: Ilya Dryomov <[email protected]>
It became redundant with commit b81cd24 ("librbd/object_map: diff
state machine should track object existence") -- it != end_it condition
in the loop is sufficient.

Signed-off-by: Ilya Dryomov <[email protected]>
Commit 399a45e ("librbd/object_map: rbd diff between two
snapshots lists entire image content") fixed most of the damage caused
by commit b81cd24 ("librbd/object_map: diff state machine should
track object existence"), but the case of a "resize diff" when diffing
from snapshot was missed.  An area that was freshly allocated in image
resize is the same in principle as a freshly created image and objects
marked OBJECT_EXISTS_CLEAN are no exception.  Diff for such objects in
such an area should be set to DIFF_STATE_DATA_UPDATED, however
currently when diffing from snapshot, it's set to DIFF_STATE_DATA.

Signed-off-by: Ilya Dryomov <[email protected]>
The new "track the largest of all versions in the set, diff state is
only ever grown" semantics introduced in commit 330f2a7 ("librbd:
helper state machine for computing diffs between object-maps") don't
make sense for diff-iterate.  It's a waste because DiffIterate won't
query beyond the end version size -- this is baked into the API.

Limit this behavior to deep-copy and resurrect the original behavior
from 2015 for diff-iterate.

Signed-off-by: Ilya Dryomov <[email protected]>
…rate

In case of diff-iterate against the beginning of time, the result
depends only on the end version.  Loading and processing object maps
or intermediate snapshots is redundant and can be skipped.

This optimization is made possible by commit be507aa ("librbd:
diff-iterate shouldn't ever report "new hole" against a hole") and, to
a lesser extent, the previous commit.

Getting FastDiffInvalid, LoadObjectMapError and ObjectMapTooSmall to
pass required tweaking not just expectations, but also start/end snap
ids and thus also the meaning of these tests.  This is addressed in the
next commit.

Fixes: https://tracker.ceph.com/issues/63341
Signed-off-by: Ilya Dryomov <[email protected]>
For each covered edge case or error, run through the following
scenarios:

- where the edge case concerns snap_id_start
- where the edge case concerns snap_id_end
- where the edge case concerns intermediate snapshot and
  snap_id_start == 0 (diff against the beginning of time)
- where the edge case concerns intermediate snapshot and
  snap_id_start != 0 (diff from snapshot)

Signed-off-by: Ilya Dryomov <[email protected]>
Same as with round_up_to(), d isn't required to be a power of two.

Signed-off-by: Ilya Dryomov <[email protected]>
Currently diff-iterate in fast-diff mode is performed on the entire
image no matter what image extent is passed to the API.  Then, unused
diff just gets discarded as DiffIterate ends up querying only objects
that the passed image extent maps to.  This hasn't been an issue for
internal consumers ("rbd du", "rbd diff", etc) because they work on the
entire image, but turns out to lead to quadratic slowdown in some QEMU
use cases.

0..UINT64_MAX range is carved out for deep-copy which is unranged by
definition.  To get effectively unranged diff-iterate, 0..UINT64_MAX-1
range can be used.

Fixes: https://tracker.ceph.com/issues/63341
Signed-off-by: Ilya Dryomov <[email protected]>
When getting parent diff, pass the overlap-reduced image extent instead
of the entire 0..overlap range to avoid a similar quadratic slowdown on
cloned images.

Signed-off-by: Ilya Dryomov <[email protected]>
This is a leftover from commit 2b3a468 ("librbd: switch
diff-iterate API to use new object-map diff helper").

Signed-off-by: Ilya Dryomov <[email protected]>
It's totally broken: instead of returning the current position and
moving to the next position, it returns the next position and doesn't
move anywhere.  Luckily it hasn't been used until now.

Signed-off-by: Ilya Dryomov <[email protected]>
Currently it's done in two cases:

- if the loaded object map is larger than expected based on byte size,
  it's truncated to expected number of objects
- in case of deep-copy, if the loaded object map is smaller than diff
  state, it's expanded to get "track the largest of all versions in the
  set" semantics

Both of these cases can be easily dealt with without modifying the
object map.  Being able to process a const object map is needed for
working on in-memory object map which is external to DiffRequest.

Signed-off-by: Ilya Dryomov <[email protected]>
T (ConstIterator or Iterator) is confused with const T here:
IteratorImpl dereference operator is wrongly overloaded on const
and returns Reference instead of ConstReference for ConstIterator.
This then fails inside bufferlist bowels because Reference is
incompatible with bufferlist::const_iterator.

Signed-off-by: Ilya Dryomov <[email protected]>
In preparation for potentially using in-memory object map, decouple
object map processing from loading object maps and place the logic in
prepare_for_object_map() and process_object_map().

Signed-off-by: Ilya Dryomov <[email protected]>
If the object map for the end version is around (already loaded in
memory, either due to the end version being a snapshot or due to
exclusive lock being held), use it to run diff-iterate against the
beginning of time.  Since it's the only object map needed in that
case, such calls would be satisfied locally.

Fixes: https://tracker.ceph.com/issues/63341
Signed-off-by: Ilya Dryomov <[email protected]>
As an optimization, try to ensure that the object map for the end
version is preloaded through the acquisition of exclusive lock and
as a consequence remains around until exclusive lock is released.
If it's not around, DiffRequest would (re)load it on each call.

Signed-off-by: Ilya Dryomov <[email protected]>
@idryomov

Copy link
Copy Markdown
Contributor Author

Rebased to resolve a conflict in PendingReleaseNotes.

@petrutlucian94

petrutlucian94 commented Jun 11, 2024 •

Copy link
Copy Markdown
Contributor

@idryomov hi, this change introduced a regression. "rbd du" gets an assertion failure if there are 0 sized images:

/mnt/data/workspace/ceph_linux/src/librbd/api/DiffIterate.cc: In function 'int librbd::api::DiffIterate<ImageCtxT>::execute() [with ImageCtxT = librbd::ImageCtx]' thread 7fa28543f740 time 2024-06-11T07:51:39.470207+0000
/mnt/data/workspace/ceph_linux/src/librbd/api/DiffIterate.cc: 341: FAILED ceph_assert(object_diff_state.size() == end_object_no - start_object_no)

I've submitted an issue: https://tracker.ceph.com/issues/66418

@idryomov

Copy link
Copy Markdown
Contributor Author

@idryomov hi, this change introduced a regression. "rbd du" gets an assertion failure if there are 0 sized images:

Thanks for the report! This is being addressed in #57973.

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