Skip to content

fix(ckpt): reap finished tasks in accept loop - #2554

Open
qiwu575757 wants to merge 1 commit into
alibaba:mainfrom
qiwu575757:fix/ckpt/listener-joinset-leak
Open

fix(ckpt): reap finished tasks in accept loop#2554
qiwu575757 wants to merge 1 commit into
alibaba:mainfrom
qiwu575757:fix/ckpt/listener-joinset-leak

Conversation

@qiwu575757

Copy link
Copy Markdown

The accept loop spawned every connection into a JoinSet but only reaped it at shutdown, so the set kept one entry — task handle plus output slot — for each connection that had already finished. Every ws-ckpt CLI invocation opens one socket connection, so the daemon grew monotonically for its whole lifetime and only released the memory on exit.

Measured on 5.10.134-19.6.3 with ws-ckpt 0.4.2, the growth was linear in connection count and independent of both the storage backend and the kind of operation, which is what identified the connection path rather than snapshot state as the source:

btrfs-base 10h soak 7.8-7.9 KB per operation
btrfs-loop 10h soak 7.9-8.0 KB per operation
loop, direct-io, 10h 8.0 KB per operation
isolated 60s sample 8.4 KB per operation

VmData tracked VmRSS almost exactly (5418 MB of 5366 MB resident), the file descriptor count stayed flat, and the snapshot pool was held constant during the soaks, so the growth was heap held by the daemon rather than page cache, descriptors, or index state. A kill -9 returned RSS from 5.7 GB to 46 MB. Under a checkpoint-heavy agent workload this reaches roughly 370 MB/h, and about 1.7 GB/h under the functional suite, so a long-lived daemon eventually OOMs.

Drain completed tasks with try_join_next after each select iteration. It is synchronous, so reaping cannot delay the next accept, and it avoids the second mutable borrow of join_set that a join_next branch inside the same select! would need while the accept arm still spawns into the set. Shutdown still drains with join_next under the existing timeout, so in-flight connections keep their grace period.

After the change, 20000 operations grow RSS by 2.6 MB (0.13 KB per operation, down from ~8 KB), and a further 40000 operations add 2.0 MB in total with no linear trend, i.e. what remains is allocator headroom rather than accumulation. Descriptors stay at 14.

The accept loop spawned every connection into a `JoinSet` but only
reaped it at shutdown, so the set kept one entry — task handle plus
output slot — for each connection that had already finished. Every
ws-ckpt CLI invocation opens one socket connection, so the daemon grew
monotonically for its whole lifetime and only released the memory on
exit.

Measured on 5.10.134-19.6.3 with ws-ckpt 0.4.2, the growth was linear
in connection count and independent of both the storage backend and the
kind of operation, which is what identified the connection path rather
than snapshot state as the source:

  btrfs-base 10h soak      7.8-7.9 KB per operation
  btrfs-loop 10h soak      7.9-8.0 KB per operation
  loop, direct-io, 10h     8.0 KB per operation
  isolated 60s sample      8.4 KB per operation

VmData tracked VmRSS almost exactly (5418 MB of 5366 MB resident), the
file descriptor count stayed flat, and the snapshot pool was held
constant during the soaks, so the growth was heap held by the daemon
rather than page cache, descriptors, or index state. A `kill -9`
returned RSS from 5.7 GB to 46 MB. Under a checkpoint-heavy agent
workload this reaches roughly 370 MB/h, and about 1.7 GB/h under the
functional suite, so a long-lived daemon eventually OOMs.

Drain completed tasks with `try_join_next` after each select iteration.
It is synchronous, so reaping cannot delay the next accept, and it
avoids the second mutable borrow of `join_set` that a `join_next` branch
inside the same `select!` would need while the accept arm still spawns
into the set. Shutdown still drains with `join_next` under the existing
timeout, so in-flight connections keep their grace period.

After the change, 20000 operations grow RSS by 2.6 MB (0.13 KB per
operation, down from ~8 KB), and a further 40000 operations add 2.0 MB
in total with no linear trend, i.e. what remains is allocator headroom
rather than accumulation. Descriptors stay at 14.

Signed-off-by: Qi Wu <shijing.wq@alibaba-inc.com>
@qiwu575757
qiwu575757 requested a review from Ziqi002 as a code owner August 14, 2026 09:54
@github-actions github-actions Bot added the component:ckpt src/ws-ckpt label Aug 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e4040e7e90

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// awaits, so reaping cannot delay the next accept; a join_next branch in
// the select! above would instead need a second mutable borrow of
// join_set while the accept arm still spawns into it.
while join_set.try_join_next().is_some() {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Wake the listener when tasks finish

When a burst of clients is accepted and then no new client connects, this reap runs only immediately after an accept()/cancel select iteration. Any connection task that completes after the last accept does not wake this loop, so its JoinSet entry remains until another client connects or the daemon shuts down; with many concurrent checkpoint requests this can still retain one task allocation per request. Drive reaping from task completion itself, such as a join_next/poll branch or another wakeup source, rather than only after accepts.

Useful? React with 👍 / 👎.

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

Labels

component:ckpt src/ws-ckpt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant