Message ID | 20230918074759.3895339-2-ruanjinjie@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2498086vqi; Mon, 18 Sep 2023 01:07:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElzRd7MRZ9+cPxOssS2HGlfhf8gdUt3avsASAgtxpNS4TZuWzkbPOUfOLM5XKxQhOdYvQG X-Received: by 2002:a05:6e02:12e4:b0:34f:203c:2432 with SMTP id l4-20020a056e0212e400b0034f203c2432mr12749063iln.12.1695024434965; Mon, 18 Sep 2023 01:07:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695024434; cv=none; d=google.com; s=arc-20160816; b=qwRDQCFbQxnoMEgeT/edRqJZ3TK22B+gTJkgZ4T3wustPtFf4qEjzNoWOX7ONcvgyA 5zEsMa7rUFFSJ7uf55ffW+Xna1Vspy2DajRxRW24sxcrem/ePaxrQsNZIUNGKq7O7mZp 3m6jclpe9+g8tSlQED4au9BmH6A02HpGeFUFJNwKYnvcelk4+ABnft2/bRyS9BI2nmBd u6zdsMJE8RXUBVcbGGU8pjZ9MC97QZF0dYU0rKnFrVq2dJR2zfSsPkcaK+wjWiNuvyGO vbBNQuKCLd/BY1JGSx5PkdPr5T0Sonp/A6296Z4cCN2rmWvllVJi75Pn6AhWJ2SZGRkd iMiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=cDF9VZz6PRkEnlooLIfOgQsCCTw40kEWHQZ70T/KLOc=; fh=aYKvMLxVtMOnlqtnIoYpQJlk5qPVDBrvQNBY4G56YZA=; b=m+WTS0S02IcP0BpU44f1ALKypAtlbbDRZv07jgBwV4sLnSTM1zJqY8f3toNq4ojEau gQNIgd2pSRQu271j863tPREmKWQI88Bsd96r/3DvYKsgLJZr8H3sIfPhz5WZ+aDcgtlB p5+Q3N7Q8O7/n/Ng1ThVaSpKnmRxyKFOFIKoU1VyrHJL/O2Fv12p1W+doskLoCydc4Ma chE2I6tHT3/3ZtYyhqxj92ZIe/gI4n1ILAdmw2fiFF+JyblWKGpOZj9TH3ODlQOizxqc qGHRzl0p2a/CRz2g+DLPg6ER6LM7o1RFplfP0eHKMEZEjssgo8uDM1Ojc12BccguGcDL KOmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l65-20020a633e44000000b0056959099f35si7569454pga.146.2023.09.18.01.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 01:07:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id BE59C80C5F9A; Mon, 18 Sep 2023 00:52:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240396AbjIRHv5 (ORCPT <rfc822;kernel.ruili@gmail.com> + 27 others); Mon, 18 Sep 2023 03:51:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240567AbjIRHvZ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 18 Sep 2023 03:51:25 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0F041723; Mon, 18 Sep 2023 00:49:35 -0700 (PDT) Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RpxdV6RbqztS88; Mon, 18 Sep 2023 15:44:30 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 18 Sep 2023 15:48:42 +0800 From: Jinjie Ruan <ruanjinjie@huawei.com> To: <sj@kernel.org>, <akpm@linux-foundation.org>, <brendan.higgins@linux.dev>, <feng.tang@intel.com>, <damon@lists.linux.dev>, <linux-mm@kvack.org>, <kunit-dev@googlegroups.com>, <linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org> CC: <ruanjinjie@huawei.com> Subject: [PATCH v2 1/2] mm/damon/core-test: Fix memory leak in damon_new_region() Date: Mon, 18 Sep 2023 15:47:58 +0800 Message-ID: <20230918074759.3895339-2-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918074759.3895339-1-ruanjinjie@huawei.com> References: <20230918074759.3895339-1-ruanjinjie@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 18 Sep 2023 00:52:33 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777361942009720087 X-GMAIL-MSGID: 1777361942009720087 |
Series |
mm/damon/core-test: Fix memory leaks in core-test
|
|
Commit Message
Jinjie Ruan
Sept. 18, 2023, 7:47 a.m. UTC
When CONFIG_DAMON_KUNIT_TEST=y and making CONFIG_DEBUG_KMEMLEAK=y
and CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y, the below memory leak is detected.
The damon_region which is allocated by kmem_cache_alloc() in
damon_new_region() in damon_test_regions() and
damon_test_update_monitoring_result() are not freed. So use
damon_free_region() to free it. After applying this patch, the following
memory leak is never detected.
unreferenced object 0xffff2b49c3edc000 (size 56):
comm "kunit_try_catch", pid 338, jiffies 4294895280 (age 557.084s)
hex dump (first 32 bytes):
01 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 49 2b ff ff ............I+..
backtrace:
[<0000000088e71769>] slab_post_alloc_hook+0xb8/0x368
[<00000000b528f67c>] kmem_cache_alloc+0x168/0x284
[<000000008603f022>] damon_new_region+0x28/0x54
[<00000000a3b8c64e>] damon_test_regions+0x38/0x270
[<00000000559c4801>] kunit_try_run_case+0x50/0xac
[<000000003932ed49>] kunit_generic_run_threadfn_adapter+0x20/0x2c
[<000000003c3e9211>] kthread+0x124/0x130
[<0000000028f85bdd>] ret_from_fork+0x10/0x20
unreferenced object 0xffff2b49c5b20000 (size 56):
comm "kunit_try_catch", pid 354, jiffies 4294895304 (age 556.988s)
hex dump (first 32 bytes):
03 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 96 00 00 00 49 2b ff ff ............I+..
backtrace:
[<0000000088e71769>] slab_post_alloc_hook+0xb8/0x368
[<00000000b528f67c>] kmem_cache_alloc+0x168/0x284
[<000000008603f022>] damon_new_region+0x28/0x54
[<00000000ca019f80>] damon_test_update_monitoring_result+0x18/0x34
[<00000000559c4801>] kunit_try_run_case+0x50/0xac
[<000000003932ed49>] kunit_generic_run_threadfn_adapter+0x20/0x2c
[<000000003c3e9211>] kthread+0x124/0x130
[<0000000028f85bdd>] ret_from_fork+0x10/0x20
Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests")
Fixes: f4c978b6594b ("mm/damon/core-test: add a test for damon_update_monitoring_results()")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
v2:
- Replace the damon_del_region() with damon_destroy_region() rather than
calling damon_free_region().
- Update the commit message.
---
mm/damon/core-test.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
Comments
Hi Jinjie, On Mon, 18 Sep 2023 15:47:58 +0800 Jinjie Ruan <ruanjinjie@huawei.com> wrote: > When CONFIG_DAMON_KUNIT_TEST=y and making CONFIG_DEBUG_KMEMLEAK=y > and CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y, the below memory leak is detected. > > The damon_region which is allocated by kmem_cache_alloc() in > damon_new_region() in damon_test_regions() and > damon_test_update_monitoring_result() are not freed. So use > damon_free_region() to free it. Nit. This patch is not directly adding use of damon_free_region() but replaces damon_del_region() call with damon_destroy_region(), so that it calls both damon_del_region() and damon_free_region(). I think this part might better to be re-written? > After applying this patch, the following > memory leak is never detected. > > unreferenced object 0xffff2b49c3edc000 (size 56): > comm "kunit_try_catch", pid 338, jiffies 4294895280 (age 557.084s) > hex dump (first 32 bytes): > 01 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 ................ > 00 00 00 00 00 00 00 00 00 00 00 00 49 2b ff ff ............I+.. > backtrace: > [<0000000088e71769>] slab_post_alloc_hook+0xb8/0x368 > [<00000000b528f67c>] kmem_cache_alloc+0x168/0x284 > [<000000008603f022>] damon_new_region+0x28/0x54 > [<00000000a3b8c64e>] damon_test_regions+0x38/0x270 > [<00000000559c4801>] kunit_try_run_case+0x50/0xac > [<000000003932ed49>] kunit_generic_run_threadfn_adapter+0x20/0x2c > [<000000003c3e9211>] kthread+0x124/0x130 > [<0000000028f85bdd>] ret_from_fork+0x10/0x20 > unreferenced object 0xffff2b49c5b20000 (size 56): > comm "kunit_try_catch", pid 354, jiffies 4294895304 (age 556.988s) > hex dump (first 32 bytes): > 03 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 ................ > 00 00 00 00 00 00 00 00 96 00 00 00 49 2b ff ff ............I+.. > backtrace: > [<0000000088e71769>] slab_post_alloc_hook+0xb8/0x368 > [<00000000b528f67c>] kmem_cache_alloc+0x168/0x284 > [<000000008603f022>] damon_new_region+0x28/0x54 > [<00000000ca019f80>] damon_test_update_monitoring_result+0x18/0x34 > [<00000000559c4801>] kunit_try_run_case+0x50/0xac > [<000000003932ed49>] kunit_generic_run_threadfn_adapter+0x20/0x2c > [<000000003c3e9211>] kthread+0x124/0x130 > [<0000000028f85bdd>] ret_from_fork+0x10/0x20 > > Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests") > Fixes: f4c978b6594b ("mm/damon/core-test: add a test for damon_update_monitoring_results()") > Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Other than the above trivial nit, Reviewed-by: SeongJae Park <sj@kernel.org> > --- > v2: > - Replace the damon_del_region() with damon_destroy_region() rather than > calling damon_free_region(). > - Update the commit message. And thank you for making the changes. Thanks, SJ > --- > mm/damon/core-test.h | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h > index 79f1f12e0dd5..3959be35b901 100644 > --- a/mm/damon/core-test.h > +++ b/mm/damon/core-test.h > @@ -30,7 +30,7 @@ static void damon_test_regions(struct kunit *test) > damon_add_region(r, t); > KUNIT_EXPECT_EQ(test, 1u, damon_nr_regions(t)); > > - damon_del_region(r, t); > + damon_destroy_region(r, t); > KUNIT_EXPECT_EQ(test, 0u, damon_nr_regions(t)); > > damon_free_target(t); > @@ -321,6 +321,8 @@ static void damon_test_update_monitoring_result(struct kunit *test) > damon_update_monitoring_result(r, &old_attrs, &new_attrs); > KUNIT_EXPECT_EQ(test, r->nr_accesses, 150); > KUNIT_EXPECT_EQ(test, r->age, 20); > + > + damon_free_region(r); > } > > static void damon_test_set_attrs(struct kunit *test) > -- > 2.34.1 > >
On 2023/9/18 19:00, SeongJae Park wrote: > Hi Jinjie, > > On Mon, 18 Sep 2023 15:47:58 +0800 Jinjie Ruan <ruanjinjie@huawei.com> wrote: > >> When CONFIG_DAMON_KUNIT_TEST=y and making CONFIG_DEBUG_KMEMLEAK=y >> and CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN=y, the below memory leak is detected. >> >> The damon_region which is allocated by kmem_cache_alloc() in >> damon_new_region() in damon_test_regions() and >> damon_test_update_monitoring_result() are not freed. So use >> damon_free_region() to free it. > > Nit. This patch is not directly adding use of damon_free_region() but replaces > damon_del_region() call with damon_destroy_region(), so that it calls both > damon_del_region() and damon_free_region(). > > I think this part might better to be re-written? OK. Thank you! > >> After applying this patch, the following >> memory leak is never detected. >> >> unreferenced object 0xffff2b49c3edc000 (size 56): >> comm "kunit_try_catch", pid 338, jiffies 4294895280 (age 557.084s) >> hex dump (first 32 bytes): >> 01 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 ................ >> 00 00 00 00 00 00 00 00 00 00 00 00 49 2b ff ff ............I+.. >> backtrace: >> [<0000000088e71769>] slab_post_alloc_hook+0xb8/0x368 >> [<00000000b528f67c>] kmem_cache_alloc+0x168/0x284 >> [<000000008603f022>] damon_new_region+0x28/0x54 >> [<00000000a3b8c64e>] damon_test_regions+0x38/0x270 >> [<00000000559c4801>] kunit_try_run_case+0x50/0xac >> [<000000003932ed49>] kunit_generic_run_threadfn_adapter+0x20/0x2c >> [<000000003c3e9211>] kthread+0x124/0x130 >> [<0000000028f85bdd>] ret_from_fork+0x10/0x20 >> unreferenced object 0xffff2b49c5b20000 (size 56): >> comm "kunit_try_catch", pid 354, jiffies 4294895304 (age 556.988s) >> hex dump (first 32 bytes): >> 03 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 ................ >> 00 00 00 00 00 00 00 00 96 00 00 00 49 2b ff ff ............I+.. >> backtrace: >> [<0000000088e71769>] slab_post_alloc_hook+0xb8/0x368 >> [<00000000b528f67c>] kmem_cache_alloc+0x168/0x284 >> [<000000008603f022>] damon_new_region+0x28/0x54 >> [<00000000ca019f80>] damon_test_update_monitoring_result+0x18/0x34 >> [<00000000559c4801>] kunit_try_run_case+0x50/0xac >> [<000000003932ed49>] kunit_generic_run_threadfn_adapter+0x20/0x2c >> [<000000003c3e9211>] kthread+0x124/0x130 >> [<0000000028f85bdd>] ret_from_fork+0x10/0x20 >> >> Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests") >> Fixes: f4c978b6594b ("mm/damon/core-test: add a test for damon_update_monitoring_results()") >> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> > > Other than the above trivial nit, > > Reviewed-by: SeongJae Park <sj@kernel.org> > >> --- >> v2: >> - Replace the damon_del_region() with damon_destroy_region() rather than >> calling damon_free_region(). >> - Update the commit message. > > And thank you for making the changes. > > > Thanks, > SJ > >> --- >> mm/damon/core-test.h | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h >> index 79f1f12e0dd5..3959be35b901 100644 >> --- a/mm/damon/core-test.h >> +++ b/mm/damon/core-test.h >> @@ -30,7 +30,7 @@ static void damon_test_regions(struct kunit *test) >> damon_add_region(r, t); >> KUNIT_EXPECT_EQ(test, 1u, damon_nr_regions(t)); >> >> - damon_del_region(r, t); >> + damon_destroy_region(r, t); >> KUNIT_EXPECT_EQ(test, 0u, damon_nr_regions(t)); >> >> damon_free_target(t); >> @@ -321,6 +321,8 @@ static void damon_test_update_monitoring_result(struct kunit *test) >> damon_update_monitoring_result(r, &old_attrs, &new_attrs); >> KUNIT_EXPECT_EQ(test, r->nr_accesses, 150); >> KUNIT_EXPECT_EQ(test, r->age, 20); >> + >> + damon_free_region(r); >> } >> >> static void damon_test_set_attrs(struct kunit *test) >> -- >> 2.34.1 >> >>
diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index 79f1f12e0dd5..3959be35b901 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -30,7 +30,7 @@ static void damon_test_regions(struct kunit *test) damon_add_region(r, t); KUNIT_EXPECT_EQ(test, 1u, damon_nr_regions(t)); - damon_del_region(r, t); + damon_destroy_region(r, t); KUNIT_EXPECT_EQ(test, 0u, damon_nr_regions(t)); damon_free_target(t); @@ -321,6 +321,8 @@ static void damon_test_update_monitoring_result(struct kunit *test) damon_update_monitoring_result(r, &old_attrs, &new_attrs); KUNIT_EXPECT_EQ(test, r->nr_accesses, 150); KUNIT_EXPECT_EQ(test, r->age, 20); + + damon_free_region(r); } static void damon_test_set_attrs(struct kunit *test)