From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: [PATCH AUTOSEL 5.4 12/24] blk-cgroup: Pre-allocate tree node on blkg_conf_prep Date: Mon, 2 Nov 2020 20:19:55 -0500 Message-ID: <20201103012007.183429-12-sashal@kernel.org> References: <20201103012007.183429-1-sashal@kernel.org> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604366423; bh=hdqDq+TaiDRElSCvu1+PkOkwPfGZkN6dKoBDHWd73AM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oK5rhnY4GRXRBQcn4eTdojpn9k7/+q2lM8+ZhdDVgjQk7Te6Ik1Wz5Vi5aOUKUxXJ Hk4aUGg4eN1H33RsdF9TJYnL184+qyUsofGnECFjwj2w1FlF99xz8/FrpuZEyAzmVS ikC/fEaL4BFN7YP9hTZTSXAf5no4uROJH0tI6kBI= In-Reply-To: <20201103012007.183429-1-sashal-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> List-ID: Content-Type: text/plain; charset="us-ascii" To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: Gabriel Krisman Bertazi , Tejun Heo , Jens Axboe , Sasha Levin , cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-block-u79uwXL29TY76Z2rM5mHXA@public.gmane.org From: Gabriel Krisman Bertazi [ Upstream commit f255c19b3ab46d3cad3b1b2e1036f4c926cb1d0c ] Similarly to commit 457e490f2b741 ("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 Signed-off-by: Gabriel Krisman Bertazi Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-cgroup.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index a4793cfb68f28..3d34ac02d76ef 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -855,6 +855,12 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, goto fail; } + if (radix_tree_preload(GFP_KERNEL)) { + blkg_free(new_blkg); + ret = -ENOMEM; + goto fail; + } + rcu_read_lock(); spin_lock_irq(&q->queue_lock); @@ -862,7 +868,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, if (IS_ERR(blkg)) { ret = PTR_ERR(blkg); blkg_free(new_blkg); - goto fail_unlock; + goto fail_preloaded; } if (blkg) { @@ -871,10 +877,12 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, blkg = blkg_create(pos, q, new_blkg); if (IS_ERR(blkg)) { ret = PTR_ERR(blkg); - goto fail_unlock; + goto fail_preloaded; } } + radix_tree_preload_end(); + if (pos == blkcg) goto success; } @@ -884,6 +892,8 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, ctx->body = input; return 0; +fail_preloaded: + radix_tree_preload_end(); fail_unlock: spin_unlock_irq(&q->queue_lock); rcu_read_unlock(); -- 2.27.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 773EFC55178 for ; Tue, 3 Nov 2020 01:24:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B1B3222B9 for ; Tue, 3 Nov 2020 01:24:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604366656; bh=hdqDq+TaiDRElSCvu1+PkOkwPfGZkN6dKoBDHWd73AM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=es50Ez7UMIfoN8H//sSmUpvTEqnsZl7WJrnakJuYryiRFZ6Kno/7m+Znon/fs1eZx uFlfEohc6njwQoSsUvBuECFWKl0+o8hkpxMKhdZZOw1I/Gtt5Acz+sHX+/xFayRe2j 7nIO4iTeEGYqHN4EAUM/RX232oJJx/iNQD49Ptzs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728103AbgKCBUZ (ORCPT ); Mon, 2 Nov 2020 20:20:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:35094 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728089AbgKCBUY (ORCPT ); Mon, 2 Nov 2020 20:20:24 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CAA9F222B9; Tue, 3 Nov 2020 01:20:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604366423; bh=hdqDq+TaiDRElSCvu1+PkOkwPfGZkN6dKoBDHWd73AM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oK5rhnY4GRXRBQcn4eTdojpn9k7/+q2lM8+ZhdDVgjQk7Te6Ik1Wz5Vi5aOUKUxXJ Hk4aUGg4eN1H33RsdF9TJYnL184+qyUsofGnECFjwj2w1FlF99xz8/FrpuZEyAzmVS ikC/fEaL4BFN7YP9hTZTSXAf5no4uROJH0tI6kBI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Gabriel Krisman Bertazi , Tejun Heo , Jens Axboe , Sasha Levin , cgroups@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 12/24] blk-cgroup: Pre-allocate tree node on blkg_conf_prep Date: Mon, 2 Nov 2020 20:19:55 -0500 Message-Id: <20201103012007.183429-12-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201103012007.183429-1-sashal@kernel.org> References: <20201103012007.183429-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Gabriel Krisman Bertazi [ Upstream commit f255c19b3ab46d3cad3b1b2e1036f4c926cb1d0c ] Similarly to commit 457e490f2b741 ("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 Signed-off-by: Gabriel Krisman Bertazi Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-cgroup.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index a4793cfb68f28..3d34ac02d76ef 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -855,6 +855,12 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, goto fail; } + if (radix_tree_preload(GFP_KERNEL)) { + blkg_free(new_blkg); + ret = -ENOMEM; + goto fail; + } + rcu_read_lock(); spin_lock_irq(&q->queue_lock); @@ -862,7 +868,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, if (IS_ERR(blkg)) { ret = PTR_ERR(blkg); blkg_free(new_blkg); - goto fail_unlock; + goto fail_preloaded; } if (blkg) { @@ -871,10 +877,12 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, blkg = blkg_create(pos, q, new_blkg); if (IS_ERR(blkg)) { ret = PTR_ERR(blkg); - goto fail_unlock; + goto fail_preloaded; } } + radix_tree_preload_end(); + if (pos == blkcg) goto success; } @@ -884,6 +892,8 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, ctx->body = input; return 0; +fail_preloaded: + radix_tree_preload_end(); fail_unlock: spin_unlock_irq(&q->queue_lock); rcu_read_unlock(); -- 2.27.0