Skip to content

Commit f255c19

Browse files
krisman-at-collaboraaxboe
authored andcommitted
blk-cgroup: Pre-allocate tree node on blkg_conf_prep
Similarly to commit 457e490 ("blkcg: allocate struct blkcg_gq outside request queue spinlock"), blkg_create can also trigger occasional -ENOMEM failures at the radix insertion because any allocation inside blkg_create has to be non-blocking, making it more likely to fail. This causes trouble for userspace tools trying to configure io weights who need to deal with this condition. This patch reduces the occurrence of -ENOMEMs on this path by preloading the radix tree element on a GFP_KERNEL context, such that we guarantee the later non-blocking insertion won't fail. A similar solution exists in blkcg_init_queue for the same situation. Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 52abfcb commit f255c19

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎block/blk-cgroup.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,14 +657,20 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
657657
goto fail;
658658
}
659659

660+
if (radix_tree_preload(GFP_KERNEL)) {
661+
blkg_free(new_blkg);
662+
ret = -ENOMEM;
663+
goto fail;
664+
}
665+
660666
rcu_read_lock();
661667
spin_lock_irq(&q->queue_lock);
662668

663669
blkg = blkg_lookup_check(pos, pol, q);
664670
if (IS_ERR(blkg)) {
665671
ret = PTR_ERR(blkg);
666672
blkg_free(new_blkg);
667-
goto fail_unlock;
673+
goto fail_preloaded;
668674
}
669675

670676
if (blkg) {
@@ -673,10 +679,12 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
673679
blkg = blkg_create(pos, q, new_blkg);
674680
if (IS_ERR(blkg)) {
675681
ret = PTR_ERR(blkg);
676-
goto fail_unlock;
682+
goto fail_preloaded;
677683
}
678684
}
679685

686+
radix_tree_preload_end();
687+
680688
if (pos == blkcg)
681689
goto success;
682690
}
@@ -686,6 +694,8 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
686694
ctx->body = input;
687695
return 0;
688696

697+
fail_preloaded:
698+
radix_tree_preload_end();
689699
fail_unlock:
690700
spin_unlock_irq(&q->queue_lock);
691701
rcu_read_unlock();

0 commit comments

Comments
 (0)