From patchwork Fri Jun 19 22:32:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 6649531 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 58B6AC05AC for ; Fri, 19 Jun 2015 22:32:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B76982073B for ; Fri, 19 Jun 2015 22:32:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 03D782073A for ; Fri, 19 Jun 2015 22:32:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756228AbbFSWcc (ORCPT ); Fri, 19 Jun 2015 18:32:32 -0400 Received: from mga02.intel.com ([134.134.136.20]:52325 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751060AbbFSWc2 (ORCPT ); Fri, 19 Jun 2015 18:32:28 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 19 Jun 2015 15:32:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,646,1427785200"; d="scan'208";a="714182093" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.39.19]) by orsmga001.jf.intel.com with ESMTP; 19 Jun 2015 15:32:23 -0700 Subject: [RFC][PATCH 2/2] fs: conditionally do memory barrier in __sb_end_write() 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 From: Dave Hansen Date: Fri, 19 Jun 2015 15:32:23 -0700 References: <20150619223223.10B658AD@viggo.jf.intel.com> In-Reply-To: <20150619223223.10B658AD@viggo.jf.intel.com> Message-Id: <20150619223223.94775FFA@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=-7.2 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 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(). The stated purpose for the smp_mb() in __sb_end_write() is to ensure "s_writers are updated before we wake up waiters". We only wake up waiters if waitqueue_active(), but we do the smp_mb() unconditionally. It seems like we should be able to avoid it unless we are actually doing the wake_up(). 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 --- b/fs/super.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 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-19 15:20:37.953726659 -0700 +++ b/fs/super.c 2015-06-19 15:20:37.956726794 -0700 @@ -1147,13 +1147,14 @@ out: void __sb_end_write(struct super_block *sb, int level) { percpu_counter_dec(&sb->s_writers.counter[level-1]); - /* - * Make sure s_writers are updated before we wake up waiters in - * freeze_super(). - */ - smp_mb(); - if (waitqueue_active(&sb->s_writers.wait)) + if (waitqueue_active(&sb->s_writers.wait)) { + /* + * Make sure other CPUs can see our s_writers update + * before we wake up waiters in freeze_super(). + */ + smp_mb(); wake_up(&sb->s_writers.wait); + } rwsem_release(&sb->s_writers.lock_map[level-1], 1, _RET_IP_); } EXPORT_SYMBOL(__sb_end_write);