From patchwork Mon Sep 18 07:47:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13389075 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54862CD37B0 for ; Mon, 18 Sep 2023 07:48:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 881BB6B02A5; Mon, 18 Sep 2023 03:48:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 832006B02A6; Mon, 18 Sep 2023 03:48:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D2906B02A8; Mon, 18 Sep 2023 03:48:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5F0E36B02A5 for ; Mon, 18 Sep 2023 03:48:51 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 212AC140BEB for ; Mon, 18 Sep 2023 07:48:51 +0000 (UTC) X-FDA: 81248941662.27.2A7491A Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf26.hostedemail.com (Postfix) with ESMTP id 3FA77140004 for ; Mon, 18 Sep 2023 07:48:47 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf26.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695023329; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cDF9VZz6PRkEnlooLIfOgQsCCTw40kEWHQZ70T/KLOc=; b=JnKCAqWaiQsZOWKD86K2l6O8e+rMCHKGeRVt3ZbF9xb+uhF+4ZJ9iHVhti1rPwYqUHfhYe Y6sCKBGLrcw1tiJPQIgObY1LANYW/mZHW2xLFWpfWd9wpsjiS/bQKBbHCJzUaorg9b2b4N 6g6rHLfh6IZBf6fI1JxYemsozEHKVpY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf26.hostedemail.com: domain of ruanjinjie@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=ruanjinjie@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695023329; a=rsa-sha256; cv=none; b=TXzSe3CNwsy6Ejv/Ofo9yRqQfXKsFG6+Er3cCtU06Cy7+KCNLujeVz/FNo8x9NFMiB6mqi 4L2sidb1YMAsNx/T5crCRvTE+bPAPqZxoGRvJKrkQvHlUzaDEI0wW1/UPp3ySvGsEUDRDu EoBB2Eg+xvbhPh65hZhfkCdVioMZgRs= 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 To: , , , , , , , , CC: 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 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-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3FA77140004 X-Stat-Signature: 9bgdczjpafej5f1fh34ayk7cyrmmhi5t X-Rspam-User: X-HE-Tag: 1695023327-562387 X-HE-Meta: U2FsdGVkX198vbxp2ZSePSKtv+Iq7Q410AvWjkmfgT6ohcaDd9Ep3TLm/83ZMRIGZlsVf5ra5WOBWXxbS+Wymlw2kImkSK64C5I+uNJg2ZuIXSrYdFvupjqFDZ8Ttc7RiiB8BQUnL17z/7poMHwE/oDOR8TrGT00+sZnzV1auEdhLFfxcV3FAEkboZckKADcaUg1+exUWlHZpwktsHkFzG+9S+HOxPnce7HWs7Kw9SZtT1xNNcYv3zC5pLCbqj9sdFE+9P0qjndlBzAkgUX0vf7lOko1Q/rUAc6B7QZR4k42EH6azBFNGYGf+pXPC4EhO0TVoRE+C6c6XQbZ+oJQ1N0Tpjy8o+AF+KuKCAVb5wuZe9vRO5Uke29aAKzXBHhu0hL83V7nP+dpUSefSOkHgEECTYGc6K15AQc5pOGjXh7anglklQlMWc+HMlh6yLg/JGRd+x6UoOpKjnM35B/hGqpKVy6/X8JJymrgjkOnQO9vu2e6WnTewVbtPeAEF1Pf7pX5Zg1YHEZQFSVM75CViNKsHp1lI9+VX1RbvtEeYn/kHYI4WR5PfQqt2ME2jQVnQJ/8teLWuT99u230Cr2+A8aWDY0WCFcrPhaKgsn90b4/oqLr+EWQbI+clFB3UWrtP16jW90QtF9N9zhtJsHa5DHhG/yVYZesSF0PqJwI2U6Dannh9Ao3ZZ/goDJyaPebosrDQe+FTRZuW0ZFNmOaz6TN2ynFddTWfhp2jsu0tBF9LY/GIXgbjo9yRxik95ObbPt3NHTGsQRnTgw1YobnHWLmD2jAzftmXa3c9XHtzt9bF9A5omXlpRXXaCx2elJrGItnsJnuT1eNf6vTMmoEFOgJFVHLcZqYKYAaAbRLU4Ps1de5vy3UkQFZHl6UM5LtkGAOI3dTiJqW4iWcl7vEATj1SxzcBpbbqyt9yeHnH/0pHZZ4SGmSF9daonNVHl6e9xpQIN6JX0f5aeIQ83M XaPMAt8d 9v7UUJfXl1r7KtwCv+V8Uf/bhZlVefXdQHfKNk4nmZ8h1XiCf1vz9rpreUKlCqWy5fzT1x+jr7movVuCS4YyAWqoNTE2XyhmoASaC1DyO3ceF0nGnDjL+IH8D4X5ZkhEiP53Vof5X9k6U8/UOUmmCwmxPOkQ0ZkmNeRyrMoffjMOzOF1YJAKfv7vBeEGjbdOKGcjp X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: SeongJae Park --- 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(-) 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)