linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: Jinjie Ruan <ruanjinjie@huawei.com>
Cc: 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
Subject: Re: [PATCH RESEND 2/2] mm/damon/core-test: Fix memory leak in damon_new_ctx()
Date: Mon, 18 Sep 2023 05:43:26 +0000	[thread overview]
Message-ID: <20230918054326.74929-1-sj@kernel.org> (raw)
In-Reply-To: <20230918051044.3814018-3-ruanjinjie@huawei.com>

Hi Jinjie,

On Mon, 18 Sep 2023 13:10:44 +0800 Jinjie Ruan <ruanjinjie@huawei.com> wrote:

> The damon_ctx which is allocated by kzalloc() in damon_new_ctx() in
> damon_test_ops_registration() and damon_test_set_attrs() are not freed and
> it causes below memory leak. So use damon_destroy_ctx() to free it.
> 
> unreferenced object 0xffff2b49c6968800 (size 512):
>   comm "kunit_try_catch", pid 350, jiffies 4294895294 (age 557.028s)
>   hex dump (first 32 bytes):
>     88 13 00 00 00 00 00 00 a0 86 01 00 00 00 00 00  ................
>     00 87 93 03 00 00 00 00 0a 00 00 00 00 00 00 00  ................
>   backtrace:
>     [<0000000088e71769>] slab_post_alloc_hook+0xb8/0x368
>     [<0000000073acab3b>] __kmem_cache_alloc_node+0x174/0x290
>     [<00000000b5f89cef>] kmalloc_trace+0x40/0x164
>     [<00000000eb19e83f>] damon_new_ctx+0x28/0xb4
>     [<00000000daf6227b>] damon_test_ops_registration+0x34/0x328
>     [<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 0xffff2b49c1a9cc00 (size 512):
>   comm "kunit_try_catch", pid 356, jiffies 4294895306 (age 557.000s)
>   hex dump (first 32 bytes):
>     88 13 00 00 00 00 00 00 a0 86 01 00 00 00 00 00  ................
>     00 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00  ................
>   backtrace:
>     [<0000000088e71769>] slab_post_alloc_hook+0xb8/0x368
>     [<0000000073acab3b>] __kmem_cache_alloc_node+0x174/0x290
>     [<00000000b5f89cef>] kmalloc_trace+0x40/0x164
>     [<00000000eb19e83f>] damon_new_ctx+0x28/0xb4
>     [<00000000058495c4>] damon_test_set_attrs+0x30/0x1a8
>     [<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

Same to the comment on the first patch of this patchset, simply letting others
know the name of the tool you used for making this cool output could be
helpful.  Could you please add it?

Also, I prefer adding four spaces indent to quoted command outputs on commit
messages.  Could you please add that indentation?

Also, I cannot 'git am' this patch on top of mm-unstable[1].  Could you please
double check and rebase on latest mm-unstable if I din't miss something?

[1] https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/log/?h=mm-unstable

> 
> Fixes: d1836a3b2a9a ("mm/damon/core-test: initialise context before test in damon_test_set_attrs()")
> Fixes: 4f540f5ab4f2 ("mm/damon/core-test: add a kunit test case for ops registration")
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
>  mm/damon/core-test.h | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h
> index 255f8c925c00..ce86ed30fb47 100644
> --- a/mm/damon/core-test.h
> +++ b/mm/damon/core-test.h
> @@ -266,6 +266,8 @@ static void damon_test_ops_registration(struct kunit *test)
>  
>  	/* Check double-registration failure again */
>  	KUNIT_EXPECT_EQ(test, damon_register_ops(&ops), -EINVAL);
> +
> +	damon_destroy_ctx(c);
>  }
>  
>  static void damon_test_set_regions(struct kunit *test)
> @@ -342,6 +344,8 @@ static void damon_test_set_attrs(struct kunit *test)
>  	invalid_attrs = valid_attrs;
>  	invalid_attrs.aggr_interval = 4999;
>  	KUNIT_EXPECT_EQ(test, damon_set_attrs(c, &invalid_attrs), -EINVAL);
> +
> +	damon_destroy_ctx(c);
>  }
>  
>  static void damos_test_new_filter(struct kunit *test)

Other than above comments, changes look good to me.

> -- 
> 2.34.1
> 

Thanks,
SJ


  parent reply	other threads:[~2023-09-18  5:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-18  5:10 [PATCH RESEND 0/2] mm/damon/core-test: Fix memory leaks in core-test Jinjie Ruan
2023-09-18  5:10 ` [PATCH RESEND 1/2] mm/damon/core-test: Fix memory leak in damon_new_region() Jinjie Ruan
2023-09-18  5:33   ` SeongJae Park
2023-09-18  7:13     ` Ruan Jinjie
2023-09-18  5:10 ` [PATCH RESEND 2/2] mm/damon/core-test: Fix memory leak in damon_new_ctx() Jinjie Ruan
2023-09-18  5:38   ` Feng Tang
2023-09-18  5:43   ` SeongJae Park [this message]
2023-09-18  7:12     ` Ruan Jinjie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230918054326.74929-1-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=brendan.higgins@linux.dev \
    --cc=damon@lists.linux.dev \
    --cc=feng.tang@intel.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ruanjinjie@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox