Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp5135690pxv; Tue, 6 Jul 2021 18:49:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw61a1WzGkREJ+3Vn3nGBAj3btZkNvtr1wfAUSY/sZlZLgbossG3s8PoKoLwV47824Z6BQE X-Received: by 2002:a05:6e02:1e03:: with SMTP id g3mr16336952ila.248.1625622544311; Tue, 06 Jul 2021 18:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625622544; cv=none; d=google.com; s=arc-20160816; b=mEswmN7uEF1FxxP/WCM5IcppVwPBDRhkHCfG2HfMJFS8YUuG7CgnhGQ3yGp+Pn7zCG TeaalPr1EY5is6tb+utouQMHeImQQ9MJO7e+uJ34pEIsgNSbsf6AoYgMOaznxHOp/bq7 Mz13Ak7pmrzbjLQIQIoUkSIB+OFlAL8T0i8Vgn81+0kQ7Tgz/cmThhWOz7S6aC6Xkybq WjOUEOq9n1I4XXv4VGici8UGjI9qll6dCgAa/QmXahZ/beLtuFvWJCN2m5GJeZvGFHRt 8MYnBjzWulQEDpDSYJJXA0i4xvBD41FSJnen3G2aixW99lpCs+obMVMzitN19rIOQ9r2 56Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=E+hUN2ssaonD95P4achUH+W/4p8NzE5YGKEvsNVWspE=; b=bxgE6JKzKHOrdOov5vv5GDm3HBSyEYHZ0EAdSB6x86TvxdzcIfCxpeMIHbQsrzsUWH OgTn4Zl9HjN9goDPAttVrYfMvRX6XDRBMAy2tn2o4bZ5bBXUEgeu9YiQ94rNSexNGWJj WHUYqs7hvK/fJklra4t619Efap366FfBaO1Ql0r7cZ9vE8FTrlNpn9c64lpzTWqfMASk zTxSxSp1dKUL0iylrYfxqhp5DkCuhxS955Bbvu9AhFGR4LUZ91GPuiOsarQjRFLTL8ys iiQ8aM7fDgW4CTaUN89qDYaSuneZSSr9mdsQNxTtfTZcGt9FJKExI7gPN7A3GPKUs2Bm xc5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v17si2004151ilo.17.2021.07.06.18.48.52; Tue, 06 Jul 2021 18:49:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230002AbhGGBvF (ORCPT + 99 others); Tue, 6 Jul 2021 21:51:05 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:6433 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229949AbhGGBvF (ORCPT ); Tue, 6 Jul 2021 21:51:05 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GKMgD5pGQz76qf; Wed, 7 Jul 2021 09:44:56 +0800 (CST) Received: from dggema762-chm.china.huawei.com (10.1.198.204) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Wed, 7 Jul 2021 09:48:23 +0800 Received: from huawei.com (10.175.127.227) by dggema762-chm.china.huawei.com (10.1.198.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Wed, 7 Jul 2021 09:48:23 +0800 From: Yu Kuai To: , CC: , , , , Subject: [PATCH V2] blk-cgroup: prevent rcu_sched detected stalls warnings while iterating blkgs Date: Wed, 7 Jul 2021 09:56:49 +0800 Message-ID: <20210707015649.1929797-1-yukuai3@huawei.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggema762-chm.china.huawei.com (10.1.198.204) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We run a test that create millions of cgroups and blkgs, and then trigger blkg_destroy_all(). blkg_destroy_all() will hold spin lock for a long time in such situation. Thus release the lock when a batch of blkgs are destroyed. blkcg_activate_policy() and blkcg_deactivate_policy() might have the same problem, however, as they are basically only called from module init/exit paths, let's leave them alone for now. Signed-off-by: Yu Kuai --- changes in V2: - as suggested by Tejun, rename 'BLKG_DESTROY_BATCH_SIZE' and modify blkg_destroy_all() only. block/blk-cgroup.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index 7b06a5fa3cac..575d7a2e7203 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -56,6 +56,8 @@ static LIST_HEAD(all_blkcgs); /* protected by blkcg_pol_mutex */ bool blkcg_debug_stats = false; static struct workqueue_struct *blkcg_punt_bio_wq; +#define BLKG_DESTROY_BATCH_SIZE 64 + static bool blkcg_policy_enabled(struct request_queue *q, const struct blkcg_policy *pol) { @@ -422,7 +424,9 @@ static void blkg_destroy(struct blkcg_gq *blkg) static void blkg_destroy_all(struct request_queue *q) { struct blkcg_gq *blkg, *n; + int count = BLKG_DESTROY_BATCH_SIZE; +restart: spin_lock_irq(&q->queue_lock); list_for_each_entry_safe(blkg, n, &q->blkg_list, q_node) { struct blkcg *blkcg = blkg->blkcg; @@ -430,6 +434,17 @@ static void blkg_destroy_all(struct request_queue *q) spin_lock(&blkcg->lock); blkg_destroy(blkg); spin_unlock(&blkcg->lock); + + /* + * in order to avoid holding the spin lock for too long, release + * it when a batch of blkgs are destroyed. + */ + if (!(--count)) { + count = BLKG_DESTROY_BATCH_SIZE; + spin_unlock_irq(&q->queue_lock); + cond_resched(); + goto restart; + } } q->root_blkg = NULL; -- 2.31.1