linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Jan Kara <jack@suse.cz>, Jens Axboe <axboe@kernel.dk>,
	Christian Brauner <brauner@kernel.org>,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v3] fsnotify: optimize the case of no parent watcher
Date: Wed, 14 Feb 2024 12:23:10 +0100	[thread overview]
Message-ID: <20240214112310.ovg2w3p6wztuslnw@quack3> (raw)
In-Reply-To: <CAOQ4uxj-waY5KZ20-=F4Gb3F196P-2bc4Q1EDcr_GDraLZHsKQ@mail.gmail.com>

On Tue 13-02-24 21:45:56, Amir Goldstein wrote:
> On Wed, Jan 24, 2024 at 6:20 PM Amir Goldstein <amir73il@gmail.com> wrote:
> > On Wed, Jan 24, 2024 at 6:08 PM Jan Kara <jack@suse.cz> wrote:
> > > On Tue 16-01-24 14:53:00, Amir Goldstein wrote:
> > > > On Tue, Jan 16, 2024 at 2:04 PM Jan Kara <jack@suse.cz> wrote:
> > > > >
> > > > > On Tue 16-01-24 13:32:47, Amir Goldstein wrote:
> > > > > > If parent inode is not watching, check for the event in masks of
> > > > > > sb/mount/inode masks early to optimize out most of the code in
> > > > > > __fsnotify_parent() and avoid calling fsnotify().
> > > > > >
> > > > > > Jens has reported that this optimization improves BW and IOPS in an
> > > > > > io_uring benchmark by more than 10% and reduces perf reported CPU usage.
> > > > > >
> > > > > > before:
> > > > > >
> > > > > > +    4.51%  io_uring  [kernel.vmlinux]  [k] fsnotify
> > > > > > +    3.67%  io_uring  [kernel.vmlinux]  [k] __fsnotify_parent
> > > > > >
> > > > > > after:
> > > > > >
> > > > > > +    2.37%  io_uring  [kernel.vmlinux]  [k] __fsnotify_parent
> > > > > >
> > > > > > Reported-and-tested-by: Jens Axboe <axboe@kernel.dk>
> > > > > > Link: https://lore.kernel.org/linux-fsdevel/b45bd8ff-5654-4e67-90a6-aad5e6759e0b@kernel.dk/
> > > > > > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> > > > > > ---
> > > > > >
> > > > > > Jan,
> > > > > >
> > > > > > Considering that this change looks like a clear win and it actually
> > > > > > the change that you suggested, I cleaned it up a bit and posting for
> > > > > > your consideration.
> > > > >
> > > > > Agreed, I like this. What did you generate this patch against? It does not
> > > > > apply on top of current Linus' tree (maybe it needs the change sitting in
> > > > > VFS tree - which is fine I can wait until that gets merged)?
> > > > >
> > > >
> > > > Yes, it is on top of Christian's vfs-fixes branch.
> > >
> > > Merged your improvement now (and I've split off the cleanup into a separate
> > > change and dropped the creation of fsnotify_path() which seemed a bit
> > > pointless with a single caller). All pushed out.
> > >
> >
> 
> Jan & Jens,
> 
> Although Jan has already queued this v3 patch with sufficient performance
> improvement for Jens' workloads, I got a performance regression report from
> kernel robot on will-it-scale microbenchmark (buffered write loop)
> on my fan_pre_content patches, so I tried to improve on the existing solution.
> 
> I tried something similar to v1/v2 patches, where the sb keeps accounting
> of the number of watchers for specific sub-classes of events.
> 
> I've made two major changes:
> 1. moved to counters into a per-sb state object fsnotify_sb_connector
>     as Christian requested
> 2. The counters are by fanotify classes, not by specific events, so they
>     can be used to answer the questions:
> a) Are there any fsnotify watchers on this sb?
> b) Are there any fanotify permission class listeners on this sb?
> c) Are there any fanotify pre-content (a.k.a HSM) class listeners on this sb?
> 
> I think that those questions are very relevant in the real world, because
> a positive answer to (b) and (c) is quite rare in the real world, so the
> overhead on the permission hooks could be completely eliminated in
> the common case.
> 
> If needed, we can further bisect the class counters per specific painful
> events (e.g. FAN_ACCESS*), but there is no need to do that before
> we see concrete benchmark results.

OK, I think this idea is sound, I'd just be interested whether the 0-day
bot (or somebody else) is able to see improvement with this. Otherwise why
bother :)

> Jan,
> 
> Whenever you have the time, feel free to see if this is a valid direction,
> if not for the perf optimization then we are going to need the
> fsnotify_sb_connector container for other features as well.

So firstly the name fsnotify_sb_connector really confuses me. I'd save
"connector" names to fsnotify_mark_connector. Maybe fsnotify_sb_info?

Then I dislike how we have to specialcase superblock in quite a few places
and add these wrappers and what not. This seems to be mostly caused by the
fact that you directly embed fsnotify_mark_connector into fsnotify_sb_info.
What if we just put fsnotify_connp_t there? I understand that this will
mean one more pointer fetch if there are actually marks attached to the
superblock and the event mask matches s_fsnotify_mask. But in that case we
are likely to generate the event anyway so the cost of that compared to
event generation is negligible?

And I'd allocate fsnotify_sb_info on demand from fsnotify_add_mark_locked()
which means that we need to pass object pointer (in the form of void *)
instead of fsnotify_connp_t to various mark adding functions (and transform
it to fsnotify_connp_t only in fsnotify_add_mark_locked() after possibly
setting up fsnotify_sb_info). Passing void * around is not great but it
should be fairly limited (and actually reduces the knowledge of fsnotify
internals outside of the fsnotify core).

								Honza

-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2024-02-14 11:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-16 11:32 [PATCH v3] fsnotify: optimize the case of no parent watcher Amir Goldstein
2024-01-16 12:04 ` Jan Kara
2024-01-16 12:53   ` Amir Goldstein
2024-01-24 16:07     ` Jan Kara
2024-01-24 16:20       ` Amir Goldstein
2024-02-13 19:45         ` Amir Goldstein
2024-02-14 11:23           ` Jan Kara [this message]
2024-02-14 13:40             ` Amir Goldstein
2024-02-15  8:36               ` Jan Kara
2024-03-06 14:51                 ` Amir Goldstein
2024-03-08 16:00                   ` Jan Kara
2024-03-11 13:51                     ` Christian Brauner
2024-02-15 15:07           ` Jens Axboe

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=20240214112310.ovg2w3p6wztuslnw@quack3 \
    --to=jack@suse.cz \
    --cc=amir73il@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=linux-fsdevel@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).