Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
77
rated 0 times [  77] [ 0]  / answers: 1 / hits: 54769  / 2 Years ago, wed, november 2, 2022, 12:36:42

I use an application that consumes inotify watches. I've already set



fs.inotify.max_user_watches=32768


in /etc/sysctl.conf but last night the application stopped indexing unless I ran it manually, which leads me to suspect I am out of watches.



Since I don't know what the trade off is when I increase this number (does it consume more RAM?), I don't know if I should just increase this number, so I'd like to know if there's a way I can tell if it's using all these watches and what the tradeoffs might be for increasing it.


More From » kernel

 Answers
2

How do you know if you are out of watches? tail will tell!




  • Start tail with the -f (follow) option on any old file, e.g. tail -f /var/log/dmesg:


    • If all is well, it will show the last 10 lines and pause; abort with Ctrl-C

    • If you are out of watches, it will fail with this somewhat cryptic error:

      tail: cannot watch '/var/log/dmsg': No space left on device




For the curious: Why is tail a "telltail"?




  • Actually, any well-written app should have the courtesy of telling you, since the inotify API/calls clearly tells them what the deal is.

  • Try strace tail -f ... instead, and when it succeeds, it ends with:


    inotify_add_watch(4, "/var/log/dmesg", IN_MODIFY...) = 1

  • but if it fails, i.e. you are out of watches, it'll say:


    inotify_add_watch(4, "/var/log/dmesg", IN_MODIFY..)
    = -1 ENOSPC (No space left on device)



Can you increase the watches? By how much? Any tradeoffs?



Short answer: Sure, no sweat. Go to straight to a half-million (524288) if you want...the additional memory used should be negligible on a modern system with 4GB+ of memory.




  • Each used inotify watch takes up 540 bytes (32-bit system), or 1 kB (double - on 64-bit) [sources: 1, 2]

  • This comes out of kernel memory, which is unswappable.

  • So, assuming you set the max at 524288, and all were used (improbable), you'd be using approx. 256MB/512MB of 32-bit/64-bit kernel memory




    • Note that your application will also use additional memory to keep track of the inotify handles, file/directory paths, etc. -- how much depends on its design.


  • What's the max value? I guess none, in theory, as long as you have enough RAM. In practice, 524288 has been officially recommended by apps, and people have been setting it to 2 million, with the accompanying memory usage, of course.



[#37385] Friday, November 4, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ticrew

Total Points: 190
Total Questions: 111
Total Answers: 99

Location: Fiji
Member since Wed, Jul 14, 2021
3 Years ago
;