-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SublimeText uses too many inotify instances in Linux #1195
Comments
Do you experience any slowdowns in ST usage (potentially because of this)? |
Not, really... I can't say as I don't have numbers for this. But indeed it causes problems in running other programs that need inotify instances and that are then unable to set it up because they're all taken. |
I have this issue as well. Sublime Text 3 (build 3114) uses all the inotify resources available, so things like Gulp can't actually operate. And that's after I've boosted the number available by 4x. To me it's actually a fairly major issue. |
I just spent a couple hours tracing a mysterious "Too many open files" in another application to sublime's insane inotify instance infatuation. This behaviour is super painful because the symptoms pop up anywhere in the system without an immediately obvious connection to the root cause. |
Just saw this break UnrealEngine4 cook under Linux. Work around is to shutdown sublime then cook. If I had the time to waste I'd suggest someone making a caching LD_PRELOAD lib to redirect inotify calls from sublime to one that cached overlapping instances to at least avoid the duplication. I didn't run an ltrace, but you could see how often they call inotify that way for stats. :) |
Just ran into this issue today. I can't build Yocto Project while Sublime Text 3 is open because all of the inotifies get used up. If I close Sublime, suddenly I can build. |
This same bug also affects |
This is a real problem that should be addressed. In plain language the application is stealing "handles" from all other apps and services on the system. Running this application can break nearly anything else on a system using inotify or APIs using inotify. Here's a bandaid for those suffering: By default I think you have 128 instances, and check out the usage from subl is 172. This means subl will actually break itself. You can see this happen when file changes do not update in the app.
|
For the record, I just ran the command after 10h of "not doing a lot" in ST with 3 projects and a couple files open each, and it uses 28 instances. |
From my understanding, inotify does not allow watching a whole directory tree, so every subfolder of the folders in your sidebar, plus every subfolder in your Packages folder must be watched by a separate inotify instance. I think the possible solutions are:
|
Mh @wbond ok, sure you need a watcher for each dir, but I guess there's a way for optimizing it... For example, I'm using syncthing-inotify, and here it currently monitors Well, it just creates one instance. Compare:
|
@wbond All I know is that VSCode and Atom do not have this problem of gobbling up inotifies while Sublime does. I can use VSCode at the same time I am using Yocto Project or angular-cli - not so with Sublime 3. What is Sublime 3 even watching files for? angular-cli watches files so it knows when to automatically recompile typescript files. What is Sublime watching files for? |
@3v1n0 I've never use syncthing. It looks like from your commandline it perhaps rescans your filesystem every 5 seconds? The readme recommends setting your machine to have 200k watches… @RPGillespie6 From my experience (which is limited) VSCode and Atom provide a very different user experience. A few things that Sublime Text does with inotify watches:
I'm sure there are more, but those are just off the top of my head. Is there an issue with increasing the number of watches on your machine? 105 doesn't seem too bad. Ubuntu 10.04 (which I hope you aren't still using) defaulted to 8k user watches. syncthing-inotify recommends 200k watches. guard recommend 500k watches. Am I missing something here? |
A single inotify instance can be used to subscribe to notifications in any number of directories. There is no good reason for a single process to use more than a couple instances; certainly not one per watched directory. You are correct in that it is possible to avoid this issue by modifying the limit (and indeed, I have done so, so this issue no longer affects me). Unfortunately, the default limit is easily reached in normal use, and it is extremely difficult to correctly diagnose the problem and resolve it. In my case, the issue manifested with intermittent EMFILE errors in my build process. I spent significant time poking around messing with that processes rlimits, system limits, trying to find a fd leak, etc. None of that lead anywhere, and the only thing I had to go on was that my build was consistently failing to create inotify instances, and not any other fds. I did some more poking, and only then discovered that notify instances were covered by a different limit (not shown in any typical tool). Further futzing (standard tools like lsof not being able to tell you about inotify instances) eventually fingered Sublime as the responsible party. This is horrific UX! As things stand, Sublime's sloppy resource use starves random innocent processes! Worse, the resource in question is rather obscure, not exposed by typical diagnostic tools (rlimit, lsof), and generally hard to trace back. Sublime itself apparently silently ignores the errors it gets creating additional instances, and just intermittently fails to reload files, instead of some sort of error message that might tip the user off on the root cause of all the breakage. |
I think I was imprecise with my terminology a few comments ago. I am also no expert in inotify, I am just trying to help in diagnosing if there is a real issue here, or if this is just the nature of the beast. I am reviewing the Linux file notification code now. Here is how works:
I was interchangeably referring to instances and watches. We utilize an instance per distinct sidebar folder, for the So, out of the box, Sublime Text will utilize 4 + n instances, where n is the number of folders open in the sidebars of all Sublime Text windows. However, it appears that an instance is set up for the directory containing a file when it is opened. I have yet to work in this part of the codebase, so I am not familiar with exactly what it is doing and why, but I know it deals with monitoring a file for changes. I know there is a fair amount of complexity here because files can be opened from filesystems that don't support inotify, so there are fallback mechanisms to ensure that the user is notified if a file is modified while they are working on it. There is a fair amount going on in the implementation, and I don't have the time right at the moment to immerse myself in it. I'll follow up in the future to see if I find some way to reduce the number of instances. |
Mh, I see... Thanks for the explaination. Using GIO FileMonitor isn't an option here? As you'd avoid to care about different file systems too. |
Since it sounds like this isn't exactly an easy fix, in the interim, an obvious error message along the lines of "Unable to watch directory because system watch limit has been reached. Raising the system limit is recommended. This situation may also cause other applications that use inotify to misbehave." would go a long way. (There's a specific errno for this, and there's no way Sublime isn't also getting hit by it, so it should be pretty easy to detect). The worst part of the problem is that it manifests as intermittent misbehaviour of random applications, and is hard to diagnose. A strong indication of the root cause and corrective action would turn this into a minor annoyance. |
I did not encounter a problem where other applications misbehaved, but I had the problem where the sidebar was not updated when new files were created in a folder in my project. I can confirm that in my case the bottleneck is definitely the number of instances and not the number of watches (where the default value is 128 instances not 8K like the watches). To make things worse, I work on a server where I don't have admin access to tweak that number and where other coworkers also use sublime, so the 128 instances are shared between all of us. I don't know inotify except for what is mentioned in this thread, but I sure hope there can be a way to make sublime use watches instead of instances to achieve the same behavior. |
Hello, I raised For me this does not induce a high CPU load, Sublime is very quiet in terms of resources. But it does consumes CPU when Sublime cannot create that amount of watches. It also makes trouble at seeing new files even created from Sublime, in the project files tree. Also, maybe I should create a separate issue for this, but could Sublime notify about the lack of watches on the system? I discovered this by using Edit: i use the latest SublimeText 3 Nightly, on ArchLinux with kernel 4.11.9. |
Hello, There are too many git instances n the version Build 3143. See below ps -aex on MacOS. After a while, nothing opens up and I get "Too many processes" and all of a sudden MacOS reboots informing that there's an issue with the OS. Please let me know if you require additional debug info.. Devendras-MacBook-Pro:~ devnaga$ ps -aex | grep git | wc -l 41376 ?? 0:00.00 (git) |
Sublime Text doesn't run git by itself, so this must be some plugin's work. I suggest disabling a few (git-related) packages and trying to find the one causing these many unclodes git processes. |
This was fixed in build 3158. |
I'm on ST3, Build 3207 and ST again eats all watchers that it can (8K on the system):
Is this related to the TypeScript plugin or is the bug back? Maybe a workaround would be to add a project-specific exclude list of folders. By default, that should include:
since those folders usually contain thousands of files and devs will rarely look into them. |
ditto @digulla's comment, this is not fixed. ST3 build 3211, can't run
|
@wbond
EDIT: |
Also seeing this problem on 3211. I tried disabling indexing and git but that didn't seem to help |
I'm quite heavily using SublimeText... And it's not uncommon that I've 7-8 windows of it open, where at least two or three projects have may opened files too.
However, it seems that SublimeText uses too many inotify instances even in this case. In fact, I'm running also other programs that are doing file monitoring (such as cloud sync ones), but they just use one or two inotify instances. Sublime Text seems to abuse of them.
You can check which process uses inotify, with this command:
and this is result for me (this is running in Ubuntu, and I've only included the first results, out of 53 processes):
So, as you can see the sublime text inotify count is way over the average, outdistancing any other program (even the nautilus filemanger, never uses more than one inotify instance).
Considering that in many distros the default value for
fs.inotify.max_user_instances
is set to 1024, sublime could cause the inotify service not to be avilable to other processes.I've not checked the internals, but I'm quite sure there's a way to reduce the usage of inotify instances, even keeping the monitor active for many views. As the GFileMonitor (python API) allows to do.
The text was updated successfully, but these errors were encountered: