From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751035AbdHSGLU convert rfc822-to-8bit (ORCPT ); Sat, 19 Aug 2017 02:11:20 -0400 Received: from mout.gmx.net ([212.227.17.21]:53537 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750832AbdHSGLT (ORCPT ); Sat, 19 Aug 2017 02:11:19 -0400 Message-ID: <1503123049.5112.49.camel@gmx.de> Subject: [rfc patch] sched/topology: fix domain reconstruction memory leakage From: Mike Galbraith To: Peter Zijlstra , Ingo Molnar Cc: LKML Date: Sat, 19 Aug 2017 08:10:49 +0200 Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.20.5 Mime-Version: 1.0 Content-Transfer-Encoding: 8BIT X-Provags-ID: V03:K0:OCw2X2j4YHr7WtxsxaO3pDLTEeP5YnOOyObNiPn2y1TRm/NsOUH M8wW34kGcKueiA0LAelXALtjklu3BiBBpolD6G94gP2lwCn20RK6PFgn/Fx2nefou9/yQ5i Xx8GFuLOXLTbK+UzaP4oD+aGHy/A7F5FY9cijjVJs68cWMMy2APEfSKBenBD1NrGgElRu1N +qSsze15R9OI1PG7qS0YA== X-UI-Out-Filterresults: notjunk:1;V01:K0:vH447dY4Vto=:gMpQ6MGXbkGcU3tl+2BsF/ rqQUOCmAtzMpHsHlRKZX/vM3rUlrCaaYWbq0ItFyvbPeafrBVjhjAcD7Vi9ZUPjZ9OmR6h9Es BkAlRhVxeXXc3/t3y8sQAy2o3144I/HpI5Es8eebg+Z+pILRsmR7yGyJO94BOSk1iAGxitXIk 41axh8EsFUxylNXZznL8L/LU9uauAjBtiLqiHN7QEhkSkjMEoSSM/ADzgpu12mFg5lwdVvb9U FVeSmp/dwW05I1wGM//Xq+VZj0oMi/LtR97c1UnlmvwRYMfB0btYtIzcRM+vFvA6UW75FBVwc whB4BgL4BtugwrAv5U+DjB1w8G+eNiaDVPmOFuZr+VFNpcdos6OaoX6itzIJVuhkPRqsKsnI2 hQE6AVdiEQXvHcO0LKHtKPA/h2q/q4Qm6nneqi55+ZX5ooLTvRjFgkS48cXCLTd0nI9IycLJx JeTujvra5Gc2Y7jXEWi6oMECPalBB3GUfJ6UtPt+RLV42HPGzD6aoXCJDQYiH5GNQzirmSa7d SgfZfYojdcD59WUs5PSAIjA4aLxIRuyaRp5fckpdFv3qIoGRfMPEd6qgUXNI1dRNfpyt1SUnh T26TGm98kRlvF3w4b2ONNyF/q94ICfl1A4z7aRuQSmuLqRCEoMu0yGExWpgz4tzQVpxhpJ9Ap zPUWYp2CO65b82BLoy6y1IpXLUHaocUA+OEq/cAIErdIxWFN8Y3CbW9c4UUo43t8eRgFK6iI4 yeEfSAOZvK5D5hxPaxf0XKK/6pTcyW7ag1XyxTqxyotUlXxdKnUqRq71xUXHXf9pXrA2pkS76 XpuUsowdifqBJzvBjQ0AAIb0pbLiZj/YjWyqVcdU7YPG24vtus= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Greetings, While beating on cpu hotplug with the shiny new topology fixes backported, my memory poor 8 socket box fairly quickly leaked itself to death, 0c0e776a9b0f being the culprit.  With the below applied, box took a severe beating overnight without a whimper. I'm wondering (ergo rfc) if free_sched_groups() shouldn't be renamed to put_sched_groups() instead, with overlapping domains taking a group reference reference as well so they can put both sg/sgc rather than put one free the other.  Those places that want an explicit free can pass free to only explicitly free sg (or use two functions).  Minimalist approach works (minus signs, yay), but could perhaps use some "pretty". sched/topology: fix domain reconstruction memory leakage Since 0c0e776a9b0f, build_sched_groups() takes a reference on each sg and sgc during domain generation, where previously it only took a reference on the first group. Iterate groups and drop all added references during domain destruction, otherwise CPU hotplug leaks. Signed-off-by: Mike Galbraith Fixes: 0c0e776a9b0f ("sched/topology: Rewrite get_group()") --- kernel/sched/topology.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -323,7 +323,7 @@ static struct root_domain *alloc_rootdom return rd; } -static void free_sched_groups(struct sched_group *sg, int free_sgc) +static void free_sched_groups(struct sched_group *sg, int put) { struct sched_group *tmp, *first; @@ -334,10 +334,11 @@ static void free_sched_groups(struct sch do { tmp = sg->next; - if (free_sgc && atomic_dec_and_test(&sg->sgc->ref)) + if (put && atomic_dec_and_test(&sg->sgc->ref)) kfree(sg->sgc); + if (put < 2 || atomic_dec_and_test(&sg->ref)) + kfree(sg); - kfree(sg); sg = tmp; } while (sg != first); } @@ -345,15 +346,11 @@ static void free_sched_groups(struct sch static void destroy_sched_domain(struct sched_domain *sd) { /* - * If its an overlapping domain it has private groups, iterate and - * nuke them all. + * If it's an overlapping domain it has private groups, iterate, + * freeing groups, otherwise dropping group references. In both + * cases, we must drop group capacity references. */ - if (sd->flags & SD_OVERLAP) { - free_sched_groups(sd->groups, 1); - } else if (atomic_dec_and_test(&sd->groups->ref)) { - kfree(sd->groups->sgc); - kfree(sd->groups); - } + free_sched_groups(sd->groups, !(sd->flags & SD_OVERLAP)+1); if (sd->shared && atomic_dec_and_test(&sd->shared->ref)) kfree(sd->shared); kfree(sd);