Skip to content

osd: Reduce reads when rebalancing healthy Erasure Coded PGs - #64502

Merged
aainscow merged 1 commit into
ceph:mainfrom
aainscow:ec_reduce_rebalance_reads
Aug 1, 2025
Merged

aainscow merged 1 commit into
ceph:mainfrom
aainscow:ec_reduce_rebalance_reads

Conversation

@aainscow

@aainscow aainscow commented Jul 15, 2025 •

Copy link
Copy Markdown
Contributor

Jerasure and ISA-L plugins (and probably other) EC plugins have the following algorithm for selecting which shards they need to read:

if (all needed shards are available) {
  request reads to all shards
} else {
  pick the first K available shards
}

This is fine for most good-path IO, since it always picks the minimal set of required shards. However, it is flawed when all shards need recovery at the same time. This is common during rebalancing, where due to CRUSH, the set of OSDs will frequently all change.

These plugins should never read more than K shards. The extra challenge here is that we don't want to change this API since we don't want to change the behaviour of old EC.

To fix this, therefore we make new EC only request K shards to be recovered in the first place if read optimisations are enabled for the plugin.

https://tracker.ceph.com/issues/72371

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

@aainscow
aainscow requested a review from a team as a code owner July 15, 2025 08:05
@github-actions github-actions Bot added the core label Jul 15, 2025
@aainscow aainscow self-assigned this Jul 15, 2025
@aainscow
aainscow force-pushed the ec_reduce_rebalance_reads branch from ead29fc to efad06e Compare July 15, 2025 14:28
@aainscow

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@aainscow
aainscow requested a review from rzarzynski July 16, 2025 15:04
@aainscow

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@aainscow

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@aainscow

Copy link
Copy Markdown
Contributor Author

jenkins test make check

1 similar comment
@aainscow

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@connorfawcett

Copy link
Copy Markdown
Contributor

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

@aainscow -The validation of the PR has been successfully completed. The review is currently pending. Once the review is done,feel free to merge the PR.

Comment thread src/common/bitset_set.h
int bits_set = std::popcount(words[i]);
if (bits_set > n) {
uint64_t tmp = words[i];
// This could be optimised with BMI _pdep_u64

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.

ACK. Probably not worth the effort - at least for the current use case. The majority of the calls to this function will be with a bitset that has <=n set bits and will never enter this if statement. When there are >n bits set we are going to save one or more read I/Os, the cost of the for loop is insignificant vs this saving

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think a more detailed comment is worth it, but I have added more detail to the commit message to cover this.

Comment thread src/osd/ECCommon.cc
// If we support partial reads, we are making the assumption that only
// K shards need to be read to recover data. We opt here for minimising
// the number of reads over minimising the amount of parity calculations
// that are needed.

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 performance is limited by the drives, then less read I/Os is a clear advantage.
  • If performance is limited by the network then less remote read I/Os is a clear advantage.
  • If performance is limited by the CPU then the CPU cost of M unnecessary remote read I/Os (messenger+bluestore) is almost certainly more than the cost of doing an extra encode operation to calculate the coding parities.
  • If performance is limited by system memory bandwidth the encode+crc generation has less overhead than the read+bluestore crc check+messenger overheads.

Longer term this logic should probably be pushed into the plugins, in particular to give LRC the opportunity to optimize for locality of the shards. Reason for not doing this now is that it would be messy because the legacy EC code cannot support this optimization and LRC isn't yet optimizing for locality

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think a more detailed comment is worth it, but I have added more detail to the commit message to cover this.

Comment thread src/common/bitset_set.h
const_iterator find_nth(unsigned int n) const {
for (size_t i = 0; i < word_count; ++i) {
int bits_set = std::popcount(words[i]);
if (bits_set > n) {

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: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will fix. I don't think this needs a new qa

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

@aainscow - If validation is required for this PR, please add the 'needs-qa' label.

…upports it).

Plugins which support partial reads, should never need more than k shards
to read the data, even if some shards have failed. However, rebalancing commonly
requests k + m shards, as very frequently all shards are moved. If this occurs
and all k + m shards are online, the read will be achieved by reading ALL shards
rather than just reading k shards. This commit fixes that issue.

The problem is that we don't want to change the API to the old EC, so we cannot
update the plugin behaviour here.  Instead, the EC code itself will reduce
the number of shards it tells minimum_to_decode about.

In a comment we note that bitset_set performance could be improved using _pdep_u64.
This would require fiddly platform-specific code and would likely not show
any performance improvements for most applications. The majority of the calls to
this function will be with a bitset that has <=n set bits and will never enter this
if statement. When there are >n bits set we are going to save one or more read I/Os,
the cost of the for loop is insignificant vs this saving. I have left the comment
in as a hint to future users of this function.

Further notes were made in a review comment that are worth recording:

- If performance is limited by the drives, then less read I/Os is a clear advantage.
- If performance is limited by the network then less remote read I/Os is a clear advantage.
- If performance is limited by the CPU then the CPU cost of M unnecessary remote
  read I/Os (messenger+bluestore) is almost certainly more than the cost of doing an
  extra encode operation to calculate the coding parities.
- If performance is limited by system memory bandwidth the encode+crc generation
  has less overhead than the read+bluestore crc check+messenger overheads.

Longer term this logic should probably be pushed into the plugins, in particular
to give LRC the opportunity to optimize for locality of the shards. Reason for
not doing this now is that it would be messy because the legacy EC code cannot
support this optimization and LRC isn't yet optimizing for locality

Signed-off-by: Alex Ainscow <[email protected]>
@aainscow
aainscow force-pushed the ec_reduce_rebalance_reads branch from efad06e to 52915db Compare August 1, 2025 08:17
@aainscow

aainscow commented Aug 1, 2025

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@aainscow aainscow added the backport-complete A backport was necessary, but all work has been completed. label Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-complete A backport was necessary, but all work has been completed. common core performance TESTED tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants