Skip to content

os/bluestore/compression: Fix Estimator::split_and_compress#63373

Merged
aclamk merged 1 commit intoceph:mainfrom
aclamk:aclamk-bs-fix-split-and-compress
Jun 3, 2025
Merged

os/bluestore/compression: Fix Estimator::split_and_compress#63373
aclamk merged 1 commit intoceph:mainfrom
aclamk:aclamk-bs-fix-split-and-compress

Conversation

@aclamk
Copy link
Contributor

@aclamk aclamk commented May 20, 2025

Fixed calculation on effective blob size.
When fully non-compressible data is passed,
it could cause losing few bytes in the end.
Example:

 -107> 2025-05-17T20:40:50.468+0000 7f267a42f640 15 bluestore(/var/lib/ceph/osd/ceph-4) _do_write_v2_compressed 200000~78002 -> 200000~78002
 -106> 2025-05-17T20:40:50.468+0000 7f267a42f640 20 blobs to put: 200000~f000(4d61) 20f000~f000(b51) 21e000~f000(b51) 22d000~f000(b51) 23c000~f000(b51) 24b000~f000(b51) 25a000~f000(b51) 269000~f000(b51)
In result we split 0x78002 into 8 * 0xf000, losing 0x2 in the process.

Calculations for original:

>>> size=0x78002
>>> blobs=(size+0xffff) / 0x10000
>>> blob_size = size / blobs
>>> print hex(size), blobs, hex(blob_size)
0x78002 8 0xf000 <-this means roundup is 0xf000

Calculations for fixed:

>>> size=0x78002
>>> blobs=(size+0xffff) / 0x10000
>>> blob_size = (size+blobs-1) / blobs
>>> print hex(size), blobs, hex(blob_size)
0x78002 8 0xf001 <-this meand roundup is 0x10000

Fixes: https://tracker.ceph.com/issues/71353

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

@aclamk aclamk requested a review from a team as a code owner May 20, 2025 07:53
uint32_t blob_size = p2roundup((size + blobs - 1) / blobs, au_size);
std::vector<uint32_t> blob_sizes(blobs);
for (auto& i: blob_sizes) {
i = std::min(size, blob_size);
Copy link
Contributor

Choose a reason for hiding this comment

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

the std::min() should probably be moved out of the loop?

Copy link
Contributor

Choose a reason for hiding this comment

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

A matter of taste, but I would have preferred a more descriptive version of lines 164,165.
Possibly something along the lines of:
double blobs_as_double = std::ceil(static_cast(size) / max_blob_size);
uint32_t blobs = blobs_as_double;
uint32_t blob_size = p2roundup(std::ceil( size / blobs_as_double), au_size);

Copy link
Contributor

Choose a reason for hiding this comment

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

... or, instead of std::ceil() (that requires a non-integer in this case), just use the
function already there: p2roundup()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

std::min() cannot be outside loop.
It assigns values to subsequent elements, so the sum of all elements will be size.
But you missing it suggest to me that maybe I should rename "i" to "iterated_blob_size"?

p2roundup() cannot be used, blobs is not p2 value.
What I would like to do, but it is not if it exist would be: std::divide_roundup().
I would prefer to stay in integer arithmetic and do not use floats here.

Copy link
Contributor

@ronen-fr ronen-fr May 21, 2025

Choose a reason for hiding this comment

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

  • yes. I missed that. Shame on me.
  • (removed)
  • I understand the reluctance to move to floats. Was looking for such a divide_roundup(), but did not find one yet.

@ronen-fr
Copy link
Contributor

Other than the nits and my prefs - LGTM

uint32_t blob_size = p2roundup((size + blobs - 1) / blobs, au_size);
std::vector<uint32_t> blob_sizes(blobs);
for (auto& i: blob_sizes) {
i = std::min(size, blob_size);
Copy link
Contributor

@ronen-fr ronen-fr May 21, 2025

Choose a reason for hiding this comment

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

  • yes. I missed that. Shame on me.
  • (removed)
  • I understand the reluctance to move to floats. Was looking for such a divide_roundup(), but did not find one yet.

@aclamk aclamk force-pushed the aclamk-bs-fix-split-and-compress branch from c7823e0 to 980b1d5 Compare May 21, 2025 06:38
@aclamk aclamk added aclamk-testing-phoebe bluestore testing aclamk-testing-nauvoo bluestore testing and removed aclamk-testing-phoebe bluestore testing labels May 21, 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

Fixed calculation on effective blob size.
When fully non-compressible data is passed,
it could cause losing few bytes in the end.
Example:
 -107> 2025-05-17T20:40:50.468+0000 7f267a42f640 15 bluestore(/var/lib/ceph/osd/ceph-4) _do_write_v2_compressed 200000~78002 -> 200000~78002
 -106> 2025-05-17T20:40:50.468+0000 7f267a42f640 20 blobs to put: 200000~f000(4d61) 20f000~f000(b51) 21e000~f000(b51) 22d000~f000(b51) 23c000~f000(b51) 24b000~f000(b51) 25a000~f000(b51) 269000~f000(b51)
In result we split 0x78002 into 8 * 0xf000, losing 0x2 in the process.

Calculations for original:
>>> size=0x78002
>>> blobs=(size+0xffff) / 0x10000
>>> blob_size = size / blobs
>>> print hex(size), blobs, hex(blob_size)
0x78002 8 0xf000 <-this means roundup is 0xf000

Calculations for fixed:
>>> size=0x78002
>>> blobs=(size+0xffff) / 0x10000
>>> blob_size = (size+blobs-1) / blobs
>>> print hex(size), blobs, hex(blob_size)
0x78002 8 0xf001 <-this meand roundup is 0x10000

Fixes: https://tracker.ceph.com/issues/71353

Signed-off-by: Adam Kupczyk <akupczyk@ibm.com>
@aclamk aclamk force-pushed the aclamk-bs-fix-split-and-compress branch from 980b1d5 to 80b7d68 Compare May 28, 2025 17:13
@aclamk
Copy link
Contributor Author

aclamk commented Jun 3, 2025

Verified by https://tracker.ceph.com/issues/71503.

@aclamk aclamk merged commit 897abcb into ceph:main Jun 3, 2025
12 checks passed
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.

2 participants