mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Hansen <dave@sr71.net>
To: dave@sr71.net
Cc: jack@suse.cz, viro@zeniv.linux.org.uk,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	paulmck@linux.vnet.ibm.com, tim.c.chen@linux.intel.com,
	ak@linux.intel.com, dave.hansen@linux.intel.com
Subject: [RFCv2][PATCH 3/7] fs: fsnotify: replace memory barrier in __sb_end_write() with RCU
Date: Wed, 24 Jun 2015 17:16:06 -0700	[thread overview]
Message-ID: <20150625001606.E834E08B@viggo.jf.intel.com> (raw)
In-Reply-To: <20150625001605.72553909@viggo.jf.intel.com>


From: Dave Hansen <dave.hansen@linux.intel.com>

If I sit in a loop and do write()s to small tmpfs files,
__sb_end_write() is third-hottest kernel function due to its
smp_mb().

__sb_end_write() uses the barrier to avoid races with freeze_super()
and its calls to sb_wait_write().  But, now that freeze_super() is
calling synchronize_rcu() before each sb_wait_write() call, we can
use that to our advantage.

The synchronize_rcu() ensures that all __sb_end_write() will see
freeze_super()'s updates to s_writers.counter.  That, in turn,
guarantees that __sb_end_write() will try to wake up any subsequent
call by freeze_super() to sb_wait_write().

Cc: Jan Kara <jack@suse.cz>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
---

 b/fs/super.c |   17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff -puN fs/super.c~selectively-do-barriers-in-__sb_end_write fs/super.c
--- a/fs/super.c~selectively-do-barriers-in-__sb_end_write	2015-06-24 17:14:35.315142611 -0700
+++ b/fs/super.c	2015-06-24 17:14:35.318142745 -0700
@@ -1146,14 +1146,23 @@ out:
  */
 void __sb_end_write(struct super_block *sb, int level)
 {
+	rcu_read_lock();
 	percpu_counter_dec(&sb->s_writers.counter[level-1]);
 	/*
-	 * Make sure s_writers are updated before we wake up waiters in
-	 * freeze_super().
+	 * We are racing here with freeze_super()'s calls to
+	 * sb_wait_write().  We want to ensure that we call
+	 * wake_up() whenever one of those calls _might_ be
+	 * in sb_wait_write().
+	 *
+	 * Since freeze_super() does a synchronize_rcu() before
+	 * each of its sb_wait_write() calls, it can guarantee
+	 * that it sees our update to s_writers.counter as well
+	 * as that we see its update to s_writers.frozen.
 	 */
-	smp_mb();
-	if (waitqueue_active(&sb->s_writers.wait))
+	if (unlikely(sb->s_writers.frozen >= level))
 		wake_up(&sb->s_writers.wait);
+	rcu_read_unlock();
+
 	rwsem_release(&sb->s_writers.lock_map[level-1], 1, _RET_IP_);
 }
 EXPORT_SYMBOL(__sb_end_write);
_

  parent reply	other threads:[~2015-06-25  0:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-25  0:16 [RFCv2][PATCH 1/7] fs: optimize inotify/fsnotify code for unwatched files Dave Hansen
2015-06-25  0:16 ` [RFCv2][PATCH 2/7] fs: use RCU for free_super() vs. __sb_start_write() Dave Hansen
2015-06-26 12:59   ` Jan Kara
2015-06-25  0:16 ` Dave Hansen [this message]
2015-06-26 13:07   ` [RFCv2][PATCH 3/7] fs: fsnotify: replace memory barrier in __sb_end_write() with RCU Jan Kara
2015-06-25  0:16 ` [RFCv2][PATCH 4/7] fsnotify: encapsulate embedded fsnotify data in a single spot Dave Hansen
2015-06-26 13:19   ` Jan Kara
2015-06-25  0:16 ` [RFCv2][PATCH 5/7] fsnotify: use fsnotify_head for vfsmount data Dave Hansen
2015-06-25  0:16 ` [RFCv2][PATCH 7/7] fsnotify: track when ignored mask clearing is needed Dave Hansen
2015-06-26 13:26   ` Jan Kara
2015-06-25  0:16 ` [RFCv2][PATCH 6/7] fsnotify: change fsnotify_recalc_mask() conventions Dave Hansen
2015-06-25  0:57 ` [RFCv2][PATCH 1/7] fs: optimize inotify/fsnotify code for unwatched files Eric Paris
2015-06-25 16:28   ` Dave Hansen

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=20150625001606.E834E08B@viggo.jf.intel.com \
    --to=dave@sr71.net \
    --cc=ak@linux.intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=tim.c.chen@linux.intel.com \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®