Repository navigation
tsi: release the control socket and addresses in tsi_release - #1
Open
ethannortharc wants to merge 1 commit into
Open
ethannortharc wants to merge 1 commit into
ethannortharc wants to merge 1 commit into
Conversation
tsi_create_common() and tsi_accept() give every TSI socket its own control socket (tsk->csocket, an AF_VSOCK datagram socket), and bind() and sendto() may allocate tsk->bound_addr and tsk->sendto_addr, but tsi_release() frees none of them. Every socket() and every accepted connection in the guest therefore leaves a kernel vsock socket (a sockfs inode and its slab) behind until the VM stops. The leaked sockets have no file descriptor, so they never show up in /proc/<pid>/fd and drop_caches cannot reclaim them: only inode-nr and SUnreclaim keep growing. A long-running guest doing ordinary work leaked 4,000 to 9,000 of them an hour; after 25 hours, 166,000 leaked inodes and 288 MB of SUnreclaim (about 47 MB on a fresh boot). Release them in tsi_release(), as the TSIv4 rewrite already does. Signed-off-by: Ethan <ethan.northarc@gmail.com>
|
Hit this on a long-running guest: SUnreclaim grew ~150 MB/h until the OOM killer fired. Same change measured on 6.18.55, N=2000 each, read 95 s after close: IPv4 loopback 2531 → 6 B per connection, curl over loopback 3143 → 307 B, outbound 1343 → 0 B, AF_UNIX unchanged. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
tsi_create_common()(everysocket()) andtsi_accept()(every accepted connection) give each TSI socket its own control socket (tsk->csocket, an AF_VSOCK datagram socket), andbind()/sendto()may allocatetsk->bound_addr/tsk->sendto_addr.tsi_release()frees none of them, so every TSI socket leaves a kernel vsock socket (a sockfs inode and its slab) behind until the VM stops.The leaked sockets have no file descriptor, so they never show up in
/proc/<pid>/fdanddrop_cachescannot reclaim them: only/proc/sys/fs/inode-nrandSUnreclaimkeep growing. A long-running guest doing ordinary work (health checks, a browser, git) leaked 4,000 to 9,000 of them an hour; after 25 hours it had 166,000 leaked inodes and 288 MB ofSUnreclaim(about 47 MB on a fresh boot), and after several days processes in the guest were OOM-killed.This releases them in
tsi_release(), as the TSIv4 rewrite onwip/tsiv4-7.3already does, for the TSIv3 code that libkrunfw 5.x ships.Reproducer
In a guest with TSI:
Without the patch the first number grows by about 1,000 (one control socket per socket) and stays there.
Testing
Applied to libkrunfw 5.6.2 (Linux 6.12.109, whose
tsi_release()is identical to this branch's), on x86_64:inode-nrandSUnreclaimstayed flat (before: about +4,400 inodes and +11 MB an hour while idle).