Received: by 10.223.164.221 with SMTP id h29csp73925wrb; Mon, 23 Oct 2017 18:19:15 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QuT2kBsmMC+/+m7a+SKly/6Ggq7Ol6vm01UXecyT6c+OeH7rZbxhZWJnxcUS/rNGdOP+j5 X-Received: by 10.84.218.79 with SMTP id f15mr11496328plm.145.1508807955068; Mon, 23 Oct 2017 18:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508807955; cv=none; d=google.com; s=arc-20160816; b=ZQaa5QbUI03htWbCahP3rr1opG0Qw/G5i+cZ2CQ7km0nk7p53QD7bVPC5etSN79Pot jxcvrBAM55NH+IJ6nGUuCLh0ajpVZJGa+CEd3IV6qDyv0wB5Yv/HxUXzeEQ+Q0U8h95J /t2RDNYjopjlRc9xld/UQj+yukUODuisM/PRopejlYu7JDvxSR/V+UxxhyNfi5GfYcut oukvYUwOi/ZeYsVrQY3DuQmVwuI3vLYip8oG2iBHCEeFVH54UPEzrZIx5liSpGXb40CH eAKW/G7z0NqYiXRbeqo4iA15PHoGWHFKJC2qAaQX4NyAaQaOXT3uRiR3/YMvOrXayI25 pApQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=D6OGvt6vxF/jyPuTz96ODln9a1o+ylUiO0PB7Y4Wemg=; b=gZdoTL66zGeHQ87I0BXF8p6Pfiwfgt/HFPkUKS2alGe0P06ZfYE5Hyry/xknLgjTYm s2kjRS2Iw0kMj3OBusWVpOgSoWoEN4uzv43n0PXPLLgVmwMgAu8CJg41n4yzQvGmN8RX R0ETwrRXb4MkAX4DSEylUJevyeq8gZanULSF4AF+Gn++zf96ZDFieOiZzGZv6qzOBEi0 q2/XJnargUZYaRNR8+tdHdIyOWUszgDD1IDdd2+FlXji1PMqUGqKoGOSjEkpzClo8H9Q yLTmJ16TbsD5deT755BPsZSj9XYH9x40VfSJAVxP+RWk9+18nPaiO739ancsVCG2mAvZ KHBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b3si6170006pff.392.2017.10.23.18.19.01; Mon, 23 Oct 2017 18:19:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751413AbdJXBSX (ORCPT + 99 others); Mon, 23 Oct 2017 21:18:23 -0400 Received: from mga14.intel.com ([192.55.52.115]:40191 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751220AbdJXBSW (ORCPT ); Mon, 23 Oct 2017 21:18:22 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Oct 2017 18:18:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,424,1503385200"; d="scan'208";a="1209221742" Received: from kemi-desktop.sh.intel.com ([10.239.13.103]) by fmsmga001.fm.intel.com with ESMTP; 23 Oct 2017 18:18:19 -0700 From: Kemi Wang To: Jan Kara , Jens Axboe , Darrick J Wong , Kemi Wang , Eric Biggers , Andreas Gruenbacher , Jeff Layton Cc: Dave , Andi Kleen , Tim Chen , Ying Huang , Aaron Lu , Linux Kernel Subject: [PATCH v2] buffer: Avoid setting buffer bits that are already set Date: Tue, 24 Oct 2017 09:16:42 +0800 Message-Id: <1508807802-9691-1-git-send-email-kemi.wang@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's expensive to set buffer flags that are already set, because that causes a costly cache line transition. A common case is setting the "verified" flag during ext4 writes. This patch checks for the flag being set first. With the AIM7/creat-clo benchmark testing on a 48G ramdisk based-on ext4 file system, we see 3.3%(15431->15936) improvement of aim7.jobs-per-min on a 2-sockets broadwell platform. What the benchmark does is: it forks 3000 processes, and each process do the following: a) open a new file b) close the file c) delete the file until loop=100*1000 times. The original patch is contributed by Andi Kleen. Signed-off-by: Andi Kleen Signed-off-by: Kemi Wang Tested-by: Kemi Wang Reviewed-by: Jens Axboe --- include/linux/buffer_head.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index c8dae55..211d8f5 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -80,11 +80,14 @@ struct buffer_head { /* * macro tricks to expand the set_buffer_foo(), clear_buffer_foo() * and buffer_foo() functions. + * To avoid reset buffer flags that are already set, because that causes + * a costly cache line transition, check the flag first. */ #define BUFFER_FNS(bit, name) \ static __always_inline void set_buffer_##name(struct buffer_head *bh) \ { \ - set_bit(BH_##bit, &(bh)->b_state); \ + if (!test_bit(BH_##bit, &(bh)->b_state)) \ + set_bit(BH_##bit, &(bh)->b_state); \ } \ static __always_inline void clear_buffer_##name(struct buffer_head *bh) \ { \ -- 2.7.4 From 1582098267475132161@xxx Tue Oct 24 00:54:43 +0000 2017 X-GM-THRID: 1582062716863867471 X-Gmail-Labels: Inbox,Category Forums