git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] inotify to minimize stat() calls

From
RZRobert Zeh <robert.allan.zeh@gmail.com>
Date
Apr 25, 2013, 19:37 UTC
Message-ID
<CAKXa9=rvDQ7DXwCiTp9PTc55gNTW2UDZ4auaYG5tbboomrDAGQ@mail.gmail.com>
In-Reply-To
<87sj2f6n1u.fsf@linux-k42r.v.cablecom.net>
On Thu, Apr 25, 2013 at 3:18 AM, Thomas Rast <trast@inf.ethz.ch> wrote:
Show 13 quoted lines
>
> Robert Zeh <robert.allan.zeh@gmail.com> writes:
>
> > Here is a patch that creates a daemon that tracks file
> > state with inotify, writes it out to a file upon request,
> > and changes most of the calls to stat to use said cache.
> >
> > It has bugs, but I figured it would be smarter to see
> > if the approach was acceptable at all before spending the
> > time to root the bugs out.
>
> Thanks for tackling this; it's probably about time we got a inotify
> support :-(
Show 29 quoted lines
> > I've implemented the communication with a file, and not a socket,
> > because I think implementing a socket is going to create
> > security issues on multiuser systems.  For example, would a
> > socket allow stat information to cross user boundaries?
>
> This ties in with an issue discussed in an earlier thread:
>
>   http://thread.gmane.org/gmane.comp.version-control.git/217817/focus=218307
>
> The conclusion there was that the default limits are set such that it is
> not feasible to run one daemon per repository (that would quickly hit
> the limits when e.g. iterating all repos in a typical android tree using
> repo).
>
> So whatever you use for communication needs to work as a global daemon.
>
> I'd just trust the SSH folks to know about security; on my system
> ssh-agent creates
>
>   /tmp/ssh-RANDOMSTRING/agent.PID
>
> where the directory has mode 0700, and the file is a unit socket with
> mode 0600.  That should make doubly sure that no other user can open the
> socket.
>
> >  filechange-cache.c   | 203
> > +++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Is your MUA wrapping the patch?
Almost certainly.  I'll double check before I send off the next patch.
Show 24 quoted lines
> > +static void watch_directory(int inotify_fd)
> > +{
> > +     char buf[PATH_MAX];
> > +
> > +     if (!getcwd(buf, sizeof(buf)))
> > +             die_errno("Unable to get current directory");
> > +
> > +     int i = 0;
> > +     struct dir_struct dir;
> > +     const char *pathspec[1] = { buf, NULL };
> > +
> > +     memset(&dir, 0, sizeof(dir));
> > +     setup_standard_excludes(&dir);
> > +
> > +     fill_directory(&dir, pathspec);
> > +     for(i = 0; i < dir.nr; i++) {
> > +             struct dir_entry *ent = dir.entries[i];
> > +             watch_file(inotify_fd, ent->name);
> > +             free(ent);
> > +     }
>
> I don't get this bit.  The lstat() are run over all files listed in the
> index.  So shouldn't your daemon watch exactly those (or rather, all
> dirnames of such files)?

I believe that fill_directory is handling watching only files in the index. I had some problems a while back when I was only watching the directory with some of the inotify structures coming back empty, which is why I started watching each individual file.

> The actual directory contents are only needed to find untracked files,
> and there would be a lot of complication surrounding that, so I suggest
> saving that for later (and for now measuring the speedup with 'git
> status -uno'!).
The speed up test is a good idea.
> For example, you'd have to actually watch and re-read all .gitignore
> files, and the .git/info/exclude, and the core.excludesfile, to see if
> your notion of an ignored file became stale.

The thought in the back of my head was to simple have the daemon restart if one of those files changed, under the assumption that a restart wasn't that expensive, and that it would be complicated to check.

> Also, you seem to call watch_directory() only on the current(?) dir, but
> you need to recursively set up watches for all directories in the
> repository.

I'm calling fill_directory to get the list of files to watch; it appears to be handling the recursion for me. It also appears to be handling filtering out all of the untracked files, etc.

Show 27 quoted lines
> > +     while (1) {
> > +             int i = 0;
> > +             length = read(inotify_fd, buffer, sizeof(buffer));
> > +             for(i = 0; i < length; ) {
> > +                     struct inotify_event *event =
> > +                             (struct inotify_event*)(buffer+i);
> > +                     /* printf("event: %d %x %d %s\n", event->wd, event->mask,
> > +                        event->len, event->name); */
> > +                     if (request_watch_descriptor == event->wd) {
> > +                             write_stat_cache();
> > +                     } else if (root_directory_watch_descriptor
> > +                                == event->wd) {
> > +                             printf("root directory died!\n");
> > +                             exit(0);
> > +                     } else if (event->mask & IN_Q_OVERFLOW) {
> > +                             restart();
>
> Good.
>
> > +                     } else if (event->mask & IN_MODIFY) {
> > +                             if (event->len)
> > +                                     update_stat_cache(event->name);
> > +                     }
>
> So whenever a file changes, you stat() it.  That's good for simplicity
> now, but I suspect it will provide some optimization opportunities
> later.

I figured it would be a good idea to get things working, and then worry about optimization later :-)

>
> On some design aspects, I'd want:
>
> * a toggle to run the test suite with the daemons, or without
Yeap.
> * if you go with a user-wide daemon, a way to ensure that the test-suite
>   daemon is not the same as my "real" daemon, and make sure it is killed
>   after the test runs finish

I'm assuming a command line argument that points a daemon at a port would be the way to handle that.

> * a test that triggers IN_Q_OVERFLOW, e.g. by sending SIGSTOP and doing
>   a large repository operation

Yeap. I think you'd want some way to verify (through a log file?) that the overflow happened.

> * a test that renames directories
Yeap.
Show 8 quoted lines
> The last one is just based on my personal experience with messing with
> inotify; renaming directories is the "hard" case for that API.  We may
> already cover this in the test suite, or we may not; but it must be
> tested.
>
> Other than that last point, focus your tests not on small tests but on
> the test suite.  It would seem rather unlikely to me that you could
> manage to pass the entire test suite with this daemon active but broken.

I've had some experiences where the test suite passes with the daemon active, but not populating the cache.

> --
> Thomas Rast
> trast@{inf,student}.ethz.ch
Previous: Thomas RastNext: Thomas Rast
Message 80 of 88 in “inotify to minimize stat() calls”
  1. Ramkumar RamachandraFeb 8, 2013
  2. Junio C HamanoFeb 8, 2013
  3. Junio C HamanoFeb 8, 2013
  4. Duy NguyenFeb 9, 2013
  5. Junio C HamanoFeb 9, 2013
  6. Junio C HamanoFeb 9, 2013
  7. Robert ZehFeb 9, 2013
  8. Ramkumar RamachandraFeb 9, 2013
  9. Ramkumar RamachandraFeb 9, 2013
  10. Ramkumar RamachandraFeb 9, 2013
  11. Duy NguyenFeb 9, 2013
  12. Ramkumar RamachandraFeb 9, 2013
  13. Ramkumar RamachandraFeb 9, 2013
  14. Duy NguyenFeb 10, 2013
  15. Duy NguyenFeb 10, 2013
  16. Duy NguyenFeb 10, 2013
  17. Junio C HamanoFeb 10, 2013
  18. Duy NguyenFeb 11, 2013
  19. Duy NguyenFeb 11, 2013
  20. Torsten BögershausenMar 7, 2013
  21. Junio C HamanoMar 8, 2013
  22. Torsten BögershausenMar 8, 2013
  23. Junio C HamanoMar 8, 2013
  24. Torsten BögershausenMar 8, 2013
  25. Duy NguyenMar 8, 2013
  26. Ramkumar RamachandraMar 10, 2013
  27. status: hint the user about -uno if read_directory takes too longNguyễn Thái Ngọc Duy, Mar 13, 2013
  28. Torsten BögershausenMar 13, 2013
  29. Junio C HamanoMar 13, 2013
  30. Duy NguyenMar 14, 2013
  31. Junio C HamanoMar 14, 2013
  32. Duy NguyenMar 15, 2013
  33. Torsten BögershausenMar 15, 2013
  34. Ramkumar RamachandraMar 15, 2013
  35. Junio C HamanoMar 15, 2013
  36. Torsten BögershausenMar 15, 2013
  37. Junio C HamanoMar 15, 2013
  38. Torsten BögershausenMar 15, 2013
  39. Junio C HamanoMar 15, 2013
  40. Torsten BögershausenMar 16, 2013
  41. Junio C HamanoMar 17, 2013
  42. Duy NguyenMar 16, 2013
  43. demerphqFeb 10, 2013
  44. Duy NguyenFeb 10, 2013
  45. Magnus BäckFeb 14, 2013
  46. Ramkumar RamachandraFeb 10, 2013
  47. Duy NguyenFeb 11, 2013
  48. Erik Faye-LundFeb 10, 2013
  49. Duy NguyenFeb 11, 2013
  50. Karsten BleesFeb 12, 2013
  51. Duy NguyenFeb 13, 2013
  52. Duy NguyenFeb 13, 2013
  53. Jeff KingFeb 13, 2013
  54. Jeff KingFeb 13, 2013
  55. Karsten BleesFeb 13, 2013
  56. Jeff KingFeb 13, 2013
  57. Karsten BleesFeb 14, 2013
  58. name-hash.c: fix endless loop with core.ignorecase=trueKarsten Blees, Feb 27, 2013
  59. Junio C HamanoFeb 27, 2013
  60. Karsten BleesFeb 27, 2013
  61. name-hash.c: fix endless loop with core.ignorecase=trueKarsten Blees, Feb 27, 2013
  62. Junio C HamanoFeb 28, 2013
  63. Ramkumar RamachandraFeb 19, 2013
  64. Karsten BleesFeb 19, 2013
  65. Drew NorthupFeb 19, 2013
  66. Duy NguyenFeb 19, 2013
  67. Junio C HamanoFeb 9, 2013
  68. Robert ZehFeb 10, 2013
  69. Martin FickFeb 10, 2013
  70. Robert ZehFeb 10, 2013
  71. Duy NguyenFeb 11, 2013
  72. Robert ZehFeb 11, 2013
  73. Ramkumar RamachandraFeb 19, 2013
  74. Robert ZehApr 24, 2013
  75. Duy NguyenApr 24, 2013
  76. Robert ZehApr 25, 2013
  77. Duy NguyenApr 25, 2013
  78. Robert ZehApr 26, 2013
  79. Thomas RastApr 25, 2013
  80. Robert ZehApr 25, 2013
  81. Thomas RastApr 25, 2013
  82. Thomas RastApr 27, 2013
  83. Duy NguyenApr 27, 2013
  84. Ramkumar RamachandraFeb 9, 2013
  85. Ævar Arnfjörð BjarmasonFeb 14, 2013
  86. Junio C HamanoFeb 14, 2013
  87. Ramkumar RamachandraFeb 19, 2013
  88. Duy NguyenApr 30, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.