Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp321905pxa; Thu, 27 Aug 2020 03:23:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfYBY32vUDVY+0xBrU5kBkwJGIi4cmfOzcplrANakf2p+hWqE2djnVsRYUb8FR4dx/BGJx X-Received: by 2002:a17:906:4c97:: with SMTP id q23mr21003047eju.11.1598523819898; Thu, 27 Aug 2020 03:23:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598523819; cv=none; d=google.com; s=arc-20160816; b=QWQEuco4So1XuFouPrQHIlReMkboRLxps+dK65UvLzUXtIJJ3qpw7pjkyCzw0lqasu e4WI9jOvQ+729P0/jgJe6bgZeRMDj9/lm+8T4DA0v8g46cNxtvPO6KNiKbxrLFMa6x2v PEvbUrmuqnzNTSb1CLY9yV0PguMk3Q192eNIFU2/QaRi8hu4ccIkJCTVK3hfICIk5TV/ 5Z4uogSeXQce+cflWfx2GLNIxGvfFILYUzw+SrSm0sH/3n7ZMf1YBS/LY5HY+Dr5SdUN eqNaQPUx9Lja2r/LDDk57JqoB/BvWfZuPlEiFGv1CnXdw0RI4nCxSviSpmrZQnHL8pi4 ze/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=XhHdoMYPvjOignG+TN53BWUmEUPimfk2HNQ2bSQcWWQ=; b=YIuPX7HsvhniLubVRh3Oo79qBYxs4QTtT/IvIBbJMRIIIIMRuaAxpZbnk6SF+UUnHg /e3hIdOyCfeZrDR4oiM8PJL48nNhyrPNTmVrFFRn+kMj5S30agnOl+1LCSJEaysuadsW Kfy8yq4q0HqE5uuN8hOjMx+/YlWKw/tmWW8C2ZuVQZjbMCqCNWTSen9GAecQmp8VdtSK VpuvLkpWNtfRugUQMndJO8UUDwNs3laU6x1AQz+Ra18vBS13kcc2KpN+UTPZfivNpppa 8gcAGQLMXOzLH4uI/eCiQd6l6sM+xLNhiJuyPi0hdbIjCjBhBCW7lFs3e97EOgs7dEjY dx5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rk14si1075935ejb.58.2020.08.27.03.23.17; Thu, 27 Aug 2020 03:23:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726266AbgH0KW3 (ORCPT + 99 others); Thu, 27 Aug 2020 06:22:29 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:40438 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728466AbgH0KWX (ORCPT ); Thu, 27 Aug 2020 06:22:23 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 9002C4E592AF5C867A64; Thu, 27 Aug 2020 18:22:19 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.487.0; Thu, 27 Aug 2020 18:22:13 +0800 From: Shaokun Zhang To: , CC: Yuqi Jin , kernel test robot , Will Deacon , Mark Rutland , "Peter Zijlstra" , Alexander Viro , Boqun Feng , Shaokun Zhang Subject: [PATCH] fs: Optimized fget to improve performance Date: Thu, 27 Aug 2020 18:19:44 +0800 Message-ID: <1598523584-25601-1-git-send-email-zhangshaokun@hisilicon.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yuqi Jin It is well known that the performance of atomic_add is better than that of atomic_cmpxchg. The initial value of @f_count is 1. While @f_count is increased by 1 in __fget_files, it will go through three phases: > 0, < 0, and = 0. When the fixed value 0 is used as the condition for terminating the increase of 1, only atomic_cmpxchg can be used. When we use < 0 as the condition for stopping plus 1, we can use atomic_add to obtain better performance. we test syscall in unixbench on Huawei Kunpeng920(arm64). We've got a 132% performance boost. with this patch and the patch [1] System Call Overhead 9516926.2 lps (10.0 s, 1 samples) System Benchmarks Partial Index BASELINE RESULT INDEX System Call Overhead 15000.0 9516926.2 6344.6 ======== System Benchmarks Index Score (Partial Only) 6344.6 with this patch and without the patch [1] System Call Overhead 5290449.3 lps (10.0 s, 1 samples) System Benchmarks Partial Index BASELINE RESULT INDEX System Call Overhead 15000.0 5290449.3 3527.0 ======== System Benchmarks Index Score (Partial Only) 3527.0 without any patch System Call Overhead 4102310.5 lps (10.0 s, 1 samples) System Benchmarks Partial Index BASELINE RESULT INDEX System Call Overhead 15000.0 4102310.5 2734.9 ======== System Benchmarks Index Score (Partial Only) 2734.9 [1] https://lkml.org/lkml/2020/6/24/283 Cc: kernel test robot Cc: Will Deacon Cc: Mark Rutland Cc: Peter Zijlstra Cc: Alexander Viro Cc: Boqun Feng Signed-off-by: Yuqi Jin Signed-off-by: Shaokun Zhang --- Hi Rong, Can you help to test this patch individually and with [1] together on your platform please? [1] has been tested on your platform[2]. [2] https://lkml.org/lkml/2020/7/8/227 include/linux/fs.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index e019ea2f1347..2a9c2a30dc58 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -972,8 +972,19 @@ static inline struct file *get_file(struct file *f) atomic_long_inc(&f->f_count); return f; } + +static inline bool get_file_unless_negative(atomic_long_t *v, long a) +{ + long c = atomic_long_read(v); + + if (c <= 0) + return 0; + + return atomic_long_add_return(a, v) - 1; +} + #define get_file_rcu_many(x, cnt) \ - atomic_long_add_unless(&(x)->f_count, (cnt), 0) + get_file_unless_negative(&(x)->f_count, (cnt)) #define get_file_rcu(x) get_file_rcu_many((x), 1) #define file_count(x) atomic_long_read(&(x)->f_count) -- 2.7.4