Skip to content

Commit a731763

Browse files
YuKuai-huaweiaxboe
authored andcommitted
blk-cgroup: prevent rcu_sched detected stalls warnings while iterating blkgs
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 <yukuai3@huawei.com> Acked-by: Tejun Heo <tj@kernel.org> Link: https://lore.kernel.org/r/20210707015649.1929797-1-yukuai3@huawei.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent d80c228 commit a731763

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

block/blk-cgroup.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ static LIST_HEAD(all_blkcgs); /* protected by blkcg_pol_mutex */
5656
bool blkcg_debug_stats = false;
5757
static struct workqueue_struct *blkcg_punt_bio_wq;
5858

59+
#define BLKG_DESTROY_BATCH_SIZE 64
60+
5961
static bool blkcg_policy_enabled(struct request_queue *q,
6062
const struct blkcg_policy *pol)
6163
{
@@ -422,14 +424,27 @@ static void blkg_destroy(struct blkcg_gq *blkg)
422424
static void blkg_destroy_all(struct request_queue *q)
423425
{
424426
struct blkcg_gq *blkg, *n;
427+
int count = BLKG_DESTROY_BATCH_SIZE;
425428

429+
restart:
426430
spin_lock_irq(&q->queue_lock);
427431
list_for_each_entry_safe(blkg, n, &q->blkg_list, q_node) {
428432
struct blkcg *blkcg = blkg->blkcg;
429433

430434
spin_lock(&blkcg->lock);
431435
blkg_destroy(blkg);
432436
spin_unlock(&blkcg->lock);
437+
438+
/*
439+
* in order to avoid holding the spin lock for too long, release
440+
* it when a batch of blkgs are destroyed.
441+
*/
442+
if (!(--count)) {
443+
count = BLKG_DESTROY_BATCH_SIZE;
444+
spin_unlock_irq(&q->queue_lock);
445+
cond_resched();
446+
goto restart;
447+
}
433448
}
434449

435450
q->root_blkg = NULL;

0 commit comments

Comments
 (0)