Skip to content

erasure-code/clay: decode sub-chunks in place - #72056

Merged
ljflores merged 1 commit into
ceph:mainfrom
lumir-sliva:clay-subchunk-in-place-decode
Sep 29, 2026
Merged

ljflores merged 1 commit into
ceph:mainfrom
lumir-sliva:clay-subchunk-in-place-decode

Conversation

@lumir-sliva

@lumir-sliva lumir-sliva commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Since tentacle, CLAY computes wrong parity and returns garbage whenever it has to rebuild a
lost data shard, for profiles where the sub-chunk size isn't a multiple of 64 bytes (12+4,
10+4, 16+4 and 6+3 with the default stripe unit). Reproducer, harness and raw output are on
the tracker, so the reasoning can be checked independently.

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

What's wrong

216eb26 ("erasure-code: Increase SIMD_ALIGN from 32 to 64", #60246) is in every tentacle
release. CLAY works plane by plane on sub-chunks, which are substr_of() views into U_buf
and the coupled chunks, and before every inner jerasure call it runs
rebuild_aligned[_size_and_memory](..., SIMD_ALIGN) on those views. A sub-chunk is only
aligned to its own size: for k=12 m=4 d=15 there are 256 sub-chunks in an 8192 byte chunk, so
each one is 32 bytes. With SIMD_ALIGN=32 those views stayed in place. With 64, every odd
sub-chunk gets silently copied, the inner decode writes into the copy and the result is lost.

Parity is computed through the same decode_layered() path (the parity shards are the
erasures), so both directions break:

  • encode: parity shards come out wrong on disk (on 12+4, the odd sub-chunks of two parity
    shards and all of the other two). Data shards are fine, so healthy reads look fine, and
    deep-scrub can't tell because hinfo is computed over the wrong parity
  • decode: the output buffer for the lost shard is returned unwritten, so degraded reads
    return uninitialised memory plus stale U_buf planes. The CRC changes on every read of the
    same object. With a data digest that's EIO (full-object read crc ... != expected), without
    one (after partial writes, e.g. RBD) the client gets the garbage
  • recovery and backfill write corrupt shards, and partial writes to a degraded stripe rebuild
    the rest of the stripe from parity and write it back as data

Reported against a production 19.2.3 -> 20.2.4 upgrade with CLAY 12+4 RGW and RBD pools. The
mon doesn't allow allow_ec_optimizations on a CLAY profile, so this is the legacy EC path.
squid is unaffected.

Fix

Stop realigning the sub-chunk views that the inner decode writes into; they get a contiguity
assert instead. In the normal decode/encode path the inputs are views into buffers that are
already aligned at chunk level, so they are left alone as well, which is exactly what squid did
with SIMD_ALIGN=32. In repair_one_lost_chunk() the inputs come from the read reply and may
be misaligned, so those are still realigned (copying an input is harmless). That path is
currently unreachable because is_repair() always returns 0, but it keeps the right behaviour
for when it comes back.

Reverting SIMD_ALIGN isn't an option: it was raised on purpose, and existing pools have the
32-byte sub-chunk baked into their stripe_width, so CLAY has to cope with it.

Side note: the old loops only realigned indices 0..2 and never 3, which is why only part of
the output was lost.

This does not repair data already written by an affected OSD. Objects written or modified on
20.x with an affected profile have bad parity and need a whole-object rewrite once the fix is
in. Worth a release note, happy to add one here or separately.

How to check it yourself

Reproducer, harness and raw output are attached to the tracker.

  • the new ErasureCodeClay.encode_decode_small_subchunks test fails on main (98fb1cf) on
    every erasure pattern and passes with this change:
    unittest_erasure_code_clay --gtest_filter='*small_subchunks*'
  • existing CLAY coverage didn't catch it: the round-trip tests have been DISABLED_ since
    0a9e718 and only used k=2..4 (sub-chunks of 256+ bytes, still 64-aligned), and
    ceph-erasure-code-corpus has no CLAY entries
  • the whole thing is one constant: rebuilding the CLAY plugin with only SIMD_ALIGN = 32 makes
    encode and decode correct again

Also verified on vstart (17 OSDs, CLAY 12+4):

  • 19.2.3 degraded reads correct, 20.2.4 EIO on every object that needs a lost data shard;
    jerasure and ISA 12+4 fine on both
  • parity shards pulled off BlueStore with ceph-objectstore-tool match what the plugin
    computes outside the OSD, wrong sub-chunks at exactly the misaligned offsets
  • with the patched libec_clay.so: degraded reads correct with up to 3 shards down, backfill
    plus deep-scrub clean, and rewritten objects clean
profile sub-chunk bytes main this PR
k=2 m=2, k=4 m=2, k=4 m=3/4 256-1024 ok ok
k=8 m=3, k=8 m=4, k=6 m=4 64 ok ok
k=6 m=3 d=8 160 broken ok
k=10 m=4, k=12 m=4, k=16 m=4 32 broken ok

Will backport to tentacle once this is reviewed.

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)
    • Includes unit test(s)
    • Includes integration test(s)
    • Includes bug reproducer
    • No tests

Since 216eb26 raised ErasureCode::SIMD_ALIGN from 32 to 64, CLAY
realigns sub-chunk views that are smaller than SIMD_ALIGN (32 bytes for
k=12 m=4 d=15) before decoding into them. The realign copies the view,
the inner decode writes into the copy and the result is lost. Encode
goes through the same path, so parity is written wrong, and degraded
reads return uninitialised memory.

Don't realign the sub-chunk views that are written in place; assert
that they are contiguous instead. The repair path still realigns its
inputs, which come from the read reply and may be misaligned. Add an
enabled round-trip test with 32-byte sub-chunks.

Fixes: https://tracker.ceph.com/issues/80848
Reported-by: Michal Strnad
Signed-off-by: Lumir Sliva <[email protected]>
@github-actions

Copy link
Copy Markdown

Thank you for your contribution. Since you are not yet a member of the Ceph organization with write permissions on ceph/ceph.git, our CI will not automatically run. Any member of the Ceph organization may label this PR ci-approved to allow Jenkins CI jobs to run.

@mheler

mheler commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Related #71927

@lumir-sliva

Copy link
Copy Markdown
Contributor Author

Related #71927

Thanks, I went through it, they don't overlap:

  • osd: Remove sub-chunk support in Fast EC #71927 removes sub-chunk support from Fast EC (ECBackend/ECCommon, crimson, and the new-API minimum_to_decode() signature). It doesn't touch ErasureCodeClay.cc or the legacy ECBackendL/ECCommonL path, and this PR only touches ErasureCodeClay.cc and its test, so no conflict either way.
  • CLAY never runs on Fast EC in the first place. The mon refuses allow_ec_optimizations on a CLAY profile because the plugin doesn't advertise FLAG_EC_PLUGIN_OPTIMIZED_SUPPORTED ("ec optimizations not currently supported for pool profile" in OSDMonitor.cc). So every CLAY pool is on the legacy path, and the bug here is in the plugin itself, so osd: Remove sub-chunk support in Fast EC #71927 neither fixes nor affects it.

On whether CLAY is still worth fixing, this is how I read the code and docs:

  • tentacle: supported and not deprecated, and tentacle is supported until 2027-06-01 per doc/releases/releases.yml
  • umbrella: deprecated (ce1cbb1, plus the DEPRECATED_EC_PLUGIN health warning from 8b94da2), but still ships
  • Vampire: planned removal

So CLAY is on its way out, but it's there today, and public telemetry still shows CLAY pools (https://telemetry-public.ceph.com/d/b5664aff-721e-4c8a-b79a-7d3e2a8eaf07/ec-plugin). Anyone on tentacle with 12+4, 10+4, 16+4 or 6+3 is writing bad parity right now, and a lost data shard means lost data, so this needs to reach them in a tentacle point release. It's also worth a line in the tentacle release notes telling those users to migrate to a supported profile, since they'll have to move off CLAY before Vampire anyway and have to rewrite that data regardless.

@lumir-sliva
lumir-sliva marked this pull request as ready for review September 24, 2026 13:44
@lumir-sliva
lumir-sliva requested a review from a team as a code owner September 24, 2026 13:44
@batrick batrick mentioned this pull request Sep 24, 2026
4 of 14 tasks

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

The fix looks good.

Any CLAY profile with a sub chunk size that isn't a multiple of SIMD_ALIGN will copy the parity/decode output buffers, write the result into the copy, and then discard it. So encode produces the wrong parity, and decode returns garbage. At SIMD_ALIGN=32, the realign on those buffers was a no-op, which is why this has only been exposed now. These buffers don't actually need alignment. The fix correctly stops realigning them and keeps alignment only for the helper data, which I think is the only input that can arrive misaligned.

I've run the new unit test with and without the fix and confirmed it fails without the fix, and passes with it.

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath15-testing-20260929.043152-main.

@ljflores

Copy link
Copy Markdown
Member

@ljflores
ljflores merged commit dffaf99 into ceph:main Sep 29, 2026
22 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.

7 participants