Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752808AbbFYA5M (ORCPT ); Wed, 24 Jun 2015 20:57:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39752 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751239AbbFYA5G (ORCPT ); Wed, 24 Jun 2015 20:57:06 -0400 Message-ID: <1435193823.19444.36.camel@redhat.com> Subject: Re: [RFCv2][PATCH 1/7] fs: optimize inotify/fsnotify code for unwatched files From: Eric Paris To: Dave Hansen Cc: dave.hansen@linux.intel.com, akpm@linux-foundation.org, jack@suse.cz, viro@zeniv.linux.org.uk, john@johnmccutchan.com, rlove@rlove.org, tim.c.chen@linux.intel.com, ak@linux.intel.com, linux-kernel@vger.kernel.org Date: Wed, 24 Jun 2015 19:57:03 -0500 In-Reply-To: <20150625001605.72553909@viggo.jf.intel.com> References: <20150625001605.72553909@viggo.jf.intel.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3216 Lines: 81 On Wed, 2015-06-24 at 17:16 -0700, Dave Hansen wrote: > From: Dave Hansen > > 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.8% 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 > Cc: Andrew Morton > Cc: Jan Kara > Cc: Al Viro > Cc: Eric Paris > Cc: John McCutchan > Cc: Robert Love > Cc: Tim Chen > Cc: Andi Kleen > 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-24 > 17:14:34.573109264 -0700 > +++ b/fs/notify/fsnotify.c 2015-06-24 17:14:34.576109399 -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: 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 (!to_tell->i_fsnotify_marks.first && > + (!mnt || !mnt->mnt_fsnotify_marks.first)) > + return 0; two useless peeps from the old peanut gallery of long lost.... 1) should you actually move this check up before the IN_MODIFY check? This seems like it would be by far the most common case, and you'd save yourself a bunch of useless conditionals/bit operations. 2) do you want to use hlist_empty(&to_tell->i_fsnotify_marks) instead, for readability (and they are static inline, so compiled code is the same) It is fine as it is. Don't know how much you want to try to bikeshed... -- 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/