Skip to content

ct/l0: Share, don't copy, downloaded object when caching#29058

Merged
dotnwat merged 1 commit intoredpanda-data:devfrom
wdberkeley:l0-sharing-is-caring
Jan 6, 2026
Merged

ct/l0: Share, don't copy, downloaded object when caching#29058
dotnwat merged 1 commit intoredpanda-data:devfrom
wdberkeley:l0-sharing-is-caring

Conversation

@wdberkeley
Copy link
Copy Markdown
Contributor

Use iobuf::share not iobuf::copy to obtain an iobuf to read into the cloud storage cache. This eliminates an extra copy of a fairly hefty (~4MiB usually) buffer, reducing peak memory usage of the L0 fetch.

Very minor: I moved the creation of the input stream so it happens after we obtain the space reservation for the object.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v25.3.x
  • v25.2.x
  • v25.1.x

Release Notes

  • none

Use iobuf::share not iobuf::copy to obtain an iobuf to read into the
cloud storage cache. This eliminates an extra copy of a fairly hefty
(~4MiB usually) buffer, reducing peak memory usage of the L0 fetch.

Very minor: I moved the creation of the input stream so it happens
after we obtain the space reservation for the object.
Copilot AI review requested due to automatic review settings December 18, 2025 17:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes memory usage in the L0 cloud storage fetch path by using iobuf::share() instead of iobuf::copy() when caching downloaded objects. This eliminates an unnecessary copy of the ~4MiB buffer, reducing peak memory consumption during L0 fetches.

Key changes:

  • Replaced iobuf::copy() with iobuf::share() to avoid duplicating the downloaded payload buffer
  • Moved input stream creation to after space reservation acquisition

if (sr_guard.has_value()) {
// TODO: use proper priority class
probe->num_cache_writes++;
auto buf_str = make_iobuf_input_stream(payload.share());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it looks like you could make_iobuf_input_stream(std::move(payload)) which I think would be preferrable?

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.

We return std::move(payload) from this function so we can't move out of it here.

@wdberkeley wdberkeley requested a review from dotnwat January 6, 2026 18:00
@dotnwat dotnwat merged commit 8c22c50 into redpanda-data:dev Jan 6, 2026
20 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.

3 participants