Skip to content

Close torrent file descriptors on the disk thread.#849

Closed
j-c-m wants to merge 1 commit into
rakshasa:masterfrom
j-c-m:feature/disk-thread-close
Closed

Close torrent file descriptors on the disk thread.#849
j-c-m wants to merge 1 commit into
rakshasa:masterfrom
j-c-m:feature/disk-thread-close

Conversation

@j-c-m

@j-c-m j-c-m commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

This change keeps file closing from blocking main (ui / peers network activity). I have another PR to open which moves munmap and sync to the disk thread as well, these both help transfer rates and ui feel as they no longer block on the main thread.

Detach FileManager bookkeeping on main, then queue raw fds for ::close on rtorrent disk so least-active and close_all_files do not block the peer/UI thread on slow FS teardown.

Detach FileManager bookkeeping on main, then queue raw fds for ::close
on rtorrent disk so least-active and close_all_files do not block the
peer/UI thread on slow FS teardown.
@rakshasa

Copy link
Copy Markdown
Owner

Disk thread does hashing, so we don't want time-sensitive actions like freeing up fd's to be done there.

Seems this would be better as a separate class in torrent/system that you can pass fd's to close, it uses std::async and atomic signals, and if we're starving for fds you can call a function to block until fd closes have completed.

@j-c-m

j-c-m commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

I'll look at it (wondering if is better to just have another worker thread to handle close/munmap/msync vs std::async, was trying to avoid adding excess complexity). With #834 I went from running against almost whatever limit there was, to basically only a handful of open and active fds, which makes the dance around the file limit rare and allows libtorrent to tolerate time to close. (this PR does have close_fd_now() which blocks at the limit)

@rakshasa

Copy link
Copy Markdown
Owner

Check j-c-m-feature/disk-thread-close (not tested)

@rakshasa rakshasa closed this Jul 25, 2026
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