Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp844219rdh; Thu, 23 Nov 2023 22:07:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHgb1FBX6x4DeVrWu9qlAhGMVaI3qwSl7epfYLPeFQqa7CBIfD6tMbvt7RvzHhPQoKGdJAf X-Received: by 2002:a05:6870:a688:b0:1f5:cf59:1ed1 with SMTP id i8-20020a056870a68800b001f5cf591ed1mr1974408oam.4.1700806078141; Thu, 23 Nov 2023 22:07:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700806078; cv=none; d=google.com; s=arc-20160816; b=UbF4pgJ3e/63hsMTfHQsynOSOC/f0dvCFY8GFA1C8SW7wbvK0VMuaLDXoqXIYKXpod nLjna/If3AF8J9rA6wl2fbvPDhMfFXW6Jvleb87uZ5H8YURc9Wj9xfOkN4YATF4upNkU U9leasF1h+3MCnauttAVq4Th6IMLvxvTumcEGUIZY5OuCz+O5UtmvTOgwGHmqMzMteYX frtBMk67NNt6GlYxb6Stdm9Y0NVbJroPxLyfEMwTUjYtwkJyD8Lhj0jWuvPTcfZxCnG6 YgdWL1kJIKTc2UqDVi4TvVUKPB0HjTln7p05pwpA+B40h/hqhC8WNV4eCjx1prMFxpKB Px6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mKxWUgBkshDSs4B2WASlKAmLfggYuaL+kX3Oj3+r6FU=; fh=vDsv/0Rb6aybIi/Xas2DR+uQpFXMLtn4no3J1t38V0s=; b=tFd4JJD2XDNGraN6Pdrg1y71gjSJBbbIxQg8pIHMoR+cc3Qj8GfolCVtgB7r+KRNSO eFFo+swyFTLgwv6/lHUZDrs7JbXwBsEPOkPwFb5As7uVyYnAuiRo9an1Kpl2Lrv+GJfz m2IaC2ip0cRU39U60oaBsSbw7KO0pdFwgcVb9Ns4EUZQ7+Ih4mB3s4wKrj0+ftcuhPXC +iLCh+Sd43IqqESqduf7pms3xpU9oj2r9pk7EfUmkyJ6AlIg0ym1JcJMOaqmnycgiLQ9 I0Ww0Uw3DQLIkkfedeYDUM4NODmZtcVkrZeBSZUonhD5i6/T1rW0k7pfCmlimup9UsP6 V08w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=KZ6ZsvVD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id t5-20020a625f05000000b006cb83b233a2si2642975pfb.355.2023.11.23.22.07.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 22:07:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=KZ6ZsvVD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 60F228072A14; Thu, 23 Nov 2023 22:06:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232893AbjKXGFu (ORCPT + 99 others); Fri, 24 Nov 2023 01:05:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231496AbjKXGEV (ORCPT ); Fri, 24 Nov 2023 01:04:21 -0500 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFE3410DD; Thu, 23 Nov 2023 22:04:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=mKxWUgBkshDSs4B2WASlKAmLfggYuaL+kX3Oj3+r6FU=; b=KZ6ZsvVDsZiRhl7reMm8ZU+L/m ScsjbK3WrOdoVz/sBBeJn/QdnvAQi/uanyqsEH0Lv5oWj6k5JPC5wCk++l2SMeUNo3TmfOEosnjje EI3LsEb9OE83W97PXoGQD9BwKcFsHDSePwLoZQNykjv20m0xBBUAtaZdmDUZq8cTZ74D4x6LcVGz6 HTnjNt+71FnlM2PapgKS5hwrWs1f+238sLxqjZ4se9M50FB5EYfg36z2x1JaT15NBaThPSlbh4nYg MKSErjtGs9+zHS8r4FpJYweRKRkT66tCmadTm7nUpmanwLXHWVkeR4RnbfJ69Xw3OzsAyhK8THQqO UZc+/cLA==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1r6PIg-002PvH-22; Fri, 24 Nov 2023 06:04:26 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Christian Brauner , linux-kernel@vger.kernel.org Subject: [PATCH v3 19/21] d_prune_aliases(): use a shrink list Date: Fri, 24 Nov 2023 06:04:20 +0000 Message-Id: <20231124060422.576198-19-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231124060422.576198-1-viro@zeniv.linux.org.uk> References: <20231124060200.GR38156@ZenIV> <20231124060422.576198-1-viro@zeniv.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Al Viro X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 23 Nov 2023 22:06:35 -0800 (PST) Instead of dropping aliases one by one, restarting, etc., just collect them into a shrink list and kill them off in one pass. We don't really need the restarts - one alias can't pin another (directory has only one alias, and couldn't be its own ancestor anyway), so collecting everything that is not busy and taking it out would take care of everything evictable that had been there as we entered the function. And new aliases added while we'd been dropping old ones could just as easily have appeared right as we return to caller... Reviewed-by: Christian Brauner Signed-off-by: Al Viro --- fs/dcache.c | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index f68fe7c863e0..a3cc612a80d5 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -647,20 +647,6 @@ static struct dentry *__lock_parent(struct dentry *dentry) return parent; } -static inline struct dentry *lock_parent(struct dentry *dentry) -{ - struct dentry *parent = dentry->d_parent; - if (IS_ROOT(dentry)) - return NULL; - if (likely(spin_trylock(&parent->d_lock))) - return parent; - rcu_read_lock(); - spin_unlock(&dentry->d_lock); - parent = __lock_parent(dentry); - rcu_read_unlock(); - return parent; -} - /* * Lock a dentry for feeding it to __dentry_kill(). * Called under rcu_read_lock() and dentry->d_lock; the former @@ -1090,24 +1076,18 @@ struct dentry *d_find_alias_rcu(struct inode *inode) */ void d_prune_aliases(struct inode *inode) { + LIST_HEAD(dispose); struct dentry *dentry; -restart: + spin_lock(&inode->i_lock); hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) { spin_lock(&dentry->d_lock); - if (!dentry->d_lockref.count) { - struct dentry *parent = lock_parent(dentry); - if (likely(!dentry->d_lockref.count)) { - __dentry_kill(dentry); - dput(parent); - goto restart; - } - if (parent) - spin_unlock(&parent->d_lock); - } + if (!dentry->d_lockref.count) + to_shrink_list(dentry, &dispose); spin_unlock(&dentry->d_lock); } spin_unlock(&inode->i_lock); + shrink_dentry_list(&dispose); } EXPORT_SYMBOL(d_prune_aliases); -- 2.39.2