Skip to content

Conversation

tmds
Copy link
Member

@tmds tmds commented Jun 30, 2025

(By default) Linux allows 128 inotify instances per user. By sharing the inotify instance between the FileSystemWatchers we reduce contention with other applications.

Fixes #62869.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 30, 2025
@tmds
Copy link
Member Author

tmds commented Jun 30, 2025

@dotnet/area-system-io @stephentoub ptal.

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

@tmds big thanks for your contribution! For now I've reviewed 25% of this PR (I need to wrap my head around all the locks and it's going to take me a while), PTAL at my comments.

@tmds
Copy link
Member Author

tmds commented Jul 2, 2025

For the locking, this overview may be helpful:

  • watcherslock: guards the list of Watcher
  • lock on Watcher: guards its tree of WatchedDirectory
  • lock on Watch: guards its list of WatchedDirectory
  • addLock: this reader writer lock enables concurrent adding of watches ("readers"), but no watches may be added while an inotify watch is removed ("writer")

To prevent deadlocks, the locks (as needed) are taken in this order: watchersLock, addLock, lock on Watcher, lock on Watch.

@tmds
Copy link
Member Author

tmds commented Jul 7, 2025

@adamsitnik this is a challenge to review so feel free to ask any questions you have while looking at the code.

I'm also going to make some time this week to look at the PR with my reviewer's hat on.

@tmds
Copy link
Member Author

tmds commented Jul 10, 2025

@adamsitnik I'll be on an extended break starting next week. I wonder if you have any additional feedback/questions that I can still look into tomorrow.

If we'd like to address #62869, I think this is the way to go.
There's a cost in code complexity as we can no longer consider each inotify watch to be owned by a single FileSystemWatcher.

I don't think we need to rush this in. It would be good to have some target date in mind so this doesn't get postponed indefinitely.

@tmds
Copy link
Member Author

tmds commented Aug 18, 2025

@adamsitnik @stephentoub where do you want to go with this? Do you want to target .NET 10? Or perhaps defer to early .NET 11?

@jeffhandley
Copy link
Member

We will target .NET 11 for this, @tmds. Thanks for your patience. It might take some more time for @adamsitnik to get back to reviewing it. I'm also adding @jozkee as a reviewer to help and load-balance with Adam (I'll let them coordinate if/how to divide the reviewing).

@jeffhandley jeffhandley added this to the 11.0.0 milestone Sep 2, 2025
@jeffhandley jeffhandley requested a review from jozkee September 2, 2025 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.IO community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileSystemWatcher on Linux uses an excessive amount of resources

4 participants