From patchwork Thu Mar 31 19:08:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12797608 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 20B1DC433F5 for ; Thu, 31 Mar 2022 19:09:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239883AbiCaTLI (ORCPT ); Thu, 31 Mar 2022 15:11:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234157AbiCaTLB (ORCPT ); Thu, 31 Mar 2022 15:11:01 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC19F58E4A; Thu, 31 Mar 2022 12:09:13 -0700 (PDT) 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 22VHkOWa007047; Thu, 31 Mar 2022 19:08:36 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=CWh6wty0T9Uj2qikxBKAGxX7C47IhSdI7DMHG4AQBDA=; b=Dbhbow2p3N92d+9MggYpBa3Yt23aS+5cfEPeaLvlYABICAEpE5F96YC0kKRTUbtht+7y 3LFnNdaRfWXfFLSu346IFz65GJ+/ZB0MPinstEcBeJKUierm6SpnB0CrPepmXMpqx9Gs PWbUzrbGm1FzTGBiJ2276r+iERuA2VJWBryDWQviZYp0GBU7SnyBHpOcGSrmCIbpFDVJ fBKJw1X4T277hbXnYMe7tLRAe6qypw00lK2Hk5b5HqKZVhRxMyhvb1zo/ffaaZrs4PSf 43otIW0ZuU0lcX7b9383NqDCw61SGrzf313M08nHYuZRVMBxpk007gYa+ZymDz6o8hpx Fw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3f1tes56mv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 31 Mar 2022 19:08:35 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 22VJ2Pa1024848; Thu, 31 Mar 2022 19:08:35 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2171.outbound.protection.outlook.com [104.47.58.171]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f1s989x9d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 31 Mar 2022 19:08:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U9WqkKIfNaD6HZU9hWQvXvbAkoYaw+z1df07S8S+Y0mWLdBXj0P2KlzPH0T4zLya0/Vj7Lqf6wzHF2oeguZpX5xo/Kn8nAXYRquRd9ZU1hfuTfE93MmAA8XGNVw/ehBktdwNfGn4KtVq7MS9tkQXbQWg+Xev4hQsl8qXcKZum2CV2C2fg6AftYmy3p/+90IPHWw4evinEAXeFAVq/XoBa7rRwSJmKeaAZEYmGxE6txJ7iogU/eaO+X6Y/OQZDv00Fq1zEzPnK79s5xCw62Isr799TsPrRrlvscpchN3DwKKy8UrceF3Lw03n656L1LllhzfAjN2WHBhGpj7HJ+AxbQ== 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=CWh6wty0T9Uj2qikxBKAGxX7C47IhSdI7DMHG4AQBDA=; b=GyXuskLhDyNj2ZWm1rLAPzTgWJ5W0YtbB6TMDbhoPWhp6V6M/nAhqrumP3FoUJ/Za7XnAV2v5UBdcKB+8ciw2tYwdWLp/ATgea1auPjo2D4vnd78X8bTKxp5GAKt4PJ/BXPsL8vr2nPp2l5Ag67u7qiEZATgObuHlbbwBet8bVn/EnZwsKJRB6ZS/ekuEk3bUW/xY/cMQGAFaC44IWV9mq581C5e3j0jqTNMfDeXS4ED9YcD++w1Jv6+S3vk4Pm6sygRAR6X6+LeMttr9p1sGAdoBDgcjAdCK5NLCOHTYKi6b7X1/GIHrUSe+a30hi+BpsoBsEXXhxeOO+Eg9nHSVA== 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=CWh6wty0T9Uj2qikxBKAGxX7C47IhSdI7DMHG4AQBDA=; b=bVL6Ggqnq2Eu7ibUf0a1c+N/ZSXP86dJ7NvwT8A+RH75WBqpFXQWfLgqZUYf0FAzgA5vz1OnPegOD9uMrYbJwoIOSBfnkNevYooHHdk8SSocGxGF9/SBFEtdrAOGzhTYQ1XV8qFjLYbleR/yxTLA44OLXOXsvvMRWoXBxnNTs40= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by BN7PR10MB2529.namprd10.prod.outlook.com (2603:10b6:406:c4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.21; Thu, 31 Mar 2022 19:08:33 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::9ca1:a713:90c3:b5b3]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::9ca1:a713:90c3:b5b3%7]) with mapi id 15.20.5123.021; Thu, 31 Mar 2022 19:08:32 +0000 From: Stephen Brennan To: Alexander Viro Cc: Andrew Morton , Luis Chamberlain , Stephen Brennan , Arnd Bergmann , Matthew Wilcox , James Bottomley , Gao Xiang , Dave Chinner , Roman Gushchin , Colin Walters , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/2] fs/dcache: make cond_resched in __dentry_kill optional Date: Thu, 31 Mar 2022 12:08:26 -0700 Message-Id: <20220331190827.48241-2-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220331190827.48241-1-stephen.s.brennan@oracle.com> References: <20220331190827.48241-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: DM6PR07CA0079.namprd07.prod.outlook.com (2603:10b6:5:337::12) 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: a997d9fe-ddd3-4d9d-dfd1-08da1349d957 X-MS-TrafficTypeDiagnostic: BN7PR10MB2529:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zXjxZ5z5fJRN8MGiiciLEPo/s0VyDEUaEWTzBoS4C8lJHHguwK9cva26efMByvxfeBqnQzuNkjbinIkjnISKRb3Sh/Ptr5KfnGsrTTtCblGCqf+F7hqPo3JKed6QKeYjUj5hCqhXVlvf2WS/rqcUcNupud13/HT98udauhSaF714VInZYebSVedoZec8GzLgPCy+QLW08Z8c/eixr24E2YUCb4jw/D79QLNFfctczjqyV/11oLyE84rXCbormM8hWMpXBoGdOkX6rFsmkQWlJbG7K6nifEVjDBM9hsgq7TyDN5gEw0MOYDiK101PM8jpE/nGTKFiPU6EFJYsGhnemdYC4AeRK3qLQaKJJhnaetdNgtJnvketpEaloA1pnYOobT9TQZTOGodtqZyzqCs43bU2IRZaIBKnZbCv1l31PEEVhDSP5unD1J8JxOsYkZflGvJ1406lXX04HcmLs74DFcZKPR3Jl5vHWGA6EfpPhueFKdHyT0wEvGDMWxhpeXeavi9gG+N43u36lRhi7OnK9iNtIJ5U4uEsGIR3ygFWwGPw7dnJo2IkCr6jjB1KKOs64+lFLhKH/OuEBxNBEWh/Gg8k5E8+Al+itOM/tNjUbHb3s7uj05kRn7qss6TFyNZM8p3n1Hvu17wJAWRcuD5+/+lqDxNDWq7qxmmu3yZsgco56Y6IyxAQvuBsoAEpqgqeg1SYIkoG/N3PVbTXJmYZ0g== 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:(13230001)(366004)(1076003)(2616005)(6486002)(2906002)(6666004)(26005)(86362001)(5660300002)(8936002)(508600001)(54906003)(6916009)(66556008)(38100700002)(186003)(4326008)(8676002)(66476007)(7416002)(52116002)(36756003)(6512007)(38350700002)(66946007)(6506007)(103116003)(83380400001)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2EzjXiQlHgmoS6NBOmtNJdWhWzCVfJHYnTaDyQ9Zukb3rgLoGfiS8AIkLyhAZP+NKcWGXvvz7WH0V2FxUcKBXZcAVwimxiKtHhz7myY68wpEwc5AEfM7GpelLwzf6pV0SwqayzX+D+0IBGPyipNEj5qa2mqvbvj9jIt8mjLhrHKn24ybYdahU1JuLYOeY3D+A2HThK1mwcomp9CU+QOv/4tTbGxCShwxc2hZkegmol9on/GelMmVkc8CGLBZM56mZTqJVTZkG10ZojeoCqf7LPsIIPIeL8xlCoHvOno88NF3gNG01mYvBtoghX58wpOajz6SUPsePcleXspltAc7Vtda/1rb7X78FPKyogHa+VSZjCUDchWrr4GwWHZOO7q+wDzNhvSMnmn1F4I2HDFV+oZ0tWLc7uggcs81sCA4tGxapFcuuksQmlzO5RgV49GtOGqp39z2HXi9xsatXl2/cH1OauFR5kKPRDRbrfUs4VuzppUmmyR7DgVsqz5A4aJzEgP1tsre8SqdT94YQqLngsDe4+pXwvF+QXo/9xMqkyD9tN2j+EBa8g6QwJ50PT8eyXeUfHN6jtoXP5aI4bDkFfb3OX11MAg3cDoM31EFeNjiXXj/Glg1MkEUth8YwF2COzsKX+GKtchxlZZtS8Gc1yHnLgLnm4xBKT/MWMpC9Zd1X7csGul8AOKjTTWoEo4GQBo+i2FEft9jQa8l4vHCGdyc7f1p7LammWwKpCL8c3CoAcCuCD/OSmJwS+Z4XnbMA/1Q8/xhWqOCQHE8KskrxNw0PtT8Gv3TKpWddwtZYEptuxMj9QMRZN7aHUzcbm9DLuTbBuVa13tBp0LnrKGsPzciz+dEJkYxiI35V3df/aYF2XptS1vfLXnsOYU7hVBPjK4OO5hb5sHJC70QVWDi74W06Xu962kUq0/GQLEdH3WhWW4ImxG8hD+d8Z5SwIrhh3fQNq0yBAvmZ67l//sKTYMpBAeM2+JYo2Z6NYv+nhQHruMIynQTE/uqRIjA7E8kFzKMoPqqBkzmi893h0QZiEFE7teAvtHFKjgwn7featGT8fN01QfNEH0whKPvulZC+hJX/uTlgXT6Lv5wHqok1KmMXBIEGqik00oOz34Uts2np3TVXz72gp7H45j1erUE80OH0848CFU8SrnwPuRLJ/KKw9cJK7b9htLOjLm/POvX6KKkAY5LQaKbuhcwh75rBZh94gEstYkwxsMLqr3pFvqmOwbZZnOz9y35OipH64HDHNet83gSpWr5wOi4lAwRLtj21NvFSc/v8HEGABYhPv9Tx1huoI6DeMGAHvB/PT6wMw+Byyn6Cxq3CZkbIvsA3hSrjNL7pUUmMnkDh//kZ1syl4DocOMVuKwKdY6STPwXxlAgMmlGlxThrvUcx+BZLSjpY2OW7Sx+ZV+JaQhZMjwPkrWd5XX2IixpkB9SZobSiGBZvhTgMzLrCnrEiG2Ifhp1MZEHGB338z2qTL2LSooHb4R3qm8q2ib6vps71JdEXuPEJmHoKFqRzsVbH/Z80Oi44DhffchUReBSSM7bYzShX9b/OBHpqImd22LAdM6fx2KcTFb/603WKmGrnyHQPJePcvHgZvQ3Iyl65j3d3NkyzcGMtxaAxcw4DfxnWx3F6imqQ4v6syF29OgRecjt5BaToSwSnxrOeX0Eus4lkqbSbT7xmkuwYxP0pt5loFlpVQ12dvX9c9sDsEHkaWoB4Hk7C7BZQw2j+PAW2p3fqyKZx2NzLVqBnhKmvgMyPYY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a997d9fe-ddd3-4d9d-dfd1-08da1349d957 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2022 19:08:32.8332 (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: g9bd6sMIoOcVEPEEe0xDRRB37FEvIGqZyOFQEJqR2PRUJfe+E43SMWrjF1GBrdddjJwviNBg6DLVLSpYmY9Jjp6N1kIgbfAKIAh3ILPoL6U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR10MB2529 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.850 definitions=2022-03-31_06:2022-03-30,2022-03-31 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203310101 X-Proofpoint-GUID: 8tdz1qk_txRsRJC_kzKDbkC1IrReA91I X-Proofpoint-ORIG-GUID: 8tdz1qk_txRsRJC_kzKDbkC1IrReA91I Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Some callers of __dentry_kill may be killing single dentries, where a cond_resched is not strictly necessary (and may result in undesirable sleeps). Add a check_resched flag so the caller may request that we do not call cond_resched(). Signed-off-by: Stephen Brennan --- fs/dcache.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index 93f4f5ee07bf..b1480433ddc5 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -575,7 +575,7 @@ static inline void dentry_unlist(struct dentry *dentry, struct dentry *parent) } } -static void __dentry_kill(struct dentry *dentry) +static void __dentry_kill(struct dentry *dentry, bool check_resched) { struct dentry *parent = NULL; bool can_free = true; @@ -619,7 +619,8 @@ static void __dentry_kill(struct dentry *dentry) spin_unlock(&dentry->d_lock); if (likely(can_free)) dentry_free(dentry); - cond_resched(); + if (check_resched) + cond_resched(); } static struct dentry *__lock_parent(struct dentry *dentry) @@ -730,7 +731,7 @@ static struct dentry *dentry_kill(struct dentry *dentry) goto slow_positive; } } - __dentry_kill(dentry); + __dentry_kill(dentry, true); return parent; slow_positive: @@ -742,7 +743,7 @@ static struct dentry *dentry_kill(struct dentry *dentry) if (unlikely(dentry->d_lockref.count != 1)) { dentry->d_lockref.count--; } else if (likely(!retain_dentry(dentry))) { - __dentry_kill(dentry); + __dentry_kill(dentry, true); return parent; } /* we are keeping it, after all */ @@ -1109,7 +1110,7 @@ void d_prune_aliases(struct inode *inode) if (!dentry->d_lockref.count) { struct dentry *parent = lock_parent(dentry); if (likely(!dentry->d_lockref.count)) { - __dentry_kill(dentry); + __dentry_kill(dentry, true); dput(parent); goto restart; } @@ -1198,7 +1199,7 @@ void shrink_dentry_list(struct list_head *list) parent = dentry->d_parent; if (parent != dentry) __dput_to_list(parent, list); - __dentry_kill(dentry); + __dentry_kill(dentry, true); } } @@ -1645,7 +1646,7 @@ void shrink_dcache_parent(struct dentry *parent) parent = data.victim->d_parent; if (parent != data.victim) __dput_to_list(parent, &data.dispose); - __dentry_kill(data.victim); + __dentry_kill(data.victim, true); } } if (!list_empty(&data.dispose)) From patchwork Thu Mar 31 19:08:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12797609 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 CA9E5C433EF for ; Thu, 31 Mar 2022 19:09:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239959AbiCaTLK (ORCPT ); Thu, 31 Mar 2022 15:11:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239795AbiCaTLC (ORCPT ); Thu, 31 Mar 2022 15:11:02 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 280CC9969C; Thu, 31 Mar 2022 12:09:15 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22VHe3EU030419; Thu, 31 Mar 2022 19:08:38 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=HY65+16Zps/dpcltFkHOttyuBPjIeHmnz6h8+YBKs9Q=; b=GgP42O5RQvdlDjxelHvqqnmWYYPge9tznksiUWuoerTsTInX2nBmlhuPRNR9LANKmEqj a+gKIZAFn7Ld/JnjtgCmnlOlp4MxGOmfAzITWlRgoh0PtuODjN9+jIPlJsCxw0/Su8cw LNz2hGMJZYJrwKV4CVG/1zVYbx3b83zQqv/IjoKqblng4NwSpPz/6PAOC9M5MB3D5LAn zXurMWymn8OAm8mwmfWYUJn6C+vQQTPjlUzyLEnJC53t9QwaQ4DGOo4vqF78Xd1bVjDO 2PlyxRMC2CRQtkSmwm8zmeUklJRgENc8HhrclC6hSrzXWRiEfi7LPGsla5WDuJ9wLgrk eA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com with ESMTP id 3f1se0n8w2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 31 Mar 2022 19:08:38 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 22VJ0buF011531; Thu, 31 Mar 2022 19:08:36 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3f1s95scqf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 31 Mar 2022 19:08:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lQNXlsVHblyXn9vXJYopw+PieQ9rHp6ErFTQme4dm9Nf/ai6p8Z39KRdbA0d1hmDMXA3w68t+ICAK6+iF28KFiK1Y+KCoZ04b0/y3ZSJvBrAsPbH0g3foBdDIWn920fK+rFxa8mTljAvwTPq172TQnlvzUxn/SoXkyTdeONSkUQXW2VPill1WUrQkKTlJv0Q8KsCNnLEPDdnA6wVocTkdMlR077KNZzLcRdAqDlDfxpjwehF71hLApGcFXBi5+TzJ0pecgnW0vkZg8vfosFNbRlUtkHf2Ex4v+bi9KWWypKVRndLmpgUYnY0+f3l1tlccXIF6vXscBz9rKq2aerlog== 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=HY65+16Zps/dpcltFkHOttyuBPjIeHmnz6h8+YBKs9Q=; b=BfUO/0tSuAjsGvYG8XKyHfMK6NF+VcX595Td77nnn3rHDkKVgCECS/7iJHtfN2r+1VXx+nhhmph9Siim78Bqst/d9dNVJy1NDgqqj47R2ip3yMEwU9O/C+woLY89K+DumTqFvXoKLvfCWLLnM6HJgA2k3a9UEEa1Q6ShQHnrihfc3TEWE+j1KgpO1hot8OVsi8L63sZKBLqJND9RFK+GvtK9B7xLe1MdfNz8vyuCCcdVqZ5+odYmtjvmU1UwHJ3S4DF7t7OhpzHhDuGdpKsRwf+C3SDEh7vMfhum/KVQpPvl7xc6A5TUwOjeCEFlUpL/LAvHfFOYBv1SDLQL4GIeQg== 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=HY65+16Zps/dpcltFkHOttyuBPjIeHmnz6h8+YBKs9Q=; b=ltRIWLTobyv5tkmAhm+ItpzkfdR+MvxDOhxb+lZkwrMHi9e7Z8vf3kSl6seXb850JL90rB4v2tUynGZgnFR7pKBny+KGfrv6pJzlF+vo00LEjNqq79C3cftCC+ZtpvFz78vKpGVYiBsZtSkKYL8/Y4KoA7HtD4hdEpy1nhPGGJ8= Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by BN7PR10MB2529.namprd10.prod.outlook.com (2603:10b6:406:c4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.21; Thu, 31 Mar 2022 19:08:35 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::9ca1:a713:90c3:b5b3]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::9ca1:a713:90c3:b5b3%7]) with mapi id 15.20.5123.021; Thu, 31 Mar 2022 19:08:35 +0000 From: Stephen Brennan To: Alexander Viro Cc: Andrew Morton , Luis Chamberlain , Stephen Brennan , Arnd Bergmann , Matthew Wilcox , James Bottomley , Gao Xiang , Dave Chinner , Roman Gushchin , Colin Walters , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/2] fs/dcache: Add negative-dentry-ratio config Date: Thu, 31 Mar 2022 12:08:27 -0700 Message-Id: <20220331190827.48241-3-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220331190827.48241-1-stephen.s.brennan@oracle.com> References: <20220331190827.48241-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: DM3PR12CA0099.namprd12.prod.outlook.com (2603:10b6:0:55::19) 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: ce6c0000-bf64-4768-a1ae-08da1349daa5 X-MS-TrafficTypeDiagnostic: BN7PR10MB2529:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kZnIwWda2JX6SUbLQooB2zsw6n6vuk1tB0uTafBtjZyS/hMASfKGSmYVFQAOFyfe0NPyr/RpqkzEz5WNTbDYt5z5AkYuHhfN8FCa8U99AUZ6g+zNTI8uUvPxUlyjR+m/aan7WEOWkAg9dmiFbx48/yfHwdUW8DH2nmCOWF0s+Z9fLxBvFbJrYtJkPdKSIwtNjsqu3vuzY1VN3kbYB/YoC9QlkvcsAyhuaYj8jp+/P2l7DyiJm+ISlPxuzAPkaGNoJ1zcIKPZ+2s179zUL7pcWxFBqiZXZKOJF9VD7x1DaLQM+3ndxFsNpk3noEl3MlwY8Qv7eaHGtsThmPXrutQhC3TwpCqByd7FwQmKL1F/jUy986e51uctx08d/L62ba+uqITMZQbeLmrAy9tu4Dy11XEnSeeW5AOZCyMv2jKLGhODKhnxNubEn0wu0G4WAVR/q884I6ZCUHi95rw/J+Hu6w2ivzfpw7xk5NFJDhe26LhcW5GdKk91xQDKwxeryKtN1/uPGmgD1wjzuAdlxEA891s8CyTt1L/DB5R/SqYjoESjg1j99c4IqQmZJaYfR0YTQm9SuRcYSNPHQAvvpV6VbiTZpYwuU5phH3WZDTIRoM9OQ4TNYDhGMb9Rsqr+wBDkb+6YBOfO+S/O+ln3iUP9lSBOLFXXZfOh8C3Iei4QCns+Lc2kmo092r68W2LAbubxxZtVU7bUiH6JPmlTIb6R5g== 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:(13230001)(366004)(1076003)(2616005)(6486002)(2906002)(6666004)(26005)(86362001)(5660300002)(8936002)(508600001)(54906003)(6916009)(66556008)(38100700002)(186003)(4326008)(8676002)(66476007)(7416002)(52116002)(36756003)(6512007)(38350700002)(66946007)(6506007)(103116003)(83380400001)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Hb+Up24J4Ph414XkWMH3Pi8ZQyjCeGF6bxWLN/PTz37owc3zRJagypnVEpRLeJUIf49CXW7G9mEwx2FkGV3chc9lNHrFj+IyTY97B9EheSPXmAcxGz69SaYhE05OOGei2xTEC4zPghCOA4FJ7F6VoTUZsdrzlx7hRI3aIjjCkcCZc2ounkc8pVnTu04qKXlkvmVaHN9aSm7vMjzcJkNThzXNBq92h8jeXSaLTG3zy7tBtXVycWTM1C9meNcOZgl7u1btDepAUzERsv5PK56C571zQfqOMruoYCiuLj4l0LXMOny0U0QM/uEceN2rqSpeigAhvpLh3r6dg0xaL77HvSvYifTvUxfQFoAkUTlLvZcEAEDlPO8U/fOb5E8/JwzN8IkN0cp4UbaJs2DfiAcCny28Chci+yrxvVSR5NcV8g7CwY4BfHXGAPHIS0WQQrwLKYupJqawXssPasmGLffWra4zGtLHQ0JxZ0IK7iUnKS6G9M+yKd9M+EnC0bzXao6u3lmaARsTDo9g6WNfDXTbHFBXZFdWpVmuHeJ2Lu7dkvFZGUKnOwNMX/eeRNaEnM3pFgx9ORg1WUt7m3PEaxfJUw/XfrJWx3YYwhYE9nLxDwuTrzk6PWVyGo3ZkOsonMVYfsOm+80JsUdy8k0RyWrivKUE73FJKyrK7k0g3/DSsreVPRag4FelywBAV+cuapVrWjjESe+g11LPGQJaAj7F5Oo4Sq0xUnPD/+HkAkem8ABK7PP8zKeifdS2if+sC5ijYESsFt1iJQv1r5uvzzR1sGwL9xNJKadyoraw16OO1CVY6G89N4kQ45/kWJDwiXrkdbI+UggVO1++Wa4mlUGFeBU/SbJbeZ2d3r/EsGgn26WmwDV+1trwEmY90Bf1UOABTgx45xRYdXg1gbpSLAp/Qehpc+vPJcQvMRV0k7Z7aANt1kVV9L1evEdbFF7j0zHY0eUR/CiUD/EtR472l3U/w0ulsZc+1Doustzszk19ZFBZqjDK2Lj3xzlIzvOpBxpXsxzTOCgYHukR0Rd5z9Rj5Gp+IXe3Ohhkdt/EMbppS5muHmgizV3wt+wRSbqaAqCZqlgnunyp5DERW1lpEuhcBCs/S+CpCQRDCTM9PkZD7JouIJ6vFiEx/lzdXqamFbLWnWxAPTfOvpq9g0pId8dds2gAzr3bJlppnl1VWJ38nvqeZmjwVKlgGhejGOjFCS+TS1vH1rNGaStzN0lptpJLfazT2dBZlOwI057DdZZ4Jq6O0SEc9/E98iqYy2au+yWuphgCM+Av8JXPMZvGMoopcPgONuYoi69tDNZi2c0/uNaFOPxgDnUmpb7WkXL3YH1jCVHirfAVNwQIXPouDCJN+Tju7Q+GoZAA5kyI8QSuc6uXZmhsCOmoYR9dAOLOTb+E9UOJYQoFRYgH61bG4XwmYRNIjxjCIgD75HqwLoxZQMHbxYYGVPD4InOWdCOM2c+N+0P9nnWNBvslbXCYwNV3q+lZwe9fqPGLTREHNUzXPvULbqNZzDmtYOD7/jlKWfU7s7DFnkB+in5NlvDgkYSFLHjvi1P+gYQPsDljkypmuupha2Y8ZmHoFO6f9xr4K8hvY7x9FLkmUOK9K9QGXsVoDkJ5lessbg0t/yrEGqONKaJk5qdcF4FRuqdHX1mh2Y2EgCZwl4DIC/7hl3jVAXKnDAJO5DxesRzf0NJhqE98A8PZTLpoG5kmuspYRdahYclZdiQPHpimL0qgQQOHkjwVZknE0MbBd1TrKhuoJkRMpnZUTI2JZHWHmraiwIqnz5K7 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce6c0000-bf64-4768-a1ae-08da1349daa5 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2022 19:08:34.9593 (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: 1HVHPhFj79M3upF1efxMvsivrd6nbFy8vGWyTptf0rC806fMvvPvIvTMSoRMoIhwLCH/h5n0AIm1JksVn+WGH7WsmMF8UAFu8o7Oc18fq0Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR10MB2529 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.850 definitions=2022-03-31_06:2022-03-30,2022-03-31 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=879 phishscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203310101 X-Proofpoint-ORIG-GUID: U6JdAxqeR-t9LuZT6f0emTAdR0k2KZaA X-Proofpoint-GUID: U6JdAxqeR-t9LuZT6f0emTAdR0k2KZaA Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Negative dentry bloat is a well-known problem. For systems without memory pressure, some workloads (like repeated stat calls) can create an unbounded amount of negative dentries quite quickly. In the best case, these dentries could speed up a subsequent name lookup, but in the worst case, they are never used and their memory never freed. While systems without memory pressure may not need that memory for other purposes, negative dentry bloat can have other side-effects, such as soft lockups when traversing the d_subdirs list or general slowness with managing them. It is a good idea to have some sort of mechanism for controlling negative dentries, even outside memory pressure. This patch attempts to do so in a fair way. Workloads which create many negative dentries must create many dentries, or convert dentries from positive to negative. Thus, negative dentry management is best done during these same operations, as it will amortize its cost, and distribute the cost to the perpetrators of the dentry bloat. We introduce a sysctl "negative-dentry-ratio" which sets a maximum number of negative dentries per positive dentry, N:1. When a dentry is created or unlinked, the next N+1 dentries of the parent are scanned. If no positive dentries are found, then a candidate negative dentry is killed. Signed-off-by: Stephen Brennan --- fs/dcache.c | 93 +++++++++++++++++++++++++++++++++++++++++- include/linux/dcache.h | 1 + 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/fs/dcache.c b/fs/dcache.c index b1480433ddc5..ba79107a8268 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -74,6 +74,8 @@ int sysctl_vfs_cache_pressure __read_mostly = 100; EXPORT_SYMBOL_GPL(sysctl_vfs_cache_pressure); +unsigned int sysctl_negative_dentry_ratio = 5; + __cacheline_aligned_in_smp DEFINE_SEQLOCK(rename_lock); EXPORT_SYMBOL(rename_lock); @@ -183,6 +185,7 @@ static int proc_nr_dentry(struct ctl_table *table, int write, void *buffer, return proc_doulongvec_minmax(table, write, buffer, lenp, ppos); } +const unsigned int max_negative_dentry_ratio = 20; static struct ctl_table fs_dcache_sysctls[] = { { .procname = "dentry-state", @@ -191,6 +194,15 @@ static struct ctl_table fs_dcache_sysctls[] = { .mode = 0444, .proc_handler = proc_nr_dentry, }, + { + .procname = "negative-dentry-ratio", + .data = &sysctl_negative_dentry_ratio, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_douintvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = (void *)&max_negative_dentry_ratio, + }, { } }; @@ -547,6 +559,8 @@ static inline void dentry_unlist(struct dentry *dentry, struct dentry *parent) dentry->d_flags |= DCACHE_DENTRY_KILLED; if (unlikely(list_empty(&dentry->d_child))) return; + if (!IS_ROOT(dentry) && unlikely(dentry->d_parent->d_scan_cursor == &dentry->d_child)) + dentry->d_parent->d_scan_cursor = dentry->d_child.next; __list_del_entry(&dentry->d_child); /* * Cursors can move around the list of children. While we'd been @@ -1751,6 +1765,71 @@ void d_invalidate(struct dentry *dentry) } EXPORT_SYMBOL(d_invalidate); +/** + * Enforce a requirement that a directory never contains more than N negative + * dentries per positive dentry. Scan N + 1 dentries. If no positive dentries + * are found, then kill one negative dentry. parent's lock must be held, and it + * will be released by this function. + */ +static void dentry_incremental_scan(struct dentry *parent) +{ + struct dentry *dentry, *candidate = NULL; + struct list_head *cursor, *start; + unsigned int flags; + int refcount; + int nr_to_scan = sysctl_negative_dentry_ratio + 1; + int nr_positive = 0; + + if (nr_to_scan == 1) + goto out_unlock; + + cursor = start = parent->d_scan_cursor ?: parent->d_subdirs.next; + + rcu_read_lock(); + while (nr_to_scan--) { + if (cursor == &parent->d_subdirs) + goto next; + dentry = container_of(cursor, struct dentry, d_child); + flags = READ_ONCE(dentry->d_flags); + refcount = READ_ONCE(dentry->d_lockref.count); + if (d_flags_negative(flags)) { + if (!refcount && !dentry->d_inode && !candidate) + candidate = dentry; + } else { + nr_positive++; + } + next: + cursor = cursor->next; + if (cursor == start) { + rcu_read_unlock(); + goto out_unlock; + } + } + + parent->d_scan_cursor = cursor; + if (nr_positive || !candidate) { + rcu_read_unlock(); + goto out_unlock; + } + + spin_lock(&candidate->d_lock); + rcu_read_unlock(); + + /* Need to re-read candidate's flags and inode. */ + if (!d_is_negative(candidate) || candidate->d_inode || + candidate->d_lockref.count) { + spin_unlock(&candidate->d_lock); + goto out_unlock; + } + /* No need to cond_resched(); we're not repeating this operation */ + __dentry_kill(candidate, false); + /* parent->d_lock is now unlocked */ + return; + +out_unlock: + spin_unlock(&parent->d_lock); +} + /** * __d_alloc - allocate a dcache entry * @sb: filesystem it will belong to @@ -1814,6 +1893,7 @@ static struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) dentry->d_sb = sb; dentry->d_op = NULL; dentry->d_fsdata = NULL; + dentry->d_scan_cursor = NULL; INIT_HLIST_BL_NODE(&dentry->d_hash); INIT_LIST_HEAD(&dentry->d_lru); INIT_LIST_HEAD(&dentry->d_subdirs); @@ -1858,7 +1938,7 @@ struct dentry *d_alloc(struct dentry * parent, const struct qstr *name) __dget_dlock(parent); dentry->d_parent = parent; list_add(&dentry->d_child, &parent->d_subdirs); - spin_unlock(&parent->d_lock); + dentry_incremental_scan(parent); /* unlocks parent */ return dentry; } @@ -2521,6 +2601,7 @@ EXPORT_SYMBOL(d_hash_and_lookup); void d_delete(struct dentry * dentry) { struct inode *inode = dentry->d_inode; + struct dentry *parent = NULL; spin_lock(&inode->i_lock); spin_lock(&dentry->d_lock); @@ -2529,7 +2610,17 @@ void d_delete(struct dentry * dentry) */ if (dentry->d_lockref.count == 1) { dentry->d_flags &= ~DCACHE_CANT_MOUNT; + if (!IS_ROOT(dentry)) + parent = dentry->d_parent; dentry_unlink_inode(dentry); + /* + * Since we have created a negative dentry, continue the + * incremental scan to keep enforcing negative dentry ratio. + */ + if (parent) { + spin_lock(&parent->d_lock); + dentry_incremental_scan(parent); /* unlocks parent */ + } } else { __d_drop(dentry); spin_unlock(&dentry->d_lock); diff --git a/include/linux/dcache.h b/include/linux/dcache.h index f5bba51480b2..59c240d8c493 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -102,6 +102,7 @@ struct dentry { }; struct list_head d_child; /* child of parent list */ struct list_head d_subdirs; /* our children */ + struct list_head *d_scan_cursor; /* * d_alias and d_rcu can share memory */