* [PATCH v2 0/2] Fixes to blkg_conf_prep
@ 2020-10-22 20:58 Gabriel Krisman Bertazi
[not found] ` <20201022205842.1739739-1-krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Gabriel Krisman Bertazi @ 2020-10-22 20:58 UTC (permalink / raw)
To: tj-DgEjT+Ai2ygdnm+yROfE0A, axboe-tSWWG44O7X1aa/9Udqfwiw
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA, khazhy-hpIqsD4AKlfQT0dZR+AlfA,
Gabriel Krisman Bertazi, kernel-ZGY8ohtN/8qB+jHODAdFcQ
Hi Tejun,
In addition to addressing your comments the previously submitted fix to
pre-allocate the radix node on blkg_conf_prep, this series fixes a small
memleak on the same function.
Gabriel Krisman Bertazi (2):
blk-cgroup: Fix memleak on error path
blk-cgroup: Pre-allocate tree node on blkg_conf_prep
block/blk-cgroup.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
--
2.28.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/2] blk-cgroup: Fix memleak on error path
[not found] ` <20201022205842.1739739-1-krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
@ 2020-10-22 20:58 ` Gabriel Krisman Bertazi
[not found] ` <20201022205842.1739739-2-krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
2020-10-22 20:58 ` [PATCH v2 2/2] blk-cgroup: Pre-allocate tree node on blkg_conf_prep Gabriel Krisman Bertazi
2020-10-26 13:58 ` [PATCH v2 0/2] Fixes to blkg_conf_prep Jens Axboe
2 siblings, 1 reply; 8+ messages in thread
From: Gabriel Krisman Bertazi @ 2020-10-22 20:58 UTC (permalink / raw)
To: tj-DgEjT+Ai2ygdnm+yROfE0A, axboe-tSWWG44O7X1aa/9Udqfwiw
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA, khazhy-hpIqsD4AKlfQT0dZR+AlfA,
Gabriel Krisman Bertazi, kernel-ZGY8ohtN/8qB+jHODAdFcQ
If new_blkg allocation raced with blk_policy change and
blkg_lookup_check fails, new_blkg is leaked.
Signed-off-by: Gabriel Krisman Bertazi <krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
---
block/blk-cgroup.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index f9b55614d67d..f9389b7cf823 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -663,6 +663,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
blkg = blkg_lookup_check(pos, pol, q);
if (IS_ERR(blkg)) {
ret = PTR_ERR(blkg);
+ blkg_free(new_blkg);
goto fail_unlock;
}
--
2.28.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] blk-cgroup: Pre-allocate tree node on blkg_conf_prep
[not found] ` <20201022205842.1739739-1-krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
2020-10-22 20:58 ` [PATCH v2 1/2] blk-cgroup: Fix memleak on error path Gabriel Krisman Bertazi
@ 2020-10-22 20:58 ` Gabriel Krisman Bertazi
[not found] ` <20201022205842.1739739-3-krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
2020-10-26 13:58 ` [PATCH v2 0/2] Fixes to blkg_conf_prep Jens Axboe
2 siblings, 1 reply; 8+ messages in thread
From: Gabriel Krisman Bertazi @ 2020-10-22 20:58 UTC (permalink / raw)
To: tj-DgEjT+Ai2ygdnm+yROfE0A, axboe-tSWWG44O7X1aa/9Udqfwiw
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA, khazhy-hpIqsD4AKlfQT0dZR+AlfA,
Gabriel Krisman Bertazi, kernel-ZGY8ohtN/8qB+jHODAdFcQ
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.
Signed-off-by: Gabriel Krisman Bertazi <krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
---
Changes since v1:
- Fail function if preload failed. (Tejun Heo)
---
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 f9389b7cf823..c68bdf58c9a6 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -657,6 +657,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);
@@ -664,7 +670,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) {
@@ -673,10 +679,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;
}
@@ -686,6 +694,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.28.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/2] blk-cgroup: Fix memleak on error path
[not found] ` <20201022205842.1739739-2-krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
@ 2020-10-26 13:54 ` Tejun Heo
0 siblings, 0 replies; 8+ messages in thread
From: Tejun Heo @ 2020-10-26 13:54 UTC (permalink / raw)
To: Gabriel Krisman Bertazi
Cc: axboe-tSWWG44O7X1aa/9Udqfwiw, cgroups-u79uwXL29TY76Z2rM5mHXA,
khazhy-hpIqsD4AKlfQT0dZR+AlfA, kernel-ZGY8ohtN/8qB+jHODAdFcQ
On Thu, Oct 22, 2020 at 04:58:41PM -0400, Gabriel Krisman Bertazi wrote:
> If new_blkg allocation raced with blk_policy change and
> blkg_lookup_check fails, new_blkg is leaked.
>
> Signed-off-by: Gabriel Krisman Bertazi <krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
Acked-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] blk-cgroup: Pre-allocate tree node on blkg_conf_prep
[not found] ` <20201022205842.1739739-3-krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
@ 2020-10-26 13:55 ` Tejun Heo
0 siblings, 0 replies; 8+ messages in thread
From: Tejun Heo @ 2020-10-26 13:55 UTC (permalink / raw)
To: Gabriel Krisman Bertazi
Cc: axboe-tSWWG44O7X1aa/9Udqfwiw, cgroups-u79uwXL29TY76Z2rM5mHXA,
khazhy-hpIqsD4AKlfQT0dZR+AlfA, kernel-ZGY8ohtN/8qB+jHODAdFcQ
On Thu, Oct 22, 2020 at 04:58:42PM -0400, Gabriel Krisman Bertazi wrote:
> 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.
>
> Signed-off-by: Gabriel Krisman Bertazi <krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
Acked-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] Fixes to blkg_conf_prep
[not found] ` <20201022205842.1739739-1-krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
2020-10-22 20:58 ` [PATCH v2 1/2] blk-cgroup: Fix memleak on error path Gabriel Krisman Bertazi
2020-10-22 20:58 ` [PATCH v2 2/2] blk-cgroup: Pre-allocate tree node on blkg_conf_prep Gabriel Krisman Bertazi
@ 2020-10-26 13:58 ` Jens Axboe
2 siblings, 0 replies; 8+ messages in thread
From: Jens Axboe @ 2020-10-26 13:58 UTC (permalink / raw)
To: Gabriel Krisman Bertazi, tj-DgEjT+Ai2ygdnm+yROfE0A
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA, khazhy-hpIqsD4AKlfQT0dZR+AlfA,
kernel-ZGY8ohtN/8qB+jHODAdFcQ
On 10/22/20 2:58 PM, Gabriel Krisman Bertazi wrote:
> Hi Tejun,
>
> In addition to addressing your comments the previously submitted fix to
> pre-allocate the radix node on blkg_conf_prep, this series fixes a small
> memleak on the same function.
Applied, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/2] blk-cgroup: Fix memleak on error path
[not found] ` <20201022205758.1739430-1-krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
@ 2020-10-22 20:59 ` Gabriel Krisman Bertazi
0 siblings, 0 replies; 8+ messages in thread
From: Gabriel Krisman Bertazi @ 2020-10-22 20:59 UTC (permalink / raw)
To: tj-DgEjT+Ai2ygdnm+yROfE0A
Cc: axboe-tSWWG44O7X1aa/9Udqfwiw, cgroups-u79uwXL29TY76Z2rM5mHXA,
khazhy-hpIqsD4AKlfQT0dZR+AlfA, kernel-ZGY8ohtN/8qB+jHODAdFcQ
Gabriel Krisman Bertazi <krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org> writes:
> If new_blkg allocation raced with blk_policy change and
> blkg_lookup_check fails, new_blkg is leaked.
hm, sorry for the duplicate, the first attempt my script tripped on the
cover letter for some reason. Please disregard this one.
--
Gabriel Krisman Bertazi
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/2] blk-cgroup: Fix memleak on error path
@ 2020-10-22 20:57 Gabriel Krisman Bertazi
[not found] ` <20201022205758.1739430-1-krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Gabriel Krisman Bertazi @ 2020-10-22 20:57 UTC (permalink / raw)
To: tj-DgEjT+Ai2ygdnm+yROfE0A, axboe-tSWWG44O7X1aa/9Udqfwiw
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA, khazhy-hpIqsD4AKlfQT0dZR+AlfA,
Gabriel Krisman Bertazi, kernel-ZGY8ohtN/8qB+jHODAdFcQ
If new_blkg allocation raced with blk_policy change and
blkg_lookup_check fails, new_blkg is leaked.
Signed-off-by: Gabriel Krisman Bertazi <krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
---
block/blk-cgroup.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index f9b55614d67d..f9389b7cf823 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -663,6 +663,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
blkg = blkg_lookup_check(pos, pol, q);
if (IS_ERR(blkg)) {
ret = PTR_ERR(blkg);
+ blkg_free(new_blkg);
goto fail_unlock;
}
--
2.28.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-10-26 13:58 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22 20:58 [PATCH v2 0/2] Fixes to blkg_conf_prep Gabriel Krisman Bertazi
[not found] ` <20201022205842.1739739-1-krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
2020-10-22 20:58 ` [PATCH v2 1/2] blk-cgroup: Fix memleak on error path Gabriel Krisman Bertazi
[not found] ` <20201022205842.1739739-2-krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
2020-10-26 13:54 ` Tejun Heo
2020-10-22 20:58 ` [PATCH v2 2/2] blk-cgroup: Pre-allocate tree node on blkg_conf_prep Gabriel Krisman Bertazi
[not found] ` <20201022205842.1739739-3-krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
2020-10-26 13:55 ` Tejun Heo
2020-10-26 13:58 ` [PATCH v2 0/2] Fixes to blkg_conf_prep Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2020-10-22 20:57 [PATCH v2 1/2] blk-cgroup: Fix memleak on error path Gabriel Krisman Bertazi
[not found] ` <20201022205758.1739430-1-krisman-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
2020-10-22 20:59 ` Gabriel Krisman Bertazi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.