Repository navigation
static-delta: Avoid copying bspatch output - #3554
Conversation
|
Hi @razzeee. Thanks for your PR. I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
There was a problem hiding this comment.
Code Review
This is a great approach to solving the OOM issue with large deltas. Using a memory-mapped temporary file is a solid strategy to reduce memory pressure. The implementation of reading the patched data in chunks is also well done.
However, I've found a critical issue with the handling of zero-sized output files. The new implementation using mmap will fail in this case, which was handled correctly by the previous g_malloc0 implementation. This would cause a regression for any delta that results in a zero-byte file.
I've added a few detailed comments with suggestions on how to fix this by special-casing when content_size is zero. Please take a look. With these changes, this should be a very robust improvement!
simonmicro
left a comment
There was a problem hiding this comment.
I would be interested to learn more about your reasoning behind changing the code around _ostree_repo_bare_content_write.
|
Sorry about the delay in review. This will need a rebase. But bigger picture - I think what we should try to do here is actually pass the tempfile down into the commit path because that code is also going to allocate a tempfile and then commit, so we're just copying data from one tempfile to another... |
6e2df36 to
cb66c5b
Compare
|
The failing job seems to be unrelated |
There was a problem hiding this comment.
🟡 Changes recommended
The mapped-output path introduces data-integrity and disk-exhaustion failure risks.
2 open findings
What changed in this PR
Reduces static-delta patch memory usage by writing bspatch output directly into a mapped temporary file instead of copying a heap buffer.
Changes:
- Adds mapped-output allocation, checksum calculation, and cleanup.
- Switches patch execution to the mapped-content helpers.
- Extends private state to track mappings.
| File | Description |
|---|---|
| src/libostree/ostree-repo-static-delta-processing.c | Uses mapped output for bspatch. |
| src/libostree/ostree-repo-private.h | Declares mapping helpers and expands private storage. |
| src/libostree/ostree-repo-commit.c | Implements mapping lifecycle and checksum handling. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| static const char zeros[64 * 1024] = { 0 }; | ||
| for (size_t offset = 0; offset < real->content_len;) |
| if (G_UNLIKELY (real->bytes_written != 0)) | ||
| return glnx_throw (error, "Cannot map bare content after writing"); |
Close the read source and release its object name and retained xattrs at the common exit, including when an opcode fails before closing the object.
Map patch output into the content writer tempfile instead of allocating a file-sized heap buffer and copying it. Reserve storage before mapping, with bounded writes and a flush when preallocation is unsupported. Checksum only appended bytes and restore the write offset after unmapping. Cover empty and multi-chunk output, subsequent writes, writes before patches, and repeated patches through the offline executor.
Force ENOSYS and EOPNOTSUPP, then verify stored bytes and checksums across patch/write sequences. Inject write and sync errors and check error propagation, missing target objects, and temporary-file cleanup.
|
I've separated this into multiple commits now, to help with review, as it increased a bit in line count. |
| if (!G_IN_SET (errno, ENOSYS, EOPNOTSUPP)) | ||
| return glnx_throw_errno_prefix (error, "fallocate"); | ||
|
|
||
| /* Materialize the backing file without a file-sized heap allocation. |
There was a problem hiding this comment.
Hmmm I think glibc posix_fallocate has this fallback already
|
|
||
| /* Map the writer's own temporary file, avoiding a separate patch buffer and copy. */ | ||
| gboolean | ||
| _ostree_repo_bare_content_map (OstreeRepoBareContent *barewrite, guint8 **out_buf, |
There was a problem hiding this comment.
I think this is OK as is but I'd prefer if we returned the length alongside the buf as a followup - kind of like a Rust slice. It's too bad glib (or glibc, or C) don't have a standard type for this, in Rust it's just &mut [u8] of course.



Hey,
my C is very bad, so this was found and done with AI. After looking at the reports an flatpak/flatpak#6255
I would expect this, to be slightly less performant, but work more reliably on systems with less RAM. Most of the things we do here, also seem to have been done in other code files here and there, so it doesn't seem to be unprecedented to go this route.
I haven't been able to runtime test this and I'm unsure how - especially validating, that it still works in the wild (e.g. doesn't break deltas)