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=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 BA8D3C47082 for ; Thu, 3 Jun 2021 16:59:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A51D561159 for ; Thu, 3 Jun 2021 16:59:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230201AbhFCRBj (ORCPT ); Thu, 3 Jun 2021 13:01:39 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:38048 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229719AbhFCRBi (ORCPT ); Thu, 3 Jun 2021 13:01:38 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1loqhD-000jT9-SG; Thu, 03 Jun 2021 10:59:51 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=email.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1loqhB-0014ta-S2; Thu, 03 Jun 2021 10:59:51 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Ian Kent Cc: Greg Kroah-Hartman , Tejun Heo , Eric Sandeen , Fox Chen , Brice Goglin , Al Viro , Rick Lindsley , David Howells , Miklos Szeredi , Marcelo Tosatti , linux-fsdevel , Kernel Mailing List In-Reply-To: <162218365578.34379.12523496660412609287.stgit@web.messagingengine.com> (Ian Kent's message of "Fri, 28 May 2021 14:34:15 +0800") References: <162218354775.34379.5629941272050849549.stgit@web.messagingengine.com> <162218365578.34379.12523496660412609287.stgit@web.messagingengine.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Date: Thu, 03 Jun 2021 11:59:26 -0500 Message-ID: <87sg1yq3yp.fsf@disp2133> MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1loqhB-0014ta-S2;;;mid=<87sg1yq3yp.fsf@disp2133>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18HxLa+PRc0hpmh8oMEaTcHefBrxSzyR14= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [REPOST PATCH v4 3/5] kernfs: switch kernfs to use an rwsem X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ian Kent writes: > The kernfs global lock restricts the ability to perform kernfs node > lookup operations in parallel during path walks. > > Change the kernfs mutex to an rwsem so that, when opportunity arises, > node searches can be done in parallel with path walk lookups. > > Signed-off-by: Ian Kent > --- > fs/kernfs/dir.c | 117 ++++++++++++++++++++++++------------------- > fs/kernfs/file.c | 4 + > fs/kernfs/inode.c | 16 +++--- > fs/kernfs/kernfs-internal.h | 5 +- > fs/kernfs/mount.c | 12 ++-- > fs/kernfs/symlink.c | 4 + > include/linux/kernfs.h | 2 - > 7 files changed, 86 insertions(+), 74 deletions(-) > > diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c > index 5151c712f06f5..1e2e35a201dfb 100644 > --- a/fs/kernfs/dir.c > +++ b/fs/kernfs/dir.c > @@ -17,7 +17,7 @@ > > #include "kernfs-internal.h" > > -DEFINE_MUTEX(kernfs_mutex); > +DECLARE_RWSEM(kernfs_rwsem); > static DEFINE_SPINLOCK(kernfs_rename_lock); /* kn->parent and ->name */ > static char kernfs_pr_cont_buf[PATH_MAX]; /* protected by rename_lock */ > static DEFINE_SPINLOCK(kernfs_idr_lock); /* root->ino_idr */ > @@ -26,10 +26,21 @@ static DEFINE_SPINLOCK(kernfs_idr_lock); /* root->ino_idr */ > > static bool kernfs_active(struct kernfs_node *kn) > { > - lockdep_assert_held(&kernfs_mutex); > return atomic_read(&kn->active) >= 0; > } > > +static bool kernfs_active_write(struct kernfs_node *kn) > +{ > + lockdep_assert_held_write(&kernfs_rwsem); > + return kernfs_active(kn); > +} > + > +static bool kernfs_active_read(struct kernfs_node *kn) > +{ > + lockdep_assert_held_read(&kernfs_rwsem); > + return kernfs_active(kn); > +} This bit is unnecessary and confusing. There is nothing read/write about how the kernfs file is active (aka being used be a function). Further all that is needed for correct operation is: > static bool kernfs_active(struct kernfs_node *kn) > { > - lockdep_assert_held(&kernfs_mutex); > + lockdep_assert_held(&kernfs_rwsem); > return atomic_read(&kn->active) >= 0; > } Eric