GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(chunk_engine): size syncing overwrites by payload length and zero-pad aligned tails by ApacheWang · Pull Request #468 · deepseek-ai/3FS

Conversation

@ApacheWang

@ApacheWang ApacheWang commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes two data-path bugs in Chunk::copy_on_write and Chunk::safe_write in src/storage/chunk_engine/src/alloc/chunk.rs:

  1. Syncing overwrites allocate based on the old chunk length instead of the incoming payload length.
    In Chunk::copy_on_write, new_len was computed as std::cmp::max(self.meta.len, offset + data.len() as u32) even when is_syncing is true, and new_chunk.meta.len was only narrowed back to offset + data.len() as u32 at the end. When replication/sync (ReliableForwarding -> is_syncing = true, offset = 0) replaces a larger chunk (e.g. 256 KiB / 512 KiB) with a smaller or empty payload:

    • The replacement slot is allocated from the old oversized size class instead of the target size class, wasting disk capacity and skewing used_size accounting (and failing unnecessarily with NoSpace when the old larger size class is full while the smaller target class still has free slots).
    • For a zero-length syncing overwrite (data.is_empty()), new_len stayed equal to self.meta.len, causing copy_on_write to flush self.meta.len.next_multiple_of(ALIGN_SIZE) bytes of stale thread-local Chunk::BUFFER contents to disk via pwrite even though the resulting chunk length is 0.
    • If truncate happened to be set alongside is_syncing and data.is_empty(), is_shrinking was also incorrectly triggered and incremented safe_write_truncate_shorten.
  2. Unaligned buffered writes flush stale thread-local Chunk::BUFFER bytes into the aligned tail on disk.
    Both Chunk::copy_on_write (non-shrinking buffered writes) and Chunk::safe_write (indirect append path) round the O_DIRECT write length up to ALIGN_SIZE (4096 bytes) using the shared thread-local Chunk::BUFFER, without zeroing vec[new_len..aligned_end]. Bytes left behind in Chunk::BUFFER by previous operations on unrelated chunks were written out to disk in the aligned tail block (whereas shrinking truncates already zeroed vec[new_len..len]).

Fix

  • In Chunk::copy_on_write:
    • Exclude is_syncing from is_shrinking and compute new_len = offset + data.len() as u32 when is_syncing is true, so both allocation size and pwrite length match the replacement payload (and skip pwrite entirely when new_len == 0).
    • Always zero vec[new_len as usize..len as usize] before new_chunk.pwrite on the buffered path.
    • Simplify new_chunk.meta.len = new_len.
  • In Chunk::safe_write (indirect append path):
    • Compute aligned_end = new_len.next_multiple_of(ALIGN_SIZE.into()) and zero vec[new_len..aligned_end] before self.pwrite.

Testing

Added two regression tests in src/storage/chunk_engine/src/core/engine.rs:

  • test_syncing_shrink_allocates_target_size_and_zero_pads_tail
  • test_unaligned_writes_zero_pad_aligned_tail

Both tests fail against main (0e876af) before the fix (wrong 256 KiB allocation on 4-byte syncing shrink, stale buffer bytes leaked in the aligned tail) and pass after the fix.

Full chunk_engine library test suite (RUST_TEST_THREADS=1 cargo test --lib on Linux):

  • test result: ok. 58 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ApacheWang
fix(chunk_engine): size syncing overwrites by payload length and zero…
cc332c5
…-pad aligned tails

Signed-off-by: bc15575202581 <[email protected]>
SF-Zhou
SF-Zhou approved these changes Nov 28, 2026
View reviewed changes

@SF-Zhou SF-Zhou left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@SF-Zhou
SF-Zhou merged commit e23f2af into deepseek-ai:main Nov 28, 2026
1 check passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@SF-Zhou SF-Zhou SF-Zhou approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@ApacheWang @SF-Zhou
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.