From patchwork Tue Dec 14 00:53:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12675141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F043C433F5 for ; Tue, 14 Dec 2021 00:53:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244528AbhLNAxu (ORCPT ); Mon, 13 Dec 2021 19:53:50 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:57028 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244517AbhLNAxs (ORCPT ); Mon, 13 Dec 2021 19:53:48 -0500 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1BDLAFXS017988; Tue, 14 Dec 2021 00:53:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=tWlwNnaPepD7uR03pYKq8nSXn+RnqrVUtViv7aTlCtg=; b=VwyaEaZHsc6Vtp2oU6/A3JZ7kMEsxXFLOgABJUQsxYigEkt3RN7TdK6qhip2dBFhvYFj aX/8uBh9MZByk3UOWk9AUmmhDEmVjYoJgCS0gjksQhBCLPX1sD9XwGl+aDhiWQ0iz2gn 0/aydX26zY6BrpVFNA3MXYuDER2T969jh0gI1IoODmTTnrhduDA+9olXu8Sq7aC61/5k phbeWsXRyyB8i8/h73ETlIkjHIqhyv4G0TjFOa4wueMuslxV7gUXt/+1/xGTMnJfN1qR J7/kt4fIoaQhcGjShpto8YIrrKJwBvipopKSJZbc7l7mr6lwN8znhsEVASVtRMRsinFC zw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3cx5aka3bt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Dec 2021 00:53:47 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1BE0f2FS133040; Tue, 14 Dec 2021 00:53:46 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2175.outbound.protection.outlook.com [104.47.58.175]) by userp3020.oracle.com with ESMTP id 3cvnep17at-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Dec 2021 00:53:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OU/ppbfFp0aWHn5HuZ3eeX8wLGVSxB2ZslESwWasOa/MbA1LvcWBgmtuTk+P1G/HmM+AgOI/aYwfLmWaQBiPqiO39p/GD976uk+xG0f4cq9WxtxU2q9NUnT4WcMeA2gg1PdTXXuOUcBRmxl/0eN6P5qtcs8jR2ng4G0ZUU1fEuWduMJ7eaIW7NtZM+9l8mFA4+dWCAqkTHIvnEV1PlpWKky9fqWqwIcMR3FtttjUCfgfL/vBOLSdPrjqIlzIXfMciwMch5m8GJlIKmV+2t17TbrW2vdfhxZ8Rz3FouU53N2TJuP8M31txtP0XmeYUksp23SADgQvUfYkM0HUSOSfgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tWlwNnaPepD7uR03pYKq8nSXn+RnqrVUtViv7aTlCtg=; b=T2783BmKUgervi6iGhl8DXx3Fe2lgLyCHgga/eiQCp/mQ/bwjnk8/s+4NAup6YQlZclMnQGb5lxN0rt4ToG/2tke20nrXdOVVCZ7kKzlLp8CRnI/Lk/L11sKEVmwceZ52fUNYH83wNRtVPYtwzUMTdlC2fseVUBnj4pX4nZxWRzZZlJ2G6zqOqwF7+1W19Z7vVoR6HAD2yyukxes+cavoDnG+nAoyG2S9/lfDLqBcqAkiKHL9lJLTI7cOVpSECvyw9aVjI4olahY7RynVKnXvxFhpFHhGdmXTHiIXJxZkD3WUl4YF3pi3VXtsdhvBt1y/JKdm4c1FeXT9dnHUJNeWA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tWlwNnaPepD7uR03pYKq8nSXn+RnqrVUtViv7aTlCtg=; b=vIb4eo4iubJEEvmd+GzbQKYp1vREXzUNLJF4vasse/bsSV9CMj3ONzhSC/YpwqVx3gvWELDLTevSxvq9YDnHjgWQ8fA8WRrs4Jx7aoaZmtK3NaBKtoB83pmgmHj+yCc4qiNZLKfduvzsE9bhcznW69XH4wL2pkTsuoOUfhhlvUc= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH2PR10MB3893.namprd10.prod.outlook.com (2603:10b6:610:f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.16; Tue, 14 Dec 2021 00:53:43 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::8c57:aca7:e90d:1026]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::8c57:aca7:e90d:1026%9]) with mapi id 15.20.4778.018; Tue, 14 Dec 2021 00:53:43 +0000 From: Stephen Brennan To: Alexander Viro Cc: Stephen Brennan , Gautham Ananthakrishna , Konstantin Khlebnikov , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] dcache: sweep cached negative dentries to the end of list of siblings Date: Mon, 13 Dec 2021 16:53:34 -0800 Message-Id: <20211214005337.161885-2-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211214005337.161885-1-stephen.s.brennan@oracle.com> References: <20211214005337.161885-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SA9P223CA0005.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::10) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 91b6a089-9444-4594-d75f-08d9be9c2d2d X-MS-TrafficTypeDiagnostic: CH2PR10MB3893:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1UX1WF1CZ8sGmmRqluxhMu5yKTPr40rn6ly7/CjxXgXmhbF1IFSrtu7hBjecF4w/vMWpwSJ/tKC8fVrA5GL9qdfB0gxiZyrhD8eWWEaMNamMkzhDUQWBta00Hjc4DIXdJY+9Bcdyj2+45yXlw8pqw5E6zK9HSUZ+1zdnACq0+aKW4HDyjnUsPOy/b2MNXmNcgUo87J771o6f4J7C88DX5T2fE01/KP5/o42DSrROkjipYLi6MSpfEIQExpUZNKChzx7wJ1ntNCjzWc1Rlzl46P6dgx60TAZKUr4psJF6gcszwzG3OoYnh+D9pQxTVAViMwdonGIa19RVTNhY9QBm/0Tce5G1CntKuho1OcQ8cpyPyBQzlkPMOyE+jRraVBFao4cUUB8bxpPEMVe5HZEF7OV3Hw6bTw3PCJaVC7hfyjTHl7LuHP1+6lvgqW8b7Xm3aI32BG6j0U4gKPM8yrSpp1VcSJu3tez7ZhyLszUlfy1r7A+yS20jhoWtMq2Vm0s9VtgRREvvklDJgxifHj+c8xg4RUS8VSs2AQrFk0IGGK0kYXVW5Gb4q41RZgssbXQBAsaI6F5CU99JveffsmbA0gTkRDD4N71/wn0RS7/s3CjdWPu6b/kb1+FU29UCdO5yxWdFIz6Cpa16FBgwOfcHSHaHEzb7j32suzxpoe571v6XSqE4yZPjCeTn7hGCKxCjhZKZ8x8LScs2ntCVV1qXQw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(86362001)(36756003)(66556008)(66476007)(26005)(6506007)(6486002)(83380400001)(103116003)(38100700002)(38350700002)(6512007)(66946007)(316002)(4326008)(1076003)(54906003)(8936002)(2906002)(186003)(6666004)(8676002)(52116002)(5660300002)(508600001)(2616005)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nyccbAX/9a7rX12rrd1NV0Tai1CEBlMIhp9CtClI19y/bWmuMxta+tk12i54GbrYLJxwMiX1qIglpxRDfDHJu4kz1kpGA5QgsK6ZU8FF+phQYIdHV55kw6Z7TPcS2u1V1/ON2aV0rkxpYW6WtD214g8BYvAiJ6DISvNCNm+xgy7Wf1FhMvcWPaGOy4+vetlO8HyvxoSnQS+rWtxI1Vp3nx6F4FJLzrDoR6llDZCmZu/dUUvZ9m+Ai1AmfivU+CPk4xBXU2MTUstL0YCKuIz+e/m+h55YLnoBHEImP3iqWeuxQP4JZzqQ/r1Aztvd63M75kEvu3W0rUIwWsiD0uWPNOkvNDWsJcCUVsnt+QwNdVMdA/IiVGMpM02dySVuumZ/adbtv8QCADpCTC2c2Sjqr6r4rIUNCu9tUfnbPrAJeJWrrKuOGQ1NccZ0y8nLFf9hhtiYBbY+7qBk5tYd2fNXJreRW/uvQ3RaEykdtY2aIlL5vfhhPzXuESKcFDaiN+zw9tDaPgAjIZY/+00mq7zm8RuGED2P9eKrRYeJE+VcvgrUsAIIQ45JeDE93MMhHztksWGktnPCkGbW8uz2YEPFOkRHhs4rrw+xsnhEL+1RLZW73mSxdOASGUb3cCxcGpe7cmVc7b//kv3m66RYCxv/+yg3aAqxVZT9EJ5bALnHDmaex28Ll4k5XmWoiL+4TeVEXLT4O5xmTc8IMt5eNuMJWG14wcWwzLHnzQwc/myuQKJO9Xk+5eld683JKwXU48JEibPFxCfvJWErZVATjV0IAGCLyvXT9SUC78frCuoZt2QpLWfveRWdU1/YDe+mywdcqQygcRTd3KJ48fDIyhQIgKb7PRGUGvB2HKUZM+wI6Aj2qV1MfuQH5DBi5wKqL4WD3560ejYdH4zsl1mYr82l5LxvZx28XckFpEQpk9xU5fVDuQG3axlNp0u/8jC+UpsyE0g6z5gjxa4T2LeYB8kGbAjM5igsF3qEzoIHVt1oW/t7t34N/8rTZI8a4SWix8ORu0l9D3aF4/Iq2IiufHJ2GoutPf9Fa3vRmSYo+YSQiS2iPV12fSfnL2tgmutapYUiZL7Zyr3TFf5xtaWaQyVg52dunRoA+/1JbakhASOs+/tlglkzF02dScsY3a9RwUjKA1oMyEP4WjNKauKUenPPP3Bmug2E2r7L8LuClZyhOB8i0ZROhXGRDqc9ngJNwHhJ7jYpFbn+EjCeLWXezfxt+eSIkj04hu22E1MkASPvvaMmTOEPsseQVAoVdG1hI1wRHXIJm3lqumc5CpJyetVCrQ7MFkvT7KkKr4hDB/PFGcKfoNkE5XcGmf3bEarAeWldzgvLCudCS5hsTNhAdS7X5ZzCS7KPe6N6AdsSBq3nLP8L9SS684bK5jiTlCuTk+JaVTJiU3ivIEgsLyaziPa1Dx1vFr0o4tQbli0trVukXjCk1ELoDCZ+Iug05mm07FTJUY40qee07jUYB1OscU56kCtLomzmdrmnqJacw50VhgrzKDLg0kHlbi7kOnELRdqIX6bcQxIE/7AXE/t4lhI0d1d4MGqc+O2MoBKUQjGHYllKkNdL7vR8QkdDwkDoBSk9j/yFhZKn5V699sFUbiuO/fmE+vRBcvkyMXWMCBNROdfUpzprly0byNfdv4U2A2wWvIirfrUZU5kvC8S0a1PIuw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 91b6a089-9444-4594-d75f-08d9be9c2d2d X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2021 00:53:43.3196 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: soFor40QsX0F53RfjdAlYQPI0d0H8i2Fc6L7rbUQSPEYn+s6ANVATudc2il7s4Ca2x4VdbgHNYZW/uWpiZmfYcs4WtOjrZdMOJcogKTbwWc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB3893 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10197 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 adultscore=0 malwarescore=0 bulkscore=0 spamscore=0 mlxlogscore=979 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2112140001 X-Proofpoint-GUID: WH6hsbOQrgjBpuEKhYI8kZvu_goT7stO X-Proofpoint-ORIG-GUID: WH6hsbOQrgjBpuEKhYI8kZvu_goT7stO Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org For disk filesystems result of every negative lookup is cached, content of directories is usually cached too. Production of negative dentries isn't limited with disk speed. It's really easy to generate millions of them if system has enough memory. Negative dentries are linked into siblings list along with normal positive dentries. Some operations walks dcache tree but looks only for positive dentries: most important is fsnotify/inotify. This patch sweeps negative dentries to the end of list at final dput() and marks with flag which tells that all following dentries are negative too. We do this carefully to avoid corruption in case the dentry is killed when we try to lock its parent. Reverse operation (recycle) is required before instantiating tail negative dentry, or calling d_add() with non-NULL inode. Co-authored-by: Konstantin Khlebnikov Co-authored-by: Gautham Ananthakrishna Signed-off-by: Stephen Brennan Reported-by: kernel test robot --- Previously Al was concerned about sweep_negative() calling lock_parent() when it held no reference, so there was no guarantee that dentry would stay allocated. I've addressed this by adding an RCU critical section into sweep_negative(), ensuring that all writes to dentry occurs within the outer critical section. Thus, the dentry could not be freed yet. By checking d_count once the lock is regained, we can be sure that the dentry has not yet been killed. This is not necessary for recycle_negative(), since it is called by d_add and d_instantiate(), both of whose callers should hold a reference. The other major concern for this patch was that not all ways for a negative dentry to be converted to positive were caught by recycle_negative(). I've moved the call into __d_instantiate(), and added a call for __d_add(). fs/dcache.c | 85 +++++++++++++++++++++++++++++++++++++++--- include/linux/dcache.h | 6 +++ 2 files changed, 86 insertions(+), 5 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index cf871a81f4fd..685b91866e59 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -635,6 +635,58 @@ static inline struct dentry *lock_parent(struct dentry *dentry) return __lock_parent(dentry); } +/* + * Move cached negative dentry to the tail of parent->d_subdirs. + * This lets walkers skip them all together at first sight. + * Must be called at dput of negative dentry with d_lock held. + * Releases d_lock. + */ +static void sweep_negative(struct dentry *dentry) +{ + struct dentry *parent; + + rcu_read_lock(); + parent = lock_parent(dentry); + if (!parent) { + rcu_read_unlock(); + return; + } + + /* + * If we did not hold a reference to dentry (as in the case of dput), + * and dentry->d_lock was dropped in lock_parent(), then we could now be + * holding onto a dead dentry. Be careful to check d_count and unlock + * before dropping RCU lock, otherwise we could corrupt freed memory. + */ + if (!d_count(dentry) && d_is_negative(dentry) && + !d_is_tail_negative(dentry)) { + dentry->d_flags |= DCACHE_TAIL_NEGATIVE; + list_move_tail(&dentry->d_child, &parent->d_subdirs); + } + + spin_unlock(&parent->d_lock); + spin_unlock(&dentry->d_lock); + rcu_read_unlock(); +} + +/* + * Undo sweep_negative() and move to the head of parent->d_subdirs. + * Must be called before converting negative dentry into positive. + * Must hold dentry->d_lock, we may drop and re-grab it via lock_parent(). + * Must be hold a reference or be otherwise sure the dentry cannot be killed. + */ +static void recycle_negative(struct dentry *dentry) +{ + struct dentry *parent; + + parent = lock_parent(dentry); + dentry->d_flags &= ~DCACHE_TAIL_NEGATIVE; + if (parent) { + list_move(&dentry->d_child, &parent->d_subdirs); + spin_unlock(&parent->d_lock); + } +} + static inline bool retain_dentry(struct dentry *dentry) { WARN_ON(d_in_lookup(dentry)); @@ -740,7 +792,7 @@ static struct dentry *dentry_kill(struct dentry *dentry) static inline bool fast_dput(struct dentry *dentry) { int ret; - unsigned int d_flags; + unsigned int d_flags, required; /* * If we have a d_op->d_delete() operation, we sould not @@ -788,6 +840,8 @@ static inline bool fast_dput(struct dentry *dentry) * a 'delete' op, and it's referenced and already on * the LRU list. * + * Cached negative dentry must be swept to the tail. + * * NOTE! Since we aren't locked, these values are * not "stable". However, it is sufficient that at * some point after we dropped the reference the @@ -805,11 +859,16 @@ static inline bool fast_dput(struct dentry *dentry) */ smp_rmb(); d_flags = READ_ONCE(dentry->d_flags); + + required = DCACHE_REFERENCED | DCACHE_LRU_LIST | + (d_flags_negative(d_flags) ? DCACHE_TAIL_NEGATIVE : 0); + d_flags &= DCACHE_REFERENCED | DCACHE_LRU_LIST | - DCACHE_DISCONNECTED | DCACHE_DONTCACHE; + DCACHE_DISCONNECTED | DCACHE_DONTCACHE | + DCACHE_TAIL_NEGATIVE; /* Nothing to do? Dropping the reference was all we needed? */ - if (d_flags == (DCACHE_REFERENCED | DCACHE_LRU_LIST) && !d_unhashed(dentry)) + if (d_flags == required && !d_unhashed(dentry)) return true; /* @@ -881,7 +940,10 @@ void dput(struct dentry *dentry) rcu_read_unlock(); if (likely(retain_dentry(dentry))) { - spin_unlock(&dentry->d_lock); + if (d_is_negative(dentry) && !d_is_tail_negative(dentry)) + sweep_negative(dentry); /* drops d_lock */ + else + spin_unlock(&dentry->d_lock); return; } @@ -1973,6 +2035,8 @@ static void __d_instantiate(struct dentry *dentry, struct inode *inode) WARN_ON(d_in_lookup(dentry)); spin_lock(&dentry->d_lock); + if (d_is_tail_negative(dentry)) + recycle_negative(dentry); /* * Decrement negative dentry count if it was in the LRU list. */ @@ -2697,6 +2761,13 @@ static inline void __d_add(struct dentry *dentry, struct inode *inode) struct inode *dir = NULL; unsigned n; spin_lock(&dentry->d_lock); + /* + * Tail negative dentries must become positive before associating an + * inode. recycle_negative() is safe to use because we hold a reference + * to dentry. + */ + if (inode && d_is_tail_negative(dentry)) + recycle_negative(dentry); if (unlikely(d_in_lookup(dentry))) { dir = dentry->d_parent->d_inode; n = start_dir_add(dir); @@ -2713,7 +2784,11 @@ static inline void __d_add(struct dentry *dentry, struct inode *inode) __d_rehash(dentry); if (dir) end_dir_add(dir, n); - spin_unlock(&dentry->d_lock); + + if (!inode && !d_is_tail_negative(dentry)) + sweep_negative(dentry); /* drops d_lock */ + else + spin_unlock(&dentry->d_lock); if (inode) spin_unlock(&inode->i_lock); } diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 9e23d33bb6f1..b877c9ca212f 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -221,6 +221,7 @@ struct dentry_operations { #define DCACHE_PAR_LOOKUP 0x10000000 /* being looked up (with parent locked shared) */ #define DCACHE_DENTRY_CURSOR 0x20000000 #define DCACHE_NORCU 0x40000000 /* No RCU delay for freeing */ +#define DCACHE_TAIL_NEGATIVE 0x80000000 /* All following siblings are negative */ extern seqlock_t rename_lock; @@ -499,6 +500,11 @@ static inline int simple_positive(const struct dentry *dentry) return d_really_is_positive(dentry) && !d_unhashed(dentry); } +static inline bool d_is_tail_negative(const struct dentry *dentry) +{ + return unlikely(dentry->d_flags & DCACHE_TAIL_NEGATIVE); +} + extern void d_set_fallthru(struct dentry *dentry); static inline bool d_is_fallthru(const struct dentry *dentry) From patchwork Tue Dec 14 00:53:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12675143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03689C433FE for ; Tue, 14 Dec 2021 00:53:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244519AbhLNAxy (ORCPT ); Mon, 13 Dec 2021 19:53:54 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:61376 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244537AbhLNAxv (ORCPT ); Mon, 13 Dec 2021 19:53:51 -0500 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1BDLEcaK022072; Tue, 14 Dec 2021 00:53:49 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=dwvIyrhIsntRrKYmTr6Qm6a0l+8t8q8Ghg1xyJtv19k=; b=b9ZzREdYj0je6W4NRFLIGoP36QGnBETSh7WOQ7suaAmlIRez5w5SSIumA5Yq+/k4gHWU MkSbkrDjVMm0eLpSjSqL9gxAQj9BYj3lw3VqzYjEfsO2L/g5ooPCFO4PArMG/uzJL7t9 Ls6HShdOFi8/nvzVZ8ymmbsbCXP/KP7fEQSp2EJbgBzSOHPUoePp6+jRchAihGYSxOnC QL7cJ/ZWmRSY4bQpJZkco9HFDdxvlBOfoJ3+9xP4p43BLNTnsZMMim1LDoDmL10osJEv qViWttJS0xI+yMZS/Q3XAmCSy/76MUAANaCyx1svVicepJD3GNfFifQBE2C6Tusc82fa uw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3cx2nfaf9f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Dec 2021 00:53:48 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1BE0f2SX133129; Tue, 14 Dec 2021 00:53:47 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2170.outbound.protection.outlook.com [104.47.58.170]) by userp3020.oracle.com with ESMTP id 3cvnep17bg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Dec 2021 00:53:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DkWfu+rLSINvARyKg2BraOJHpw7IYZFkc0dx5PQZpcvKkd859CjSVXMrUNc998Cbmv4QLoxAP6jPOGjKGnnU3SB08w1RoWwvJhPMRZkw0OPsnCdBB6UOVQr17q5sWdSh2Ha7+SmOGtpvmxIOiEio47ppiDa91RyLupexw3lK+8xx1sxvSI2EdBf7/iOYKCntCDOXXdo0gDxtRT1AKoHRU+70M6ORI693dlm3M1KfnzS/LLuvKIlA2wxE5OI8VzJgx6Q8c7/pT4ze1G6IZ3aMaSnCH/bCmrDvrG2jdmvNT9L1IWy0bSACIavMmWOiC7AY6KoSdu1ru97V+vFZJlzlEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dwvIyrhIsntRrKYmTr6Qm6a0l+8t8q8Ghg1xyJtv19k=; b=igJcwz1XhxDli+JBkrBfHGTu6v5YRM+MATEUaZA0gr3QfzC4QOuUCfINg+9tT64sJY1aYdYUwENFTpT8u2a0a+7rTZ94jVgdCnp52jOpnEwzZWwEAVvUqVCRJDsC1FnypXjMh3OuDjCqiY3zkwHSI2j94tA4F5u+KxsUhvyR+HRrLS7qwqTE9GDNv994lHLUh49w4DvKB640H49wtRZPivape05rddQNyTcRA7KksJr0Yon5Z/97M4b7YdW013GW/K/DbFBKGdZ8NUBBz26huvqiH5dsVUpix62fxVu3cay17tfBHBGzJaMI/5YLnh1s+P29M7hCm4VisKa8nzHpwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dwvIyrhIsntRrKYmTr6Qm6a0l+8t8q8Ghg1xyJtv19k=; b=PVtqMLHZoDFETdeVY/rboubIAVjxaIS5SgqOPvvaExZw+IElef/WbpWuUTQ1/HM/PezZYa3bpNkkfVbQ7IOD8GVdgabInC5D0DE1shmxvYU2PXa8JjH/CGmIHj87tUq7GJqQt0E6pn46O5uJ6K2wKROhP4jkaVpFNl5KB6S6W8M= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH2PR10MB3893.namprd10.prod.outlook.com (2603:10b6:610:f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.16; Tue, 14 Dec 2021 00:53:45 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::8c57:aca7:e90d:1026]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::8c57:aca7:e90d:1026%9]) with mapi id 15.20.4778.018; Tue, 14 Dec 2021 00:53:45 +0000 From: Stephen Brennan To: Jan Kara , Amir Goldstein Cc: Stephen Brennan , Gautham Ananthakrishna , Konstantin Khlebnikov , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] fsnotify: stop walking child dentries if remaining tail is negative Date: Mon, 13 Dec 2021 16:53:35 -0800 Message-Id: <20211214005337.161885-3-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211214005337.161885-1-stephen.s.brennan@oracle.com> References: <20211214005337.161885-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SA9PR13CA0139.namprd13.prod.outlook.com (2603:10b6:806:27::24) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 45239b2b-1602-4196-bba0-08d9be9c2e9a X-MS-TrafficTypeDiagnostic: CH2PR10MB3893:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rK8ht0i5uAvABR96Vi7kmq+Z3xdBwowkYKSkygCIczrsb+xkytPzPagGV4xQYkJIZhxAN5mEKZaXsqtJoG9aOS8ewtAI9XN3//Gs9vvF5H1SiwhfYbkr549gQoWDXCLTb4mkwSuOFTG3zwxcM8DRG8Xp1cG6J5+rmoaiIuXSD1Yvnm1rR8CS52z9/7ymwKxypTUqI3HSQ/cor8nRJ/qROJTUIC8MKsuTMu3Wm4UPtu+VnKHW0rVJOFuABWlnzN2P/EYJ2mCpqgvPz2e905u49dHHnkSXvggH3P1Aqez5Q44FRuLJA1LkzykF08u2htHbHBkZBElmlYYJ/TBEcMkvzJ1SCY8zE+POa12s/6zS042PK8AT3bgWi1i4qXworYl0xbt+/BWWy7uBREl7dtzskQOW1lbzTBrPDfZ13nJkpOIdPi0XquXFFZ7hB1rT5xIeiZCNM+7d4eyHcYGDTZlbslJl+ruxDtTFSgEdNalnrLBt1RARzt7UxWJRt6LWtpzwZeTG3Jl+WvHLmZw8ToEPPIpIkNGWVpRPkjKDUcpKLp8Yz9pUiDvEEy+iOhtb/05Gl7YTmVQRBT4FAfX9iqb7oiPznvCjOV2M7L5T5ZqV6t/LvN0JtaYQmgPyyXFoLnzYu57tjjgJ9PnEqKqxfpdxYpISqylS0cJWAY/np7QIGW5UbdZvkdW1S+jpbRJaBr8qAkKw8w60fodiqDC+aSFR7Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(86362001)(36756003)(66556008)(66476007)(26005)(6506007)(6486002)(83380400001)(103116003)(38100700002)(38350700002)(6512007)(66946007)(316002)(4326008)(110136005)(1076003)(54906003)(8936002)(2906002)(186003)(6666004)(8676002)(52116002)(5660300002)(508600001)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DjNs2joLNUXo12mpCAUyqyXJmN/wL6gxMdYuPn9+l4qu8HPuANRLz0TCbtTejDbsI83DBnubsQ0o9EY9TQGYHbd2ZchLWucLSMcmUvLJajG8vuR9KowAuFuAj9uWQI6kPPLSGbqxcPcCdbWw0R80Ly/i95qMJCoufcLcrpVEh0/wDv2mQ9go9Jnp9bvUVzeRLPd5LZIgVS2u9GMvRMnEbe7woeAn3eO6hD7CBUEfo7LVXFWXKR7YuqJo/+24HkAz10fp0W85WKOwbyk2dVK3MHsdW6vadBuiXKDh7uwfeHPhhlH3BI+lJMPQ4u9kZ0jd9hEu1cL5hpDeOHKO1SPDVnXihAjruz3wNRgh00RG5ZEAZz4OzI9irk9L0kGVsjC7QiezqZ0ErLO152ULMEZ4KoZEfqT0kEVzDE6EqVCiYZsI9B0LusQGMpBHnAOlHNfFegmv9N4LRT6C0lPeFTZxodIv27sH/Oq3jbTOBL3gTKwk5tmR+aWdqXuwOYFtwGvdiMHH23c+f10UYYKk0DqocxlXQM041sZntKEEjJbqbSy0bkpu2Ej10vQ0LYcc66GeN5NqqVUIKmdKRFEU3vy6/8ogQDwoR0wqQZL0LkRPlecntvBZqc7yhUbfl6/VB8Ecb8FPR9PgqMh2z5wLmDzCN1oEjb/Ol7Ge9H+WXIRdFpjZtTHN1+ahjygci9QTG7MwPYZ+1/b8XJMmBWcTQ9WZ55w5BW0ZYO+Z4jKaqMSDAW90TwRuqCIqc2XYVHCNrxgdp4A5hp8xxQ8+c73Eur1sntHZfDImOkHAe3DvdE2cIy/7NW03ef6vMbteMB8zhk9HcerhPcw+8Er2pzkhoop/XIRtuwLjJojKDNl9uh32bMkDNryPD9aFaj9xV1bW6s6i2mdqP8pRXyq7wJYaqt07xsZi8Qg1jcq/gWyR6kG4z3NcdoPJlmnXAotoKtzWo6Jgu6ektfH82yTYGNrUlTDigNDWe8gPm0Sx7DUXh3c13BdUqfsGuQ3lNdnHlnC4xQHpZOSWW8vduArI3NrHSU3zQLXZMOYYUHqHQf3uHMsaB+k7Fg8QbKKvhjW2aLAqr8GLzzHSDqXxUOnVyayZuh2T/aBMn5he9koQRG4PXPej9JGx/duVWYNwnTINwVy6JLWABkfMYnBIWWgt34QdpruVykiTMHZM1JjnhjQpHGwp/5wAtvqkKQ1RsZGWBswREQC6KxTstPKbr5cURu6r+O/2XifjG446PCwsLTNv1wRR/feVovPVpVDpqMEc6O9+7Q4YTJYL1IUTUwJtq/9ux4AqBNJ66mnyyf+TW3KzgmAJjuOFUjSo1irLdr1vZ57HVy/itWfes62AXnFokxx6havWfFWtQRT9TEOmA2Qw2fPoPTToQ2St1syovWvAtmj4F0Ts7h/hBTQFg5su5L+JVlqUfHHgEgwG1r/yGO9X4FTQ2gqFMK79lua/NyMspoEjclA5hLvMSbffcJkwPXoXtJzgD2MkCwFx1DNk7M/RjiJI6HJ3IR60Dpoi8k/jTIPOUYPcEqoBHlG4CDmZtYJCszg9R1cGNq6QvP8SuFN1SfYpjUXUkAtF8Sg9MdmM0D/cfRPjZR4znqAEY7lQrNsp1N+r+WAwVgwHhsEHhEoCqI4VDghhQQmT9WdemF3468Ui9QP7zgw2+MalvV02lmr/u44iXQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45239b2b-1602-4196-bba0-08d9be9c2e9a X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2021 00:53:45.6797 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YZX3NymnrUkTd72eWyzpPcmT+0ItCVwMBW2010uORIBADlNnQ1tUQdEavocYcAuA49TuWGDcro+/jmIU3AYfeW4+vGk8+KD35ePz9/t3vcQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB3893 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10197 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 adultscore=0 malwarescore=0 bulkscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2112140001 X-Proofpoint-ORIG-GUID: 0gsDhyom31aHsqAv3MZpChdIQ17kVwJY X-Proofpoint-GUID: 0gsDhyom31aHsqAv3MZpChdIQ17kVwJY Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Konstantin Khlebnikov When notification starts/stops listening events from inode's children it has to update dentry->d_flags of all positive child dentries. Scanning may take a long time if the directory has a lot of negative child dentries. Use the new tail negative flag to detect when the remainder of the children are negative, and skip them. This speeds up fsnotify/inotify watch creation, and in some extreme cases can avoid a soft lockup, for example, with 200 million negative dentries in a single directory: watchdog: BUG: soft lockup - CPU#20 stuck for 9s! [inotifywait:9528] CPU: 20 PID: 9528 Comm: inotifywait Kdump: loaded Not tainted 5.16.0-rc4.20211208.el8uek.rc1.x86_64 #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.4.1 12/03/2020 RIP: 0010:__fsnotify_update_child_dentry_flags+0xad/0x120 Call Trace: fsnotify_add_mark_locked+0x113/0x160 inotify_new_watch+0x130/0x190 inotify_update_watch+0x11a/0x140 __x64_sys_inotify_add_watch+0xef/0x140 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x44/0xae Co-authored-by: Konstantin Khlebnikov Co-authored-by: Gautham Ananthakrishna Signed-off-by: Stephen Brennan --- fs/notify/fsnotify.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 4034ca566f95..b754cd9efbad 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -127,8 +127,12 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode) * original inode) */ spin_lock(&alias->d_lock); list_for_each_entry(child, &alias->d_subdirs, d_child) { - if (!child->d_inode) + if (!child->d_inode) { + /* all remaining children are negative */ + if (d_is_tail_negative(child)) + break; continue; + } spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED); if (watched) From patchwork Tue Dec 14 00:53:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12675145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0C17C433EF for ; Tue, 14 Dec 2021 00:53:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244543AbhLNAx4 (ORCPT ); Mon, 13 Dec 2021 19:53:56 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:61640 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242767AbhLNAxw (ORCPT ); Mon, 13 Dec 2021 19:53:52 -0500 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1BDLEcaL022072; Tue, 14 Dec 2021 00:53:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=pI+3/77VPPy8Tl2qH/DQ9k4hMlg2avKEUVXFwiO0Xjo=; b=MZyxMhs54fKXV3+bYZV52U6vHPZojsjBCwIMokGzRrDdc7VP8pElzy623uIhCwu3dQMk VdiRwC7rgr3hIGtN8VNiRPHRGYjhBcdZyaj/J3wUrMMf96RtW7/liisdUINMCrWCnjkM IBWFq0vcEQJ1P5PIjkLnh49XT28twBhSd/30rCz+L1snFxuTAOYYvLF7rqtF1w1lEjfX Aw+yCH1oYltqjX+U1QO8fG58zZlkyFsueUyQd5s4WryhDGPMBp3jIuyVD7eVF0vKn9VF FXAG1x1NtmdpCLkgLXcE+TgH1CHxUg9B6sbxN9R2hFtOWdI8zGgnB85C3eGc1BiYKvtz rA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3cx2nfaf9h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Dec 2021 00:53:50 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1BE0fm8e122494; Tue, 14 Dec 2021 00:53:50 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by aserp3030.oracle.com with ESMTP id 3cvj1d37w9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Dec 2021 00:53:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GUycLenU6dVElbmwa6yBsVoYOC3fW+OegbVHgnB9i2XKwYFOOwCZraFYWDrr0A1TWDAD4EbCUiM2AvvMRqveE0wjeWNAGjbITpi+1fNR0WserwfnhSRwEp4hS91emQkGrt/wabo2NwT/6ivY4BXtbX+h+t9jHSmze2hero2H4hvdHtNxikSfuS1oT0wNkJVO0yQbz67Q1Ou/tv6buqIwDbFtepu6uN+IroSrpCjslgjRArHuNM6o1ySW39Qq7bOY/cp3wVfcPrrZVSwFGWAp+wWgMJGpycnHKKS6feLZgbxd3srKNFtm8FxlyN4YyX+KMNgENlukIJB5kBJzvQzcYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pI+3/77VPPy8Tl2qH/DQ9k4hMlg2avKEUVXFwiO0Xjo=; b=Wj/xcfEKs3hY1M15nHtW0JisNr8ryc1ODS/V7b8NrtvjsMM91YUUtqzAD8YcTzHyOOlHK5OaMtLyTOgeUHRlbFMldMPV4PUx/lJto6TnbEjLxa4+6J0EMBO8cY952mTj6K/ut6c4A1KPIaO1WJ+x088IaXYXy2bpqEQWCcxQrO4iVsA3Pl99ejquvjKeO6+OHIk2nDXRVrByzrQptP+BT26Yu31LyQ5AqIWPVMigrOQt+Kw8RGabt93o2ImKIbqSwVolEzx0hBvYSRiFE15BWJsyR1eRZezoaCmhy96oemScWZ4MeTqDb8WZ7jpsPYxBDvhrore2gLnU3AtZscWQaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pI+3/77VPPy8Tl2qH/DQ9k4hMlg2avKEUVXFwiO0Xjo=; b=nTK5BVoIbzYNNROn3ZNrE01LLyYNc7UgrOjo7id773b0HCpFKdGAELL6KTBm+kwoU/OO/5qX1/g/pWzej4PdJ4NhgwN3aU3p/fCPhXGxbxOyO3xE6Ps77NijBzvLHJRHvsj511KqID6HMwf7SPagNiabq18D6uAR6QKIMulC1h0= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH2PR10MB3893.namprd10.prod.outlook.com (2603:10b6:610:f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.16; Tue, 14 Dec 2021 00:53:48 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::8c57:aca7:e90d:1026]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::8c57:aca7:e90d:1026%9]) with mapi id 15.20.4778.018; Tue, 14 Dec 2021 00:53:48 +0000 From: Stephen Brennan To: Alexander Viro Cc: Stephen Brennan , Gautham Ananthakrishna , Konstantin Khlebnikov , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] dcache: add action D_WALK_SKIP_SIBLINGS to d_walk() Date: Mon, 13 Dec 2021 16:53:36 -0800 Message-Id: <20211214005337.161885-4-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211214005337.161885-1-stephen.s.brennan@oracle.com> References: <20211214005337.161885-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SA9PR13CA0150.namprd13.prod.outlook.com (2603:10b6:806:27::35) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fe398783-f645-4664-c3c4-08d9be9c2ff6 X-MS-TrafficTypeDiagnostic: CH2PR10MB3893:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:632; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: p04GH3VXcoApV9uUpeXqTVht2fdDb7tCkiapRx8+56o6BNCIJcBmlSZMHXqeqIjvZV6/wBl6PWI2ktfcgCl+GOQDGk5H8bhWL1AwJnmgohdNTjgj2y98OEEjSMa6fJOkcAQZKADtyQRIVj5q0wapG7FmO5318YXHR0Gb8/xp6bjx9rQsxQAZ4hwBX14KsD4K3RaOCcZAaB+zghY9t/TS1i/U52+5bVOFhfnR6s7TsqgwPHTgYFPLBMXBRwP51nK8Pc+AROqqBZt00e399kzG+37Bw27rTh/ZtpNMoWpsh/vJT8Q9cjDlFJvrvcXoXsAefxqOgeyIBpC+rFC0yvHMynuOC1RBLqAqZ7l5TRWG4Q28CrOMT/tn9bpWuCBiZzxGxdRW+rVaGfvsJwDnfz5VmDqJ4RpyzMUHJTaTus72q1HtgER51mqJE3Cxj4dm104LGCR2JeQ1KSAMCRjJ5bLlaAOeXnHef5BwXRfkhFEi1MYfqZCM9FXttMSlnxAGkdWqDJYz7y50CjkUQVzWq+kbLv6egCs1lBSmo48q4YeorG2xDRA5djBAe5RjuAXmawWSUxj0KgEoWjEjwhG+KC/cohdtShUcVptZjhp9cvzjvkII0Qza+vW1rHtDeLOqVyyJdiPa+olZyOXPmMTTDcA5966XjVn8Nv37nQltfiCOjHlt0de0pLT6X6PymQlSozU+AFx3h9bFRUQjPMwmOiW5PQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(86362001)(36756003)(66556008)(66476007)(26005)(6506007)(6486002)(83380400001)(103116003)(38100700002)(38350700002)(6512007)(66946007)(316002)(4326008)(1076003)(54906003)(8936002)(2906002)(186003)(6666004)(8676002)(52116002)(5660300002)(508600001)(2616005)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uRhaAfpAc3d4qm41KUnpNdAPLnl+QepvsZi+rIVC394DHY+m5Lkpszl0mBqN3SQWkbk2KVsdTrqlPA6yCRyxBVpwFgTz0jrnfUD83tKjztARqY4gNfvufQ/mkL4fD6JoEg2sMR0axEOL5pVsiCCWn/Dep7cl1N16B33jMooxa3AwMc/iiUhgbdyNnjZ/MBWj6GKHEQU93htCFoujyDGt2SACmAWpJfwdoZaytY/AY0Eq/HAAtRTq4Os6QYyJvo7/MU12HZeoUVKHhnHmAiH8GT+vPpJ/YLaNj0c4tnMDZfQokO7kds9K6tvYgea5PlRrRs3soEY9DbQ6fq6zGXlP5exrVag8tZCSRWw8ni0ntAK3NEOJyGMFmW13kiEvRVO1xh1AUs4MEwLDCXb+J9RpGCKLOR3F0nq2BjOCd3wZsiZsWIkC1xg4UqpM0auqfajaKgBDK7s6RUcjafD60TG6knwdNzzS1UKzBqrFNYiQAN/xrje5Og57p7z9sZkL3IvhOuGA9x+BxJj/Cp0bqWS3h3U3iB8np+6q3j8DEh9NYNa45PcaxCp6jwY3pWXS1HK4zHlyFhyba9Y4UMEHLdk088u9fJDAIusjW8Nzw8SEzHx3t1b3m10NFzw0wB5iiRLf4nQWyCmQvMA3ONZz85N3HgxGl1SHSG7D9I813sr8KLpjeU9XENURW+xn8MTVEh66MlSvm1xAKNkbIISSCNqCqxR0+bpAF7vdPCDJcCrDVJ31DACH2gj5x4Z271tq3MfDXc6HWpzEWq3f/wQemTjRpgsV0GiJW8v/EnlMV8l9drP6Xg2SQftg8q9OruY1E1fJirAjlw35fU+lUsHRTmXU5PjJkz9UZTSwlXlQPEzauXNxPktxGo0QrL1Btgi3L+vFQAM9oRKOKwZLJ4Ssxzk+1PIbjA34WiA/B+1I51BI+X/vv6TAH2o4bkQ1kMksjCINBKQiQW3KkYMTvFdY+vfnM4BDqDTagzzGQFFGUpRpjxyc9vUnED0wjyJ/68AIWGJ5ucHaBSqApJxaZcKpkB2KRANA7rpJvS6qF/GQ//kTXJa/oej02agkuQeTk7S2kLBIh91H/XhSvj13ydnbhhGfN/TtIDkLJ8O7E3GzrOM5/+exltaWOms5BYkvQKw9XTG1UL9EOe1L587wYs+3XlSfDX2IUKTX8XSmpV9mzCwqTzilc/qwMOYD03bv+ShO8XNZ8oD8HftO9FDl7IlhgTKm8uqPEh0h225SQTEHXb69TzHrZuwk6poO6zLuyIALI2N1annEakiQ/ivK2J4nF10mIqTV2Yr8R5CGK0BwahZS0XoaRy4ZnU5CM8G0F5JAsgZ9q/5aZRJYVXSf47cpmWq2brS+8rJZE+FVVeWu6Hqi5sbXeURol0/EgbnW4c+xaXyRW5kuUIBQ5H4Yyx89nK0nNPf5Zk0+NEBWA+UFMhoQXGrPUiDn1XGO5O3LM8kzBzYZ/XFRAZhlF3z9unnd3IvOz/xCzj6IyU9cv+t6P+apPQ8Odd2+QAZRJwWAWASeCkPWO+4dFQ5FGJ7N194WqawoLgyAEgUuUL5DphhFYCQ+OCUMSg/NZi9LWIywNayb+Zv22de8Xvzb+sey6QPVTY4wNwJlfFZRoZysjbFGdIRMlk+eVxeOUvMVWSHcH6E2wtpJNI1C5lJcVKFqxOF8MMoWfQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe398783-f645-4664-c3c4-08d9be9c2ff6 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2021 00:53:47.9606 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HymrENI/MUnhoVXCKnzfSu++zWmj4lhZLnq55ZSnT6YTxw7S0Lx7UCdkZRN7xkpr+/KkNJ5ra7w2/GyHAh1t3dQp2gy6rlA8rCm6EWesvDY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB3893 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10197 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2112140001 X-Proofpoint-ORIG-GUID: ttUHbSxXJbyaQkp8dbDL7l3kyegcUqgV X-Proofpoint-GUID: ttUHbSxXJbyaQkp8dbDL7l3kyegcUqgV Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Konstantin Khlebnikov This lets skip remaining siblings at seeing d_is_tail_negative(). Co-authored-by: Konstantin Khlebnikov Co-authored-by: Gautham Ananthakrishna Signed-off-by: Stephen Brennan --- fs/dcache.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/dcache.c b/fs/dcache.c index 685b91866e59..9083436f5dcb 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -1366,12 +1366,14 @@ EXPORT_SYMBOL(shrink_dcache_sb); * @D_WALK_QUIT: quit walk * @D_WALK_NORETRY: quit when retry is needed * @D_WALK_SKIP: skip this dentry and its children + * @D_WALK_SKIP_SIBLINGS: skip siblings and their children */ enum d_walk_ret { D_WALK_CONTINUE, D_WALK_QUIT, D_WALK_NORETRY, D_WALK_SKIP, + D_WALK_SKIP_SIBLINGS, }; /** @@ -1402,6 +1404,7 @@ static void d_walk(struct dentry *parent, void *data, break; case D_WALK_QUIT: case D_WALK_SKIP: + case D_WALK_SKIP_SIBLINGS: goto out_unlock; case D_WALK_NORETRY: retry = false; @@ -1433,6 +1436,9 @@ static void d_walk(struct dentry *parent, void *data, case D_WALK_SKIP: spin_unlock(&dentry->d_lock); continue; + case D_WALK_SKIP_SIBLINGS: + spin_unlock(&dentry->d_lock); + goto skip_siblings; } if (!list_empty(&dentry->d_subdirs)) { @@ -1444,6 +1450,7 @@ static void d_walk(struct dentry *parent, void *data, } spin_unlock(&dentry->d_lock); } +skip_siblings: /* * All done at this level ... ascend and resume the search. */ From patchwork Tue Dec 14 00:53:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12675147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E5F7C4332F for ; Tue, 14 Dec 2021 00:54:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244546AbhLNAyD (ORCPT ); Mon, 13 Dec 2021 19:54:03 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:65200 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231908AbhLNAxy (ORCPT ); Mon, 13 Dec 2021 19:53:54 -0500 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1BDLBGN5021573; Tue, 14 Dec 2021 00:53:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=zIfhDDpSMs7x3BIxMmfYRyCBaLwg1LOuB8LVcVYO8K0=; b=uM8XF+ZaWhUZzdtPxmX3jJ454eWaVgZbm7BPr85Y/rolHyiWMAxECi345soupcC9X7kf AN4AXpihal9CMuCh5O5C2DvZxJy4iUzDn49kAcj96O/+SYn32m/HmpCGh/wZMiG04lf2 40XVX+d76ehQEdaNPvqOJuDH15goRPRvxEjLCoHNlYhaguNezDY0QCbv6HScqrCUkwxI VtownbrD24m5TqJzQTR1RUdmM0WVeztoD8GV2oFd6IU8d+GSigYNEFgzmuDThiSSeyOh dflgkuE60jGFRY1D0gtTEfJczCWizmVlYMrSuoYt0egVsNq9Dh9XbGRGzgEnyDtfy96Y aA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3cx3ukab9x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Dec 2021 00:53:53 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1BE0fWGB190002; Tue, 14 Dec 2021 00:53:52 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2173.outbound.protection.outlook.com [104.47.59.173]) by userp3030.oracle.com with ESMTP id 3cvh3weegj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Dec 2021 00:53:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TvrfddpDrB+cPhHZocwQ4oP1rKsdRge3TrUVUJlU1jqcp2KaoqI+vV7D0GvnOgjRKhL3jlk2QLE3F4QfG11uqY840soipRgpfxVBTqVlzs86gjc1WqaZskJoYJ5RkD3IGXT0NO3Cxz5r3a8vOFFbbJZ60Aooi14OpXStNvAEQyLoTXoOWKbk9nq1tUAb8RD+qAnacTBEQFZrXD7vRDmmzDb6fI341lrORevMRIbB7ZgTzIMLJE0pz1QaCdMKbDgHNH+wwkUCe/181wCpUwmulJez/tbxfmQ0fURgnx7VfcmB61SEkRU04pFtW7WfKciKjROPWJ3Y8AUp04vQqhoOsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zIfhDDpSMs7x3BIxMmfYRyCBaLwg1LOuB8LVcVYO8K0=; b=UzPXp3ftxP+hFpbxF9fR7W9oPWMsdC4J2KUFJ85+iNzX6uh+7z4CIb+BWGjPL/phMLLIssLTaH9KbzGw3wYbzM/xZzJ148wkY0wM7Zx7w7Awh2Tf5c0utMPa278SP5gBNipuQOoKFr6J6L+I1c9cjdcH6hKA4Wfr8t6N5S+mYffFiRjB7ae3niNMOGO1TAciUoaST5PUTSttvAFS7DiTheT5L/Sp36RX6OzIa8Pasm/ltPz/3u9sF4ar+mH/4ffUQN9NJ8yMLXSqL7OFdlkBC9Jd0pJUTNuEcna9Rb0xmTMYAMsuwpROwtKrAXb8ipd+ZIX/whnzVu20fvcI77u1pw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zIfhDDpSMs7x3BIxMmfYRyCBaLwg1LOuB8LVcVYO8K0=; b=ogk7CdvY9UHpXNxoGk7IfD6W1FOsU9qnhV+Kqm2WMh0oBwRttbtyO45ZUZy+tRF1BpDIkA3js+LSqVXc5qco5pQuz2+WCZyJl3NXkIaUpb6930KqWhkaxSBlPUcPAJXsuh6zqqsnEYghvnZCVhJWv4OYPIaHP7+mnSzO6b1S2Bw= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH2PR10MB3893.namprd10.prod.outlook.com (2603:10b6:610:f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.16; Tue, 14 Dec 2021 00:53:50 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::8c57:aca7:e90d:1026]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::8c57:aca7:e90d:1026%9]) with mapi id 15.20.4778.018; Tue, 14 Dec 2021 00:53:50 +0000 From: Stephen Brennan To: Alexander Viro Cc: Stephen Brennan , Gautham Ananthakrishna , Konstantin Khlebnikov , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] dcache: stop walking siblings if remaining dentries all negative Date: Mon, 13 Dec 2021 16:53:37 -0800 Message-Id: <20211214005337.161885-5-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211214005337.161885-1-stephen.s.brennan@oracle.com> References: <20211214005337.161885-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SA9PR13CA0145.namprd13.prod.outlook.com (2603:10b6:806:27::30) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a3e9ae71-8d34-41d2-6b42-08d9be9c3168 X-MS-TrafficTypeDiagnostic: CH2PR10MB3893:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:115; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l6Hoha26YZJ8dij8UUsTWxwKOS8mjT/wKsc7/v4aFyP7rK+57fCGAHq0uBQv1/1sQjD2Yddv96x8jw+XcaEVJbsAG/6JlFaPzEzzDLII0+PhFPPPdau1LYewig+MAf5JLxkurJPdRC13QQFb43kKaPNqbrZ6rvgZgLX40X4+VZ733tBWTFpde05yDyk3Gv90Q7yMhuMzQ2Bd1ZJ3PrqBSHVz641pYHX46d9lvdKVQ8Bn1cKHlvNRUnLsNUx2AeU/g/+aVi6UD6KbydI8JcUytDd62oUEnzLJG1yLF2ZJaL6T5sAz5HA+5RmjG4OnJDebXaPInjdXnen8DKos8JHhmFAuBSsENX/pvc4LJEM0UYvZBRqQiFv0BZRRtiYlZCmj13Xqb2wIF83XCQFsA9y+ZhdBuF12/16ADOw1V1vqDwynxoZRv1HQ3brPNgzHuCE5qQ1IPsG4QwcZrMDLzKsz1L1IqqCGiv8oeFQ8VgNZzt2kYUvtb70I+VnSTq+KrP+KfzD4P5gg5loJBkdv1czA/cuhCjDnJZquynq8AccX+30p4nTSqxdHcNAVukRQVMGoAMTpH3gdTMDpXtx2CISM6CB4o3W87EQcXJNQ/Vbqpmq+xrNmgzv8PcqxJ/dvHTgRdfy+/rONRpTpPcDj5D7er95XaTVXrmWe/2QEhQjSvPLboLGQfszJ2r/L7Nuli6yxgU6yto7sapI2o6XqV5GNgQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(86362001)(36756003)(66556008)(66476007)(26005)(6506007)(6486002)(83380400001)(103116003)(38100700002)(38350700002)(6512007)(66946007)(316002)(4326008)(1076003)(54906003)(8936002)(2906002)(186003)(6666004)(8676002)(52116002)(5660300002)(508600001)(2616005)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mYCbIzaviqapGepHfSPzTIn1RE/px0dPclaeckwDMHoPJXRQWprAnxT154n9bOLHJfqf7cQQ2LltY0J57CIMngwJYGK70KRuquxgoFkMJij/MWAHApoCylHdVK7ZwcsJYZT17nz2BrDAWJKS+qxw4GBSSDnQYRsCs3pejPEZj6/hDTYB8psjfWTzpTIFbC4LKG7/476bwj5wRBVVfcsoV+M0iq77LMuzT4Ib4b7kgyxAoJFRwOJXq7eFbVEMbRivwpAiPpdJzrB6/6i5H3ZBAmwU3wuTK+7k3mednwc9U5P4+iXZ6V7FjXoYMslG/hTXPbvMqYCbWnxGWBxzUylI3y5ZrOrUwYkoomvhzXLbBb8EfwfjTiZamFNPzO0aUgrlnofQA/J/UuANZsdQ8heXhYa1azjJxKBUtBSJgVqHkfRtprGDEmo41uJlow7329qGQh+Vmb3rGVehY7S2nhPr1VqGkHBh4n0bljS3gdwh53pa53aZhc74Xj0rSMoMNEztUyOSTVRqfTd50Uvg8o8nADrmI+oiSyXl1LeCgFylsT0pDZK4CLHS6W1ekgs56krCHRrIQlRhNVYK70uOt/ihWbvgNME+r6jh2b773sVxRdGMbNnVlyvA3gWQLvy7seF34rMaUf67LDed0TJU/h0hUx+Ot+7Gq92biKPXSlZwVs6O9tT3ZDVunuIvA+XXcbVbXJ1kFYP32P1ZQZ85Ii4SoLJdIC+q7tTyh/gAGP5f6+q5jrmpKuV3LIXdO4+OijkedjoGMDFCIFY+9yxchQOhbWCUn9d65dA1tGLwp+jKbTQIqyABh6IY2KTcsuOm7+/rFEZwYiinA/1E/b/7vu7WjkUx944+/D73ukppal8YLN4mkcGNuCUzJH+5UL2fIPnbzwBnK3TT44zP/aPYR/vv/Ki6346O6LGy7gZpxxCNlJ2tFZyLhg8Z4zq6i7So/m05ZL5LzLQ6tkHreJ9nJUKJLLhnktfzDWEJGkIDCuaM4F1V9ZadK7qxJxv42VXSQ4AX/QehXCwO/eZbA+pS0iAZP7d2Lyw71AvJD7BcAvtrBpzDo2g2UH0j1DQJk6r33yQ0nMGZQrTbj+NqOHRWV8ZLdOUIJZh7znZhS6qBAlJk0OLMpSTIMT8sg1t3GBqlGa79o2ut4zwg5LotvvDxQBpXrOxpAKqF5liAa4C9YdMiK7BSaJh4ETrZWPnYXANKdEgiPQKxvxylqlQH1crmBeijAMzABYlxrJX++6LnVdL0XzqO2DHZ01MQ2MtLEHpF9ASX6GiGbcRGz1423d7FiL2ebubYwVYy8MponfrgDK+a3uekpf5ZeBdKdg4zdjJ//lNQtULy09+nrjDH106U1ACM6FNBzJgEzO3mD++Vo8CW1GynRsMBoXGdKHxdtwSyJxvk7qNHdorTFSFnQwLcQYEXga3hQYvzBFS9EM3ux2iGM6+ZCzTtJew0Xm60NjfGPa15TMcQFYveOODfElMDKamUm8CYidEmTgOf9VyWTJJTDLqurwHx3/lqdavY9I8O3nNh5REZn3tw77lIjSVB2k2z+1Xr8cmaMNYc9uMd56O9KHIJrsE1zc5n6x6pXBVcDAekZWu12oXG9xmFGXgtt3JzT1ULepUbzMTJ0oNJvek1/NGZKU3L8M8VcxhQhzEg4XLECv9uHqh0skT3r+oONxB6ow== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a3e9ae71-8d34-41d2-6b42-08d9be9c3168 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2021 00:53:50.3988 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EE6imNkkmwvrgKKAIkL6J8FAxB56J91xwIV9qlfkviRFalRfz1elE1m2SuODWHhGhV1NxGdXBdfyQ63f5yLj+PgJsBew5oDz65F3cRe09WY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB3893 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10197 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2112140001 X-Proofpoint-GUID: tqjzWpEJ83S9ccxRnTzL-IPdmgLOswWe X-Proofpoint-ORIG-GUID: tqjzWpEJ83S9ccxRnTzL-IPdmgLOswWe Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Konstantin Khlebnikov Most walkers are interested only in positive dentries. Changes in simple_* libfs helpers are mostly cosmetic: it shouldn't cache negative dentries unless uses d_delete other than always_delete_dentry(). Co-authored-by: Konstantin Khlebnikov Co-authored-by: Gautham Ananthakrishna Signed-off-by: Stephen Brennan --- fs/dcache.c | 9 +++++++++ fs/libfs.c | 3 +++ 2 files changed, 12 insertions(+) diff --git a/fs/dcache.c b/fs/dcache.c index 9083436f5dcb..85f33563936b 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -1505,6 +1505,8 @@ static enum d_walk_ret path_check_mount(void *data, struct dentry *dentry) struct check_mount *info = data; struct path path = { .mnt = info->mnt, .dentry = dentry }; + if (d_is_tail_negative(dentry)) + return D_WALK_SKIP_SIBLINGS; if (likely(!d_mountpoint(dentry))) return D_WALK_CONTINUE; if (__path_is_mountpoint(&path)) { @@ -1751,6 +1753,10 @@ void shrink_dcache_for_umount(struct super_block *sb) static enum d_walk_ret find_submount(void *_data, struct dentry *dentry) { struct dentry **victim = _data; + + if (d_is_tail_negative(dentry)) + return D_WALK_SKIP_SIBLINGS; + if (d_mountpoint(dentry)) { __dget_dlock(dentry); *victim = dentry; @@ -3231,6 +3237,9 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry) { struct dentry *root = data; if (dentry != root) { + if (d_is_tail_negative(dentry)) + return D_WALK_SKIP_SIBLINGS; + if (d_unhashed(dentry) || !dentry->d_inode) return D_WALK_SKIP; diff --git a/fs/libfs.c b/fs/libfs.c index ba7438ab9371..13cb44cf158e 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -411,6 +411,9 @@ int simple_empty(struct dentry *dentry) spin_lock(&dentry->d_lock); list_for_each_entry(child, &dentry->d_subdirs, d_child) { + if (d_is_tail_negative(child)) + break; + spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED); if (simple_positive(child)) { spin_unlock(&child->d_lock);