All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH] fs: optimize inotify/fsnotify code for unwatched files
@ 2015-06-19 21:50 Dave Hansen
  2015-06-19 23:33 ` Andi Kleen
  2015-06-23 15:17 ` Jan Kara
  0 siblings, 2 replies; 20+ messages in thread
From: Dave Hansen @ 2015-06-19 21:50 UTC (permalink / raw)
  To: dave
  Cc: dave.hansen, akpm, jack, viro, eparis, john, rlove, tim.c.chen,
	ak, linux-kernel


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
being modified *or* the vfsmount.

The *_fsnotify_mask is an aggregate of each of the masks from
each mark.  If we have nothing set in the masks at all then there
are no marks and no need to do anything with 'ignored masks'
since none exist.  This keeps us from having to do the costly
srcu_read_lock() for a check which is very cheap.

This patch gave a 10.8% speedup in writes/second on my test.

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: Tim Chen <tim.c.chen@linux.intel.com>
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-19 13:29:53.117283581 -0700
+++ b/fs/notify/fsnotify.c	2015-06-19 13:29:53.123283853 -0700
@@ -213,6 +213,16 @@ int fsnotify(struct inode *to_tell, __u3
 	    !(test_mask & to_tell->i_fsnotify_mask) &&
 	    !(mnt && test_mask & mnt->mnt_fsnotify_mask))
 		return 0;
+	/*
+	 * Optimization: The *_fsnotify_mask is an aggregate of each of the
+	 * masks from each mark.  If we have nothing set in the masks at
+	 * all then there are no marks and no need to do anything with
+	 * 'ignored masks' since none exist.  This keeps us from having to
+	 * do the costly srcu_read_lock() for a check which is very cheap.
+	 */
+	if (!to_tell->i_fsnotify_mask &&
+	    (!mnt || !mnt->mnt_fsnotify_mask))
+		return 0;
 
 	idx = srcu_read_lock(&fsnotify_mark_srcu);
 
_
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2015-06-24 17:29 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-19 21:50 [RFC][PATCH] fs: optimize inotify/fsnotify code for unwatched files Dave Hansen
2015-06-19 23:33 ` Andi Kleen
2015-06-20  0:29   ` Paul E. McKenney
2015-06-20  0:39   ` Dave Hansen
2015-06-20  2:21     ` Paul E. McKenney
2015-06-20 18:02       ` Dave Hansen
2015-06-21  1:30         ` Paul E. McKenney
2015-06-22 13:28           ` Peter Zijlstra
2015-06-22 15:11             ` Paul E. McKenney
2015-06-22 15:20               ` Peter Zijlstra
2015-06-22 16:29                 ` Paul E. McKenney
2015-06-22 19:03                   ` Peter Zijlstra
2015-06-23  0:31                     ` Paul E. McKenney
2015-06-22 18:50               ` Dave Hansen
2015-06-23  0:26                 ` Paul E. McKenney
2015-06-24 16:50                   ` Dave Hansen
2015-06-24 17:29                     ` Paul E. McKenney
2015-06-22 18:52               ` Peter Zijlstra
2015-06-23  0:29                 ` Paul E. McKenney
2015-06-23 15:17 ` Jan Kara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.