From patchwork Thu Jun 25 00:16:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 6671231 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 49567C05AC for ; Thu, 25 Jun 2015 00:16:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 74A7E20574 for ; Thu, 25 Jun 2015 00:16:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CDA2A204E0 for ; Thu, 25 Jun 2015 00:16:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752443AbbFYAQO (ORCPT ); Wed, 24 Jun 2015 20:16:14 -0400 Received: from mga03.intel.com ([134.134.136.65]:59909 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752113AbbFYAQH (ORCPT ); Wed, 24 Jun 2015 20:16:07 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 24 Jun 2015 17:16:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,673,1427785200"; d="scan'208";a="513808088" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.19]) by FMSMGA003.fm.intel.com with ESMTP; 24 Jun 2015 17:16:06 -0700 Subject: [RFCv2][PATCH 3/7] fs: fsnotify: replace memory barrier in __sb_end_write() with RCU 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 From: Dave Hansen Date: Wed, 24 Jun 2015 17:16:06 -0700 References: <20150625001605.72553909@viggo.jf.intel.com> In-Reply-To: <20150625001605.72553909@viggo.jf.intel.com> Message-Id: <20150625001606.E834E08B@viggo.jf.intel.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dave Hansen 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 Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Paul E. McKenney Cc: Tim Chen Cc: Andi Kleen Signed-off-by: Dave Hansen Reviewed-by: Jan Kara --- 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);