Skip to content

remotes/docker: throttle worker chunk buffers - #14311

Merged
samuelkarp merged 1 commit into
containerd:mainfrom
mxpv:fetcher
Oct 13, 2026
Merged

samuelkarp merged 1 commit into
containerd:mainfrom
mxpv:fetcher

Conversation

@mxpv

@mxpv mxpv commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

This PR addresses downloaded chunk data accumulating when the reader falls behind.

With max_concurrent_downloads and concurrent_layer_fetch_buffer set, containerd can use far more memory than intended limit (max_concurrent_downloads * concurrent_layer_fetch_buffer).

The download limiter bounds how many requests run at once, but downloaded chunk stays in memory until the reader consumes it. When the registry is faster than the content store write, chunks accumulate up to the size of the layer. We observed during node boots, when the daemon pull a lot of large images altogether.

This PR adds a per-layer sliding window, so we don't allocate chunks ahead. We download a new chunk only after the reader has consumed the oldest chunk in the window. A layer then holds at most chunk_size * max_workers of chunk buffers.

Copilot AI balanced review requested due to automatic review settings October 7, 2026 20:10

Copilot AI 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.

🔵 Needs a closer look

The core logic is sound and well tested, but concurrent download lifecycle changes warrant final human review.

0 open findings

What changed in this PR

Caps per-layer parallel-fetch memory using a sliding chunk window.

Changes:

  • Gates new chunk downloads on consumption of older chunks.
  • Handles cancellation and closes undispatched chunk writers.
  • Adds window, cancellation, error, and close-path tests.
File Description
core/​remotes/​docker/​fetcher.go Implements the bounded sliding window.
core/​remotes/​docker/​fetcher_test.go Adds coverage for windowing and termination paths.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@mxpv mxpv changed the title remotes/docker: cap memory allocated per layer remotes/docker: throttle worker chunk buffers Oct 7, 2026
Comment thread core/remotes/docker/fetcher.go Resolved
Comment thread core/remotes/docker/fetcher.go Resolved
With max_concurrent_downloads and concurrent_layer_fetch_buffer set,
containerd can use far more memory than intended. The download limiter
bounds how many requests run at once. A downloaded chunk stays in
memory until the reader consumes it. When the registry is faster than
the content store write, chunks accumulate up to the size of the layer.

Add a per-layer sliding window of max_workers chunks. Download a new
chunk only after the reader has consumed the oldest chunk in the
window. A layer then holds at most chunk_size * max_workers of chunk
buffers. When the fetch is cancelled, close the writers of chunks that
never reached a worker, as a reader would otherwise block on them
forever. Pooled buffers and other overhead add to total memory use.

Signed-off-by: Maksym Pavlenko <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 8, 2026 03:16

Copilot AI 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.

🔵 Needs a closer look

The concurrent buffer lifecycle and cancellation changes warrant final human validation despite focused test coverage.

0 open findings

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@mxpv mxpv added the cherry-pick/2.4.x Change to be cherry picked to release/2.4 label Oct 8, 2026
@github-project-automation github-project-automation Bot moved this from Needs Reviewers to Review In Progress in Pull Request Review Oct 13, 2026
@samuelkarp
samuelkarp added this pull request to the merge queue Oct 13, 2026
@mxpv

mxpv commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

/cherry-pick release/2.4

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@mxpv: once the present PR merges, I will cherry-pick it on top of release/2.4 in a new PR and assign it to you.

Details

In response to this:

/cherry-pick release/2.4

Instructions 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.

return err
}
for i := range numChunks {
if i >= parallelism {

@fuweid fuweid Oct 13, 2026 •

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.

just quick question, not blocker: so, only first one is slow, the i must wait for first one to close even if rest of them are idle. is it correct?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the i must wait for first one to close even if rest of them are idle. is it correct?

Chunks has equal size and belong to the same layer here.
I'd imagine what you're describing should be pretty rare?
Do you think of some kind of throttling scenario?

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.

I just recalled this one - #12811. Not sure it's rare case. We can keep eyes on that. It's trade-off. Your change introduces kind of head-of-line blocking which can avoid memory issue.

Merged via the queue into containerd:main with commit 8c451c9 Oct 13, 2026
51 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Oct 13, 2026
@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@mxpv: new pull request created: #14342

Details

In response to this:

/cherry-pick release/2.4

Instructions 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.

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

Labels

cherry-pick/2.4.x Change to be cherry picked to release/2.4 size/L

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants