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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 590B0C54EE9 for ; Fri, 2 Sep 2022 05:26:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234212AbiIBF0k (ORCPT ); Fri, 2 Sep 2022 01:26:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbiIBF0g (ORCPT ); Fri, 2 Sep 2022 01:26:36 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93D77A287C for ; Thu, 1 Sep 2022 22:26:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4E80D61FAC for ; Fri, 2 Sep 2022 05:26:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CAAAC433C1; Fri, 2 Sep 2022 05:26:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662096393; bh=kCs5hcyaQYvKEehl1r3IG5R/zbdM0jlFTO/QONZfXSs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iQpjnAIV/bYvfDkZKk+HQc+Tevna0RhemKsyrgP11ix0XS3m4adpMFBZJm251cABE 2xO4NRVAxzMaIvY7DW5WRBCBBA2N0QU5mhahRVc//pvf4joAk1gg7kMpPJ6/ZM1vGF pW3TIlIAg9UbQFKdpDW+HYFKcMITh6eTz5zMHUGo= Date: Fri, 2 Sep 2022 07:26:31 +0200 From: Greg Kroah-Hartman To: Kuyo Chang Cc: major.chen@samsung.com, Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Matthias Brugger , wsd_upstream@mediatek.com, hongfei.tang@samsung.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: Re: [PATCH 1/1] sched/debug: fix dentry leak in update_sched_domain_debugfs Message-ID: References: <20220902031518.1116-1-kuyo.chang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220902031518.1116-1-kuyo.chang@mediatek.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 02, 2022 at 11:15:15AM +0800, Kuyo Chang wrote: > From: kuyo chang > > [Syndrome] > Lowmemorykiller triggered while doing hotplug stress test as below cmd: > echo [0/1] > /sys/devices/system/cpu/cpu${index}/online > > Rootcause: > Call trace of the slab owner & usage as below after hotplug stress > test(4hr). > There exists dentry leak at update_sched_domain_debugfs. > > Total size : 322000KB > : > : > <__alloc_pages+304>: > : > <___slab_alloc+404>: > <__slab_alloc+60>: > : > : > : > <__debugfs_create_file+172>: > : > : > : > : > : > : > > [Solution] > Provided by Major Chen as below link. > https://lore.kernel.org/lkml/20220711030341epcms5p173848e98b13c09eb2fcdf2fd7287526a@epcms5p1/ > update_sched_domain_debugfs() uses debugfs_lookup() to find wanted dentry(which has > been created by debugfs_create_dir() before), but not call dput() to return this dentry > back. This result in dentry leak even debugfs_remove() is called. > > [Test result] > Using below commands to check inode_cache & dentry leak. > cat /proc/slabinfo | grep -w inode_cache > cat /proc/slabinfo | grep -w dentry > > With the patch, the inode_cache & dentry stays consistent > so the lowmemorykiller will not triggered anymore. > > Fixes: 8a99b6833c88 ("sched: Move SCHED_DEBUG sysctl to debugfs") > > Signed-off-by: Major Chen > Signed-off-by: kuyo chang > Tested-by: kuyo chang > > --- > kernel/sched/debug.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c > index bb3d63bdf4ae..4ffea2dc01da 100644 > --- a/kernel/sched/debug.c > +++ b/kernel/sched/debug.c > @@ -412,11 +412,14 @@ void update_sched_domain_debugfs(void) > > for_each_cpu(cpu, sd_sysctl_cpus) { > struct sched_domain *sd; > - struct dentry *d_cpu; > + struct dentry *d_cpu, *d_lookup; > char buf[32]; > > snprintf(buf, sizeof(buf), "cpu%d", cpu); > - debugfs_remove(debugfs_lookup(buf, sd_dentry)); > + d_lookup = debugfs_lookup(buf, sd_dentry); > + debugfs_remove(d_lookup); > + if (!IS_ERR_OR_NULL(d_lookup)) > + dput(d_lookup); That's odd, and means that something else is removing this file right after we looked it up? Is there a missing lock here that should be used instead? thanks, greg k-h 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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B824EECAAA1 for ; Fri, 2 Sep 2022 05:28:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mf5F83frsKoxV/vTfw+spI00H/Kp+OVeCkqAoYeE3eY=; b=YEztKAOEOq8w3J +wXYIdw/wadBw3v9zr5H0y8QB5jS6rr8j8UbLBq7ZtdzXou5k075OJZgd0Cto6wGfydkbNTmcjfoX MnzZloZfxIR/fyW+uzHMaU8+vjDB8zTNDZ83smETrcN9je/Fqw7/CgsZaFs6WodC/vQRMWN1zrM5u GPr4gwdTHszWSbOUxmnGFpP0n3YwnsNjJcakdVk4tEug002LpmZuJ4GUMLwmBwA0XT0rwFn422dH3 zO87K7OqoR5kgEnK17pBkA+zoiAX3HA2tFEdOm1nlh2mCUlXGcVWyGr9BPE+gPRhwPjGBir/fFfGa hVhQU/JDPhqpm1y1HoZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTzCS-000Vgm-02; Fri, 02 Sep 2022 05:26:40 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTzCP-000Vec-2S; Fri, 02 Sep 2022 05:26:38 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DBD9DB829B0; Fri, 2 Sep 2022 05:26:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CAAAC433C1; Fri, 2 Sep 2022 05:26:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662096393; bh=kCs5hcyaQYvKEehl1r3IG5R/zbdM0jlFTO/QONZfXSs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iQpjnAIV/bYvfDkZKk+HQc+Tevna0RhemKsyrgP11ix0XS3m4adpMFBZJm251cABE 2xO4NRVAxzMaIvY7DW5WRBCBBA2N0QU5mhahRVc//pvf4joAk1gg7kMpPJ6/ZM1vGF pW3TIlIAg9UbQFKdpDW+HYFKcMITh6eTz5zMHUGo= Date: Fri, 2 Sep 2022 07:26:31 +0200 From: Greg Kroah-Hartman To: Kuyo Chang Cc: major.chen@samsung.com, Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Matthias Brugger , wsd_upstream@mediatek.com, hongfei.tang@samsung.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: Re: [PATCH 1/1] sched/debug: fix dentry leak in update_sched_domain_debugfs Message-ID: References: <20220902031518.1116-1-kuyo.chang@mediatek.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220902031518.1116-1-kuyo.chang@mediatek.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220901_222637_408348_132C22F6 X-CRM114-Status: GOOD ( 23.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Sep 02, 2022 at 11:15:15AM +0800, Kuyo Chang wrote: > From: kuyo chang > > [Syndrome] > Lowmemorykiller triggered while doing hotplug stress test as below cmd: > echo [0/1] > /sys/devices/system/cpu/cpu${index}/online > > Rootcause: > Call trace of the slab owner & usage as below after hotplug stress > test(4hr). > There exists dentry leak at update_sched_domain_debugfs. > > Total size : 322000KB > : > : > <__alloc_pages+304>: > : > <___slab_alloc+404>: > <__slab_alloc+60>: > : > : > : > <__debugfs_create_file+172>: > : > : > : > : > : > : > > [Solution] > Provided by Major Chen as below link. > https://lore.kernel.org/lkml/20220711030341epcms5p173848e98b13c09eb2fcdf2fd7287526a@epcms5p1/ > update_sched_domain_debugfs() uses debugfs_lookup() to find wanted dentry(which has > been created by debugfs_create_dir() before), but not call dput() to return this dentry > back. This result in dentry leak even debugfs_remove() is called. > > [Test result] > Using below commands to check inode_cache & dentry leak. > cat /proc/slabinfo | grep -w inode_cache > cat /proc/slabinfo | grep -w dentry > > With the patch, the inode_cache & dentry stays consistent > so the lowmemorykiller will not triggered anymore. > > Fixes: 8a99b6833c88 ("sched: Move SCHED_DEBUG sysctl to debugfs") > > Signed-off-by: Major Chen > Signed-off-by: kuyo chang > Tested-by: kuyo chang > > --- > kernel/sched/debug.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c > index bb3d63bdf4ae..4ffea2dc01da 100644 > --- a/kernel/sched/debug.c > +++ b/kernel/sched/debug.c > @@ -412,11 +412,14 @@ void update_sched_domain_debugfs(void) > > for_each_cpu(cpu, sd_sysctl_cpus) { > struct sched_domain *sd; > - struct dentry *d_cpu; > + struct dentry *d_cpu, *d_lookup; > char buf[32]; > > snprintf(buf, sizeof(buf), "cpu%d", cpu); > - debugfs_remove(debugfs_lookup(buf, sd_dentry)); > + d_lookup = debugfs_lookup(buf, sd_dentry); > + debugfs_remove(d_lookup); > + if (!IS_ERR_OR_NULL(d_lookup)) > + dput(d_lookup); That's odd, and means that something else is removing this file right after we looked it up? Is there a missing lock here that should be used instead? thanks, greg k-h _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel