From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 299CEC388F7 for ; Thu, 22 Oct 2020 21:37:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C35C1241A6 for ; Thu, 22 Oct 2020 21:37:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S372399AbgJVVha (ORCPT ); Thu, 22 Oct 2020 17:37:30 -0400 Received: from mx2.suse.de ([195.135.220.15]:39088 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S372395AbgJVVha (ORCPT ); Thu, 22 Oct 2020 17:37:30 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 141DBABDE; Thu, 22 Oct 2020 21:37:28 +0000 (UTC) From: Davidlohr Bueso To: viro@zeniv.linux.org.uk Cc: akpm@linux-foundation.org, peterz@infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Davidlohr Bueso , Davidlohr Bueso Subject: [PATCH] fs/dcache: optimize start_dir_add() Date: Thu, 22 Oct 2020 14:16:50 -0700 Message-Id: <20201022211650.25045-1-dave@stgolabs.net> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Considering both end_dir_add() and d_alloc_parallel(), the dir->i_dir_seq wants acquire/release semantics, therefore micro-optimize for ll/sc archs and use finer grained barriers to provide (load)-ACQUIRE ordering (L->S + L->L). This comes at no additional cost for most of x86, as sane tso models will have a nop for smp_rmb/smp_acquire__after_ctrl_dep. Signed-off-by: Davidlohr Bueso --- Alternatively I guess we could just use cmpxchg_acquire(). fs/dcache.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index ea0485861d93..22738daccb9c 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -2502,13 +2502,18 @@ EXPORT_SYMBOL(d_rehash); static inline unsigned start_dir_add(struct inode *dir) { + unsigned n; for (;;) { - unsigned n = dir->i_dir_seq; - if (!(n & 1) && cmpxchg(&dir->i_dir_seq, n, n + 1) == n) - return n; + n = READ_ONCE(dir->i_dir_seq); + if (!(n & 1) && cmpxchg_relaxed(&dir->i_dir_seq, n, n + 1) == n) + break; cpu_relax(); } + + /* create (load)-ACQUIRE ordering */ + smp_acquire__after_ctrl_dep(); + return n; } static inline void end_dir_add(struct inode *dir, unsigned n) -- 2.26.2