Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp130295rwb; Mon, 26 Sep 2022 10:09:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ngxS2PsQZPLDDO47f6vtMo6SnCj9o/YnJI/iSnEep3f0lm1KXiTcx18hkW3zonBNVIME4 X-Received: by 2002:a50:a69d:0:b0:44e:bf40:395f with SMTP id e29-20020a50a69d000000b0044ebf40395fmr23296280edc.234.1664212174490; Mon, 26 Sep 2022 10:09:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1664212174; cv=pass; d=google.com; s=arc-20160816; b=0OL4somqLZUP3U6r3EVPDVMEHjiSnjcQNmZWmWuQZh1lFCzQ4aW/vntP2BHrV7omgY n7nnDMNOoEZypgv8iykSsyb2Xe3svWazu8kCgVkNsEaVRw0uuXoMR8G2lSugHFPY+jJ/ 6CrrnOGGl25eV76ZoFw4wPxFNVFelRoVk5nsARNABYYEvUxjZCtFMy4hihWGsSf5arPL ng3dt4xA8q+rauMtGEmeFFXrbk4RVlX1HRpjkHmJPumECuOBs9WqgrERI1zzGyZBIv2z Ez1Cd6+YptBLcxf+HusgW+GXdoli/pLL5AwMf6a9WvbfCknfAM4r9HP8ICv+RMKjT7iG aGQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=7PL/uBUVms+9QzCyE0OfwlVY6EVEcFls0NjAu923kx8=; b=nOSXgxI2DqXeA9/3c/m+8MiHfyRrwOtbxdSZSysKrMEKo6eIOdWNiEgUHf4JjAY5yC OjoEp/gtkRH4T0jyBo3EX5L25m+9ZAySl6GK4suWWp3k8BeBM3BOK/3HDTp1s3Ni6dcB E75YB9o46jqew/Hg8fAiMVZJwVlh3BVyxipOs9IwBeXPwymMoLalmBD2FmuOn0hlxxml 5IBPVPl++cP9EuDUqIK7XX3P8iciVjS+qONpM1WpW4cYLatVsicCMVjg28ZvT8vwXtcv /LiauD2r8katY00cxCUSZM93alrvZrd7y0mWABcURfTRzdnbWIAjpi5aD/33eKuzR4+Q pBzQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=CQfp5sUw; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp37-20020a1709071b2500b007313314bb73si406126ejc.806.2022.09.26.10.09.08; Mon, 26 Sep 2022 10:09:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=CQfp5sUw; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233205AbiIZQOG (ORCPT + 99 others); Mon, 26 Sep 2022 12:14:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236252AbiIZQNH (ORCPT ); Mon, 26 Sep 2022 12:13:07 -0400 Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01olkn2055.outbound.protection.outlook.com [40.92.99.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C77F39123; Mon, 26 Sep 2022 08:01:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QmLZUD0cXhQ25HVCwKJyubrkC7WvYuAkLhQolpx4R3Uxke/Bpyg4xNkTAhcGaZMFpQc7cjgv7J3pJmZNVNm0YEZJm51x3gXBKV4ulGtDYqtc4GctwhMICkRv387YZ7cNPEQMEX/48la0QJtr2g9M2VE0jutFcUDnF0ssTiLH3YEM3jL1/y8QdCiqyAKBvhIKWCfhhxgWloMdOyy4NkfI0rQbT7G/DvhaSirWLBt6gnqQzso+iAAQ9R3JHj65qeuyUFj94erUHehu5k6DmHvyWkzUKECms7xbnrZNitGPGAD1wS61OHJ+V1Ysl2ojzIyUbF7KZBvs2IARQoJAy1kZqQ== 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=7PL/uBUVms+9QzCyE0OfwlVY6EVEcFls0NjAu923kx8=; b=i35OnqZCU5pj7E1gEzeriUuAL4NkB5drygNm3AuTB4/EOORIeNrJ6pwqnAfjBesqXKyi/lTobw+vhZKsWW7kTnMzhVnVQPkNBT3Hd5ggnN92SzcRzuCKzkhDmamAD9s5hsz5JBSnU3tqH03keVp/U9CIBZPdRPwvCKOFtu04KifENqmGv6HvG4ZjVvDB7mLB1Y5+JmY6lO7Sx8SiYJDhfyddUtYlDfY7AyDtFFFV4tESamWgJuCmM5BJ4GXqWooZKZi91+Z4wIaOdcJNJTWFbKXEA95nbrmz0cjJ3OTo+uj3Iqo6bpBNTZwLXQFvwkxHSqVyTnwQncKDfM/AzJuo/A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7PL/uBUVms+9QzCyE0OfwlVY6EVEcFls0NjAu923kx8=; b=CQfp5sUwnSnsT6Qe+LvLVDzInw17lx4r1oeMrgEGvYST6xBwFRr4lGW/cSd3lKKQAeHr56dNDJ9wykv0ZyW4PuAiNFFHTlCZnybLySLpp+GfPXwip7jjQ4FGlN+TmosejiYLdBBVz1fgrk9Yk7r99roUz9yyasBcUWkq+kwfA+7dMcCdwdYdkv4G6+IjdTUQlJqbEBDDSICfFP+x7auiZ9a4qYWjpmAEJvVPycazU4Cs/8pZXAs5kpVlG53AWsOf6GOMm9HiX3La1Ozoqwim4YDAlQQcupSdrjzkivo+0FSoUFElxZ4suuIqaPdfkT4J5rPfN1ypYZbZAMct2Dfu9g== Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) by TY3P286MB2627.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:252::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.14; Mon, 26 Sep 2022 15:01:47 +0000 Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::f093:ab8c:7e3:f312]) by TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::f093:ab8c:7e3:f312%4]) with mapi id 15.20.5654.025; Mon, 26 Sep 2022 15:01:47 +0000 From: Dawei Li To: colyli@suse.de, kent.overstreet@gmail.com Cc: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, Dawei Li Subject: [PATCH] bcache: improve race performance of closure debug by rcu Date: Mon, 26 Sep 2022 23:01:18 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [GEpU/+jqBe3ONKgB2AJD+PnffGJUhm4b] X-ClientProxiedBy: SI1PR02CA0041.apcprd02.prod.outlook.com (2603:1096:4:1f6::18) To TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) X-Microsoft-Original-Message-ID: <20220926150118.937036-1-set_pte_at@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCP286MB2323:EE_|TY3P286MB2627:EE_ X-MS-Office365-Filtering-Correlation-Id: aa2510b0-9fdf-4096-cdfc-08da9fd00892 X-MS-Exchange-SLBlob-MailProps: dx7TrgQSB6eMXPOMmUb6UNBfYDG/cmLPbviPIoBhI1zh1SMo4Bs3NYN8QJDsk6eO0MFo/RLG5Oso98zcPoDRD8GNF2Pp2lgY/IjIPxQuJHW3cnqw/4OHnhwjoSRgOBkc8jAEyei80FnhDhtwXBpJgSnwmxaliWcWwTR/B9Y7dVZzq0b/qXU23KUtfVey9z4GkdNgyxDN4uRrxQ1dAk/mGUrppWazA2NXRIJSPT1Qd1WWUzDAozSMjvsUua4BTVK3lxYIFffyL89Xdsh6t4axUSXCoI01YNVKLeA7ZGUjx2rrnHjWSOtKXk7jpg9HVpO69IbTgRjQe0HFpkAw9mlJVj/X0O997zOZLiGHZkd00H8QnNglcx85/wuiQvYmF4yb6MQZvlwybje88xjurS0krlLPdarOw/J0KSVHc2H9nTYzG5qibRI+7RN36u/P/b37pKRzAeUsgV1dbgKXGDCXN2S6ugcsnX/MK/vk2YEiXRaPOeL8B0WhNsUFv1gwl6VqkKspHgvFnxYy36qFa1ytZV5ANnpSBkTCVbawC62hUuStUh6QoR3JI2WvqWiPJyNjM8qNciUfhgBRQCaCMdMYgkkOY1jDaS6UIGbmUZOTTBkmZlEc9bVat80goYIGKzWVOlD91tj4g8hLmDQARbxfzOnfi4Q4TKNHwpWq7qvUwlvTPMb6LLA6tlSNhWWcUpM8tsr9RVHSHAMtQaQ37vLxR47JyErNDLfLUGERMyNF9228qVTf86lMS+D671xgFqRx52p4Rfhdg88= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kbSX9q4vl2eo8yviE3z+8ve+P4zGJOdoOFr5/GKTMfaIkiPBgFSPm1KIGD2AYfzV3Z+H6RPCgozGYDo5uImQjPyYwjiejqKrWpnGnTu4QKyWyLY1J05R7omLcoZ3o5Py7pi+I1rrCG9d9ncgrkcDA5u+5IWT9R9RO9NzL42k+f2Les2F0mP7QojHFOElDzs/n8TvlYFD4scljpmaYb00DLWNRxHuOQHcCjU029ibGIWd7TpmYWuq6wQZZ775MsRnpdKga3IGC1KFFXSjZs9maDjJzBVKhcNViRdJIjkfTDnjUfK8rtCBjqd9ufcuixiXel+cDiydjllE0FMilqwE7hMM7QaZXmUKPgkFFcqN+OzFSiWd5HpX5mbz7eG+bx9iWrXENofTXGMkuRPoiP4cyfLvRHk/VmnQMWH6hHqDimyfnfoKhAjGlye/WMyJyS1kodajah3eawB6mVnxT8IFjsEgekcToiX+rcDGtKqjPZQxU3AUm/IaxJ6hHVpdFmw8LWOc3NfSdbzWFHuqcmzzOobhbY2lWQ+y7RU3g8OfAH2/fvCAgMWY6q1UZEklFRXxVxylTXeJiak9zNR9KsdbNMHcE4h/YKIJM1r8E+P3poDG4HkSHAes2AnDIuSQv3hF X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?HgfMjepfjCoEnipQl7a10OzeSHFrlVuKuzIrsBvWiBt31hpU5k5algqDyiFW?= =?us-ascii?Q?mxxOm3N+nPDrfdBiqYzq3nIiG3grW0acxbK5mj8JS3VnRpgDUbymxtZro2Q4?= =?us-ascii?Q?jiNSqZGT+V7s+40tWAC15ksxXsTAoz/Dvi69c/sWaKExSGVGNlfumJU5BrJC?= =?us-ascii?Q?f1noFjUHY43cVDH/9m/vS4nERYSLxoSqNnCGd1s13ZjF1xYuTSaDe/W/SzVT?= =?us-ascii?Q?MegCVROSQ6tcp8wbg9UeLd3KMq9BX84tHEmbmuL6kzdcgCNpkWkE51G7EFf9?= =?us-ascii?Q?MKqO4h0xBS6GJkjFfyQBzyMjX6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q?ZWYuBRKWyqEzd6trPnm30vV/sZo7jTgPMh5q57Roqhmqb5PN7aUTQ3ewUIbF?= =?us-ascii?Q?/+CLjqUpt+87LJBMyeek8+aXXlHgPB+VmT+6Esn6Gw=3D=3D?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: aa2510b0-9fdf-4096-cdfc-08da9fd00892 X-MS-Exchange-CrossTenant-AuthSource: TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2022 15:01:47.5023 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY3P286MB2627 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Closure debug system implements a closure list which is shared between readers and writers, and a spinlock protecting the concurrency access on it, which means that all readers and writers are mutual-exclusive, which brings overhead to performance. A rcu-based lock is introduced to solve the problem. Signed-off-by: Dawei Li --- drivers/md/bcache/closure.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/md/bcache/closure.c b/drivers/md/bcache/closure.c index d8d9394a6beb..b019d6338589 100644 --- a/drivers/md/bcache/closure.c +++ b/drivers/md/bcache/closure.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "closure.h" @@ -141,7 +142,7 @@ void closure_debug_create(struct closure *cl) cl->magic = CLOSURE_MAGIC_ALIVE; spin_lock_irqsave(&closure_list_lock, flags); - list_add(&cl->all, &closure_list); + list_add_rcu(&cl->all, &closure_list); spin_unlock_irqrestore(&closure_list_lock, flags); } @@ -153,7 +154,7 @@ void closure_debug_destroy(struct closure *cl) cl->magic = CLOSURE_MAGIC_DEAD; spin_lock_irqsave(&closure_list_lock, flags); - list_del(&cl->all); + list_del_rcu(&cl->all); spin_unlock_irqrestore(&closure_list_lock, flags); } @@ -163,9 +164,9 @@ static int debug_show(struct seq_file *f, void *data) { struct closure *cl; - spin_lock_irq(&closure_list_lock); + rcu_read_lock(); - list_for_each_entry(cl, &closure_list, all) { + list_for_each_entry_rcu(cl, &closure_list, all) { int r = atomic_read(&cl->remaining); seq_printf(f, "%p: %pS -> %pS p %p r %i ", @@ -184,7 +185,8 @@ static int debug_show(struct seq_file *f, void *data) seq_printf(f, "\n"); } - spin_unlock_irq(&closure_list_lock); + rcu_read_unlock(); + return 0; } -- 2.25.1