linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jamie Lokier <jamie@shareable.org>
To: Ian Campbell <ijc@hellion.org.uk>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-cifs-client@lists.samba.org, "Asser Femø" <asser@diku.dk>
Subject: Re: dnotify/inotify and vfs questions
Date: Thu, 25 Aug 2005 15:57:50 +0100	[thread overview]
Message-ID: <20050825145750.GA6658@mail.shareable.org> (raw)
In-Reply-To: <1124973618.17190.9.camel@icampbell-debian>

Ian Campbell wrote:
> On Tue, 2005-08-23 at 16:23 +0100, Jamie Lokier wrote:
> >     <receive some request>...
> >     if (any_dnotify_or_inotify_events_pending) {
> >         read_dnotify_or_inotify_events();
> >         if (any_events_related_to(file)) {
> >             store_in_userspace_stat_cache(file, stat(file));
> >         }
> >     }
> >     stat_info = lookup_userspace_stat_cache(file);
> > 
> > Now that's a silly way to save one system call in the fast path by itself.
> 
> I'm not that familiar with inotify internals but doesn't
> read_dnotify_or_inotify_events() or
> any_dnotify_or_inotify_events_pending() involve a syscall?

The fast path is just any_dnotify_or_inotify_events_pending: there
aren't any relevant events pending in the fast path.

There's a few methods of doing this for free per individual stat cache check.

1. Signal handler.

    dnotify: Check a variable set by the signal handler.

         [ There's a small time window between dnotify sending the
         signal and the receiving thread noticing on an SMP system due
         to the IPI, during which the sending task might have another
         way to signal the recieving task that it's finished some
         operation, so this method of using dnotify to invalidate a
         stat cache only has the correct ordering properties on UP systems. ]

         This works because dnotify signals are thread-specific,
         so the checking thread will definitely have received the
         signal after the time another process modifies the file.
         
    inotify: Disappointingly inotify doesn't support SIGIO readiness :(

2. If you have to mix the test with a poll/select/epoll/rtsig fd waiting
   for some other purpose.  For example: a file/web/local server, where the
   constraint is only that each stat() to revalidate a cached response
   appears to happen any time after the beginning of receiving the
   network request is known.

    dnotify: It's free if you were using sigtimedwait anyway for I/O events,
             provided you completely read the queue, or get the signal
             priority right.

    inotify: It's free if you were using poll/select/epoll anyway for I/O
             events, provided in the case of epoll that you completely
             read the queue, or use a two-level queue.

3. Amortising the test over many stat cache checks.

   Even if you must use a system call to check for any pending events,
   for revalidating an object which depends on multiple files, only
   one call is needed for all of the stat cache checks.

   More generally (this is more flexible), you can separate the notion
   of "cache time checkpoint" from "cache validation".  It's enough to
   know that a stat result was valid any time between the checkpoint
   time, and the current time.  That's how I'm implementing the
   file/web/local server case described above in step 2.  Then the
   events only need to be checked once during that time interval, no
   matter how many complex objects are being revalidated.

   It gets slightly more efficient when you have multiple, overlapping
   checkpoint->validation time intervals due to multiple outstanding
   requests being processed concurrently.

As I explained in the previous mail, all this is absolutely pointless
to save one system call.  It's a lot of work for negligable gain.

The point is when it saves lots of calls and userspace logic together,
for things like web page templates and compiled programs, which depend
on many files which can be revalidated in a small number of operations.

-- Jamie

  reply	other threads:[~2005-08-25 14:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-23 13:00 dnotify/inotify and vfs questions Asser Femø
2005-08-23 15:23 ` Jamie Lokier
2005-08-25 12:40   ` Ian Campbell
2005-08-25 14:57     ` Jamie Lokier [this message]
2005-08-25 15:07       ` Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050825145750.GA6658@mail.shareable.org \
    --to=jamie@shareable.org \
    --cc=asser@diku.dk \
    --cc=ijc@hellion.org.uk \
    --cc=linux-cifs-client@lists.samba.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).