Message ID | 20230918051044.3814018-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 h50csp2441261vqi; Sun, 17 Sep 2023 22:15:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGAVBnqAAIcqC8/dOVXOmpBv6uIGUqdZHmhtemFIOgCvcyr3ltbH51TFMrrFwKGt1DkF4t X-Received: by 2002:a17:902:6b0a:b0:1c1:e5f7:a743 with SMTP id o10-20020a1709026b0a00b001c1e5f7a743mr6657036plk.55.1695014112970; Sun, 17 Sep 2023 22:15:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695014112; cv=none; d=google.com; s=arc-20160816; b=xaiAxDYV9MA6ZyM1w1Ox+nM9mvVVQeZqfDyl3hL1JQ+yanqj3tURi7VKJQITZX8e7Z 8+/iCby6kTkCbchq7WBs1qqWvgYpiWOwAnCwcG03ki1EzjDMUqoIE+1FQh9u9Mqbh/b1 zWgqDQxyROlh8mVbAew3T6AF5KkoWhnvx1nINxj2xyUGapEYEEsfec58/R5dW7a8mxkg 5vEH+AiIQ5bWaqGHNP19GifhoilDdaP5IHIuWDftnQt8Rogvqh4FIsteoeTRkfH6AHri ezag4NqxZ6vtTFi4sn5E9uJPn2ag5qTA+FkOHgwleLJtwEbtstZnyx7RPiOW1sU3vL6+ as7g== 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=+/CYCX9ULxLJESJb0b+bDfwDJuFBVwmRb7urQTLFm4o=; fh=aYKvMLxVtMOnlqtnIoYpQJlk5qPVDBrvQNBY4G56YZA=; b=BA1Tfw9aIaiKa639sowghN3qECi2WS00H0tJJCFibDGP7G68JIicwQbLgXQHS59ZWv UNBhCWCh7Z8SQqOHdhfreiTp5hIhmLIXhbudQf70fy0sV9nSAtFviSLzWgp5+2ahSM6f cZZ38h6cEgdMWmtbKP2/5LSqhfiNWSEIZYiMqFf048YCuU6RKpQiORNc0g16xAgXkFkM ISjLDbYs5G5biAepUptupZikBcus6Jrym8hvLk5mpqgVTtJZRMkMEsR+oJtv6oTbuCWz k65mfvAYz5I6mF4uBL0pnpHQzXDKcATuNIt9tZUkWzh4OCiAaiB4jAZBwIYkg8bQWYdI cABw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id f18-20020a170902ce9200b001bbd0358ef7si7760764plg.518.2023.09.17.22.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 22:15:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 8BA4280C4781; Sun, 17 Sep 2023 22:12:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239586AbjIRFMN (ORCPT <rfc822;kernel.ruili@gmail.com> + 28 others); Mon, 18 Sep 2023 01:12:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236741AbjIRFMB (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 18 Sep 2023 01:12:01 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F69610F; Sun, 17 Sep 2023 22:11:53 -0700 (PDT) Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Rpt8V55WCztRn7; Mon, 18 Sep 2023 13:07:38 +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 13:11:50 +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 RESEND 1/2] mm/damon/core-test: Fix memory leak in damon_new_region() Date: Mon, 18 Sep 2023 13:10:43 +0800 Message-ID: <20230918051044.3814018-2-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918051044.3814018-1-ruanjinjie@huawei.com> References: <20230918051044.3814018-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: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Sun, 17 Sep 2023 22:12:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777351118645546410 X-GMAIL-MSGID: 1777351118645546410 |
Series |
mm/damon/core-test: Fix memory leaks in core-test
|
|
Commit Message
Jinjie Ruan
Sept. 18, 2023, 5:10 a.m. UTC
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 and it causes below
memory leak. So use damon_free_region() to free it.
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>
---
mm/damon/core-test.h | 3 +++
1 file changed, 3 insertions(+)
Comments
Hi Jinjie, Thank you for this patchset! On Mon, 18 Sep 2023 13:10:43 +0800 Jinjie Ruan <ruanjinjie@huawei.com> wrote: > 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 and it causes below > memory leak. So use damon_free_region() to free it. > > 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 Nice finding! Could you please share just a brief more detail about above cool output, e.g., just the name of the tool you used, so that others can learn it from your awesome commit message? > > 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> > --- > mm/damon/core-test.h | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h > index 6cc8b245586d..255f8c925c00 100644 > --- a/mm/damon/core-test.h > +++ b/mm/damon/core-test.h > @@ -34,6 +34,7 @@ static void damon_test_regions(struct kunit *test) > KUNIT_EXPECT_EQ(test, 0u, damon_nr_regions(t)); > > damon_free_target(t); > + damon_free_region(r); There is damon_destroy_region() function, which simply calls damon_del_region() and damon_free_region(). Unless there is needs to access the region before removing from the region, doing memory return together via the function is recommended. And this test code calls damon_del_region() just beofre above KUNIT_EXPECT_EQ(). Hence, I think replacing the damon_del_region() call with damon_destroy_region() rather than calling damon_free_region() may be simpler and shorter. Could you please do so? > } > > static unsigned int nr_damon_targets(struct damon_ctx *ctx) > @@ -316,6 +317,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); This looks nice. Thank you for fixing this! > } > > static void damon_test_set_attrs(struct kunit *test) > -- > 2.34.1 > Thanks, SJ
On 2023/9/18 13:33, SeongJae Park wrote: > Hi Jinjie, > > > Thank you for this patchset! > > On Mon, 18 Sep 2023 13:10:43 +0800 Jinjie Ruan <ruanjinjie@huawei.com> wrote: > >> 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 and it causes below >> memory leak. So use damon_free_region() to free it. >> >> 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 > > Nice finding! Could you please share just a brief more detail about above cool > output, e.g., just the name of the tool you used, so that others can learn it > from your awesome commit message? > >> >> 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> >> --- >> mm/damon/core-test.h | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h >> index 6cc8b245586d..255f8c925c00 100644 >> --- a/mm/damon/core-test.h >> +++ b/mm/damon/core-test.h >> @@ -34,6 +34,7 @@ static void damon_test_regions(struct kunit *test) >> KUNIT_EXPECT_EQ(test, 0u, damon_nr_regions(t)); >> >> damon_free_target(t); >> + damon_free_region(r); > > There is damon_destroy_region() function, which simply calls damon_del_region() > and damon_free_region(). Unless there is needs to access the region before > removing from the region, doing memory return together via the function is > recommended. > > And this test code calls damon_del_region() just beofre above > KUNIT_EXPECT_EQ(). Hence, I think replacing the damon_del_region() call with > damon_destroy_region() rather than calling damon_free_region() may be simpler > and shorter. Could you please do so? Sure. Thank you very much! > >> } >> >> static unsigned int nr_damon_targets(struct damon_ctx *ctx) >> @@ -316,6 +317,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); > > This looks nice. Thank you for fixing this! > >> } >> >> static void damon_test_set_attrs(struct kunit *test) >> -- >> 2.34.1 >> > > Thanks, > SJ
diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index 6cc8b245586d..255f8c925c00 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -34,6 +34,7 @@ static void damon_test_regions(struct kunit *test) KUNIT_EXPECT_EQ(test, 0u, damon_nr_regions(t)); damon_free_target(t); + damon_free_region(r); } static unsigned int nr_damon_targets(struct damon_ctx *ctx) @@ -316,6 +317,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)