Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1174800 > unrolled thread
| Started by | Dave Hansen <dave@sr71.net> |
|---|---|
| First post | 2015-07-01 00:10 +0200 |
| Last post | 2015-07-01 11:00 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH 1/3] fs: optimize inotify/fsnotify code for unwatched files Dave Hansen <dave@sr71.net> - 2015-07-01 00:10 +0200
Re: [PATCH 1/3] fs: optimize inotify/fsnotify code for unwatched files Jan Kara <jack@suse.cz> - 2015-07-01 11:00 +0200
| From | Dave Hansen <dave@sr71.net> |
|---|---|
| Date | 2015-07-01 00:10 +0200 |
| Subject | [PATCH 1/3] fs: optimize inotify/fsnotify code for unwatched files |
| Message-ID | <pHbT5-6y3-59@gated-at.bofh.it> |
From: Dave Hansen <dave.hansen@linux.intel.com> I have a _tiny_ microbenchmark that sits in a loop and writes single bytes to a file. Writing one byte to a tmpfs file is around 2x slower than reading one byte from a file, which is a _bit_ more than I expecte. This is a dumb benchmark, but I think it's hard to deny that write() is a hot path and we should avoid unnecessary overhead there. I did a 'perf record' of 30-second samples of read and write. The top item in a diffprofile is srcu_read_lock() from fsnotify(). There are active inotify fd's from systemd, but nothing is actually listening to the file or its part of the filesystem. I *think* we can avoid taking the srcu_read_lock() for the common case where there are no actual marks on the file. This means that there will both be nothing to notify for *and* implies that there is no need for clearing the ignore mask. This patch gave a 13.1% speedup in writes/second on my test, which is an improvement from the 10.8% that I saw with the last version. Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Jan Kara <jack@suse.cz> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Eric Paris <eparis@redhat.com> Cc: John McCutchan <john@johnmccutchan.com> Cc: Robert Love <rlove@rlove.org> Cc: Andi Kleen <ak@linux.intel.com> Cc: linux-kernel@vger.kernel.org --- b/fs/notify/fsnotify.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff -puN fs/notify/fsnotify.c~optimize-fsnotify fs/notify/fsnotify.c --- a/fs/notify/fsnotify.c~optimize-fsnotify 2015-06-30 15:03:56.819399401 -0700 +++ b/fs/notify/fsnotify.c 2015-06-30 15:03:56.822399536 -0700 @@ -205,6 +205,16 @@ int fsnotify(struct inode *to_tell, __u3 mnt = NULL; /* + * Optimization: srcu_read_lock() has a memory barrier which can + * be expensive. It protects walking the *_fsnotify_marks lists. + * However, if we do not walk the lists, we do not have to do + * SRCU because we have no references to any objects and do not + * need SRCU to keep them "alive". + */ + if (hlist_empty(&to_tell->i_fsnotify_marks) && + (!mnt || hlist_empty(&mnt->mnt_fsnotify_marks))) + return 0; + /* * if this is a modify event we may need to clear the ignored masks * otherwise return if neither the inode nor the vfsmount care about * this type of event. _ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Jan Kara <jack@suse.cz> |
|---|---|
| Date | 2015-07-01 11:00 +0200 |
| Subject | Re: [PATCH 1/3] fs: optimize inotify/fsnotify code for unwatched files |
| Message-ID | <pHm26-2Wc-7@gated-at.bofh.it> |
| In reply to | #1174800 |
On Tue 30-06-15 15:04:55, Dave Hansen wrote: > > From: Dave Hansen <dave.hansen@linux.intel.com> > > I have a _tiny_ microbenchmark that sits in a loop and writes > single bytes to a file. Writing one byte to a tmpfs file is > around 2x slower than reading one byte from a file, which is a > _bit_ more than I expecte. This is a dumb benchmark, but I think > it's hard to deny that write() is a hot path and we should avoid > unnecessary overhead there. > > I did a 'perf record' of 30-second samples of read and write. > The top item in a diffprofile is srcu_read_lock() from > fsnotify(). There are active inotify fd's from systemd, but > nothing is actually listening to the file or its part of > the filesystem. > > I *think* we can avoid taking the srcu_read_lock() for the > common case where there are no actual marks on the file. > This means that there will both be nothing to notify for > *and* implies that there is no need for clearing the ignore > mask. > > This patch gave a 13.1% speedup in writes/second on my test, > which is an improvement from the 10.8% that I saw with the > last version. > > Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> > Cc: Andrew Morton <akpm@linux-foundation.org> > Cc: Jan Kara <jack@suse.cz> > Cc: Al Viro <viro@zeniv.linux.org.uk> > Cc: Eric Paris <eparis@redhat.com> > Cc: John McCutchan <john@johnmccutchan.com> > Cc: Robert Love <rlove@rlove.org> > Cc: Andi Kleen <ak@linux.intel.com> > Cc: linux-kernel@vger.kernel.org Looks good. You can add: Reviewed-by: Jan Kara <jack@suse.com> Honza > --- > > b/fs/notify/fsnotify.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff -puN fs/notify/fsnotify.c~optimize-fsnotify fs/notify/fsnotify.c > --- a/fs/notify/fsnotify.c~optimize-fsnotify 2015-06-30 15:03:56.819399401 -0700 > +++ b/fs/notify/fsnotify.c 2015-06-30 15:03:56.822399536 -0700 > @@ -205,6 +205,16 @@ int fsnotify(struct inode *to_tell, __u3 > mnt = NULL; > > /* > + * Optimization: srcu_read_lock() has a memory barrier which can > + * be expensive. It protects walking the *_fsnotify_marks lists. > + * However, if we do not walk the lists, we do not have to do > + * SRCU because we have no references to any objects and do not > + * need SRCU to keep them "alive". > + */ > + if (hlist_empty(&to_tell->i_fsnotify_marks) && > + (!mnt || hlist_empty(&mnt->mnt_fsnotify_marks))) > + return 0; > + /* > * if this is a modify event we may need to clear the ignored masks > * otherwise return if neither the inode nor the vfsmount care about > * this type of event. > _ -- Jan Kara <jack@suse.cz> SUSE Labs, CR -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web