Skip to content

tsi: release the control socket and addresses in tsi_release - #1

Open
ethannortharc wants to merge 1 commit into
libkrun:libkrunfw-linux-6.12.xfrom
ethannortharc:tsi-release-control-socket
Open

ethannortharc wants to merge 1 commit into
libkrun:libkrunfw-linux-6.12.xfrom
ethannortharc:tsi-release-control-socket

Conversation

@ethannortharc

Copy link
Copy Markdown

tsi_create_common() (every socket()) and tsi_accept() (every accepted connection) give each TSI socket its own control socket (tsk->csocket, an AF_VSOCK datagram socket), and bind()/sendto() may allocate tsk->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>/fd and drop_caches cannot reclaim them: only /proc/sys/fs/inode-nr and SUnreclaim keep 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 of SUnreclaim (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 on wip/tsiv4-7.3 already does, for the TSIv3 code that libkrunfw 5.x ships.

Reproducer

In a guest with TSI:

sync; echo 2 > /proc/sys/vm/drop_caches; cat /proc/sys/fs/inode-nr
python3 -c 'import socket
for _ in range(1000): socket.socket(socket.AF_INET).close()'
sync; echo 2 > /proc/sys/vm/drop_caches; cat /proc/sys/fs/inode-nr

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:

  • 1,000 sockets plus 200 loopback TCP connections, made and closed: 1,399 inodes left behind before the patch, none after.
  • A guest running its normal workload for 17 hours: inode-nr and SUnreclaim stayed flat (before: about +4,400 inodes and +11 MB an hour while idle).

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>
@Liamso

Liamso commented Nov 14, 2026

Copy link
Copy Markdown

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants