Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp265189pxu; Thu, 22 Oct 2020 23:14:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVyd6iJ1yzLbfX//nAl77vo9hCZbQJ0+RVuEnC1Bp8+omLrsfEAC6jcQw2HKkGMyd3CJgM X-Received: by 2002:a17:906:3cb:: with SMTP id c11mr501127eja.117.1603433684820; Thu, 22 Oct 2020 23:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603433684; cv=none; d=google.com; s=arc-20160816; b=sD+YYuGkwy8YapMj3EOMdInXdThJKDOYzMRPtwojdmbNHsGPPr47/Ze3QvsNBqr1BE C/tcDxQT1rjqak8higs+gVmILmT3cSeCc2XxZV6HyOpNpUe5tgrEN53USZ3c8km6vzwY a0568SGa+IqxkoNyQrVN9Zs1oboDBE8v6LGvh/+BTIK1HnrlKVZyk/KHEg6+TGIVYezE tRxiWAtbjkaVhfPV7x6RoHd8090ygirjALN7/qr5xiycWJYA3uRLz9BOMor66Od9IuvY Wi2etwY7KaEWZ8NrzD0w4bqHhA71j0a6nj6p+PsgmNgTYBKa++cMpDivnPl5RR1oDqhT 9kKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=mDUVXneVzDWsRIhYesoURvRJakP8SKHZ3ntFuL3l5lU=; b=K4hPR9E5AfpK06kRGqipLPlozCOS58Juo5gvqNXgZdsaJbE18JkTNZoINIoReVgaz/ ooh7qPr/z834B1p7YR7BfEFeoTrlFBpz+RDKS/9x0CpkYJAHaLt6A87p1YaXMgyOG7Ga MYwCs/+0TwM9B/RHSyJpgHDDom63EPB7hP/Ut7l+4KImpt+7yDRLFwriSOSlmzzfx65Y hVlxgnlkmPJeJ1xqajWqULGco4CsZMmtqNT8Pwx4IYWsC7aFrmBZdH8AD7BUmIvmc9yy wBmx8yfK/GKLkA1JS01930wsHVMQbojqrm2hzyvKu0g1lsHMNYO6utnzGqpMjqX/ZgiB Xt+Q== 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 kt25si222465ejb.438.2020.10.22.23.14.18; Thu, 22 Oct 2020 23:14:44 -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 S372401AbgJVVha (ORCPT + 99 others); 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-kernel@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