Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp842962rdh; Thu, 23 Nov 2023 22:05:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGdMwIuw0fgadliFI7rwaTi2tHgzAwSvepVX5tiSso1Ak3CiXfjrT80T2XMbOyVQvyYlypD X-Received: by 2002:a17:902:cecf:b0:1cc:31c4:3426 with SMTP id d15-20020a170902cecf00b001cc31c43426mr2221051plg.11.1700805945037; Thu, 23 Nov 2023 22:05:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700805945; cv=none; d=google.com; s=arc-20160816; b=cvdAP4aPlbQB1euBP5K0K4buWtsNSSTE7MTMGBgkb50g6W0RqyZCmo83mWyziHqEd7 +MNAzSIgxnBrva8w3sawaQ/HKGPo2qvFmsoX0HuRoD2X1OAf54n2bSWOm3hjUGpfFcx2 HFkZFvdoZ9DyBpN1G5UeaPwEHN7V45g6TbVPRW334UnoMhaIBOQu8FPzzlL3TUvIS1yI xCmCluvu//BFygKG9Yg6IjE55BiiySzFviK1GxHpq0CueUXqs6w81wPjnTFRwFUUAvBy ssOkmK6rAulPvXDNgJ1WaubbM4504cOntWKYGDcNX2EUU4m6xdZkPX9qjyLw2+xvnMcg FPkQ== 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=vqFH5rERW58IIdMxyKTO+oPeZnb8OZczTTpmKipGyrA=; fh=vDsv/0Rb6aybIi/Xas2DR+uQpFXMLtn4no3J1t38V0s=; b=CWt2AAfp8Vg9gC/nGlL/G1Q49TY/6hRqWtbSZMNVtUb7F+iSDFKHzCvRkjTQY8Ol6a 1cf84PlvhOYSa2t9hu+F35WN0B4egJo5bfi9ZTv9y2OJJlrTDomAejJG1OJTTLVXfbJY 0F9Q1FVeql+GV93YFBmnJUA83iGgF35L7l4uNwRbLj9UaHS1YREufNpgzJg4MDJ+gkvT M4JREIUpgYjapGmSgfTAF/VfZ5GHPIHEhKwY6NR4Y7SzQlgv/nTcROd9remOeiY76htM yXkvGd4/okqNK8yyF99KTflSEXE8u7b8sLjoQlzYd02QM8bwU1Uqjts31zele0hc1UEv Zvvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=IZalQm1C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id m7-20020a170902db0700b001cc4fbe9281si2683587plx.582.2023.11.23.22.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 22:05:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=IZalQm1C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 5EEEE81EB9CB; Thu, 23 Nov 2023 22:05:40 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344585AbjKXGFU (ORCPT + 99 others); Fri, 24 Nov 2023 01:05:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjKXGEU (ORCPT ); Fri, 24 Nov 2023 01:04:20 -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 E143C10D0; Thu, 23 Nov 2023 22:04:26 -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=vqFH5rERW58IIdMxyKTO+oPeZnb8OZczTTpmKipGyrA=; b=IZalQm1CDM/26zqZNWLkuzZQnL XoCFW8H56OWRSgycnTzbTmahD10SLdxGszLx2xyNWABvWa2x0BFbuIcT0xuC3LKURvZmBqaH7VDp1 viy2p+jmxKAOv1za7I1rZM4eHxwbJIa6urXvjPrb+grgYsE2NGb2ojtftJhvNm8eRguMUIDzQ8xv3 nwfibLMUZxvrvT6JjL2BZmtzIcYmRjyGgdZbBXT5LPjgZ6LZBN+pTOD0Suj2GSYW/4VfZEzeF15Q2 V1T8UOCAuCh26oo7Cv8hUS0rw3HeVbREBIcFly1u+l+Gk+FTqeLAdfwrK4yy5V6lrNLN8z49Ll1Fy ohFGTtwg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1r6PIe-002PuZ-11; Fri, 24 Nov 2023 06:04:24 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Christian Brauner , linux-kernel@vger.kernel.org Subject: [PATCH v3 12/21] dentry_kill(): don't bother with retain_dentry() on slow path Date: Fri, 24 Nov 2023 06:04:13 +0000 Message-Id: <20231124060422.576198-12-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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 23 Nov 2023 22:05:40 -0800 (PST) We have already checked it and dentry used to look not worthy of keeping. The only hard obstacle to evicting dentry is non-zero refcount; everything else is advisory - e.g. memory pressure could evict any dentry found with refcount zero. On the slow path in dentry_kill() we had dropped and regained ->d_lock; we must recheck the refcount, but everything else is not worth bothering with. Note that filesystem can not count upon ->d_delete() being called for dentry - not even once. Again, memory pressure (as well as d_prune_aliases(), or attempted rmdir() of ancestor, or...) will not call ->d_delete() at all. So from the correctness point of view we are fine doing the check only once. And it makes things simpler down the road. Signed-off-by: Al Viro --- fs/dcache.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index b527db8e5901..80992e49561c 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -739,14 +739,10 @@ static struct dentry *dentry_kill(struct dentry *dentry) spin_lock(&dentry->d_lock); parent = lock_parent(dentry); got_locks: - if (unlikely(dentry->d_lockref.count != 1)) { - dentry->d_lockref.count--; - } else if (likely(!retain_dentry(dentry))) { - dentry->d_lockref.count--; + dentry->d_lockref.count--; + if (likely(dentry->d_lockref.count == 0)) { __dentry_kill(dentry); return parent; - } else { - dentry->d_lockref.count--; } /* we are keeping it, after all */ if (inode) -- 2.39.2