From nobody Sun Feb 8 05:40:33 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E13C26E708; Sat, 17 Jan 2026 02:07:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768615659; cv=none; b=WLlww0G7UvlD1g7V8gP+H3PGSiINfQ9POmK/h3DQte/BHeeLDSJBmqc0YW8U+S8mXua8MMT1CFTi7OGjbtf5FXBv5EOx3rwxnMHbp31B60jykWQmsMmQ1HCTxct+EVXgWAvxMgiAwvIShOyZCxbLqIXe7QZblxQM9zStDNUzNt0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768615659; c=relaxed/simple; bh=C2QHcQZHqTAQDaO9DNebGqZ3A/aRqpTbgJDZ81lxP1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lCjJ2ELhdR2E+uTptDebNzjTtaAVvti9OhyC/ST94IO04Acu2j8/m+k9XMLFJYA4nJy16B2qVO+LGi+O/DMpMiUOpOgPwqYFs5iVVSYXJoSN+NO6N+QBEJETNN76xuVOLmpvHV03FFOvLR4UkkcST6UeLK/EvO9XBft8ivlCXdQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EJXm0FAm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EJXm0FAm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C06DC16AAE; Sat, 17 Jan 2026 02:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768615659; bh=C2QHcQZHqTAQDaO9DNebGqZ3A/aRqpTbgJDZ81lxP1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EJXm0FAmw5o7Zyyw0HQ5vmJJXUcfUtEfBgHFoq9+OjGCg59S0H6FkN0JT9lptr+7d 0ePzKy/5IaJIzOHvvogDrFClUZEYUmTu0YJXcHrG3lGwiKUC9K2i4af9MCsMlUQFc+ RX3vnKMtcB0XTPE0RsZaWxMtbBUa3VsAGhcWNGRBzdRhjpqKE006BZRJnb865ci5Ei PHkOttph3EjUwUtsgx9XLQ6Bvg2TVUieHhuGd7mfm03fFQAGMo8WgEorSrxe06juXV uDdIsESmoRp0InW3CqGrtyzM+R8XWAkVlC7FMgCLfO+fB3/Md8SVqfzO5ErfKX6+aW DoimfPQSCYa9A== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Shuah Khan , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/5] selftests/damon/sysfs_memcg_path_leak.sh: use kmemleak Date: Fri, 16 Jan 2026 18:07:24 -0800 Message-ID: <20260117020731.226785-2-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260117020731.226785-1-sj@kernel.org> References: <20260117020731.226785-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" sysfs_memcg_path_leak.sh determines if the memory leak has happened by seeing if Slab size on /proc/meminfo increases more than expected after an action. Depending on the system and background workloads, the reasonable expectation varies. For the reason, the test frequently shows intermittent failures. Use kmemleak, which is much more reliable and correct, instead. Signed-off-by: SeongJae Park --- .../selftests/damon/sysfs_memcg_path_leak.sh | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/damon/sysfs_memcg_path_leak.sh b/tools= /testing/selftests/damon/sysfs_memcg_path_leak.sh index 64c5d8c518a4..33a7ff43ed6c 100755 --- a/tools/testing/selftests/damon/sysfs_memcg_path_leak.sh +++ b/tools/testing/selftests/damon/sysfs_memcg_path_leak.sh @@ -14,6 +14,13 @@ then exit $ksft_skip fi =20 +kmemleak=3D"/sys/kernel/debug/kmemleak" +if [ ! -f "$kmemleak" ] +then + echo "$kmemleak not found" + exit $ksft_skip +fi + # ensure filter directory echo 1 > "$damon_sysfs/kdamonds/nr_kdamonds" echo 1 > "$damon_sysfs/kdamonds/0/contexts/nr_contexts" @@ -22,22 +29,17 @@ echo 1 > "$damon_sysfs/kdamonds/0/contexts/0/schemes/0/= filters/nr_filters" =20 filter_dir=3D"$damon_sysfs/kdamonds/0/contexts/0/schemes/0/filters/0" =20 -before_kb=3D$(grep Slab /proc/meminfo | awk '{print $2}') - -# try to leak 3000 KiB -for i in {1..102400}; +# try to leak 128 times +for i in {1..128}; do echo "012345678901234567890123456789" > "$filter_dir/memcg_path" done =20 -after_kb=3D$(grep Slab /proc/meminfo | awk '{print $2}') -# expect up to 1500 KiB free from other tasks memory -expected_after_kb_max=3D$((before_kb + 1500)) - -if [ "$after_kb" -gt "$expected_after_kb_max" ] +echo scan > "$kmemleak" +kmemleak_report=3D$(cat "$kmemleak") +if [ "$kmemleak_report" =3D "" ] then - echo "maybe memcg_path are leaking: $before_kb -> $after_kb" - exit 1 -else exit 0 fi +echo "$kmemleak_report" +exit 1 --=20 2.47.3 From nobody Sun Feb 8 05:40:33 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD19E30F927; Sat, 17 Jan 2026 02:07:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768615659; cv=none; b=GbU096blcxh5k7XJkvoyWljZN2qI7HGvHut9XxV2wI7TFT2kOkijsefhbsVf5lo7f/qVsQFOuKphuBIQr1CYyGaUX+la+16PECub31T1LcmWZouvHbsWW6lQE+5OCKHHSlQ/lUaCte7kBQD3wZZooKlzAeX0Sck9G8Ia1qmDj/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768615659; c=relaxed/simple; bh=hotNE+mkKLh4E3ZrIzL4sCf5Wg0MeE2kOyjLK5ej2kg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eeHjIBizMGA1tV7CNbeU2NvUhNJTu8DYV3CRJP0ytRTWZcvbRSpd6VCtlKr4kHh0KdTfjvwQ9lv0gwdNL50j7YIJgnEhUUSvRIpm5whwQI76dF/nnMy536KJUkivf9T8jK1iqzP4On5uD9QXdVktF+V5jvsbSvYBbpSUI0jYhW4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cFgHni2f; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cFgHni2f" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8446FC19423; Sat, 17 Jan 2026 02:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768615659; bh=hotNE+mkKLh4E3ZrIzL4sCf5Wg0MeE2kOyjLK5ej2kg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cFgHni2fBFLxaEC3ayWzPAfAqtL435n6RT3GbJ0EFn8rFi4YlLAGRb1zj2eThEYIv keP/Y2hkwZwDxdmIWSPhk7LmY6CV+10esWPRC8JdsFlRygYvZp7mrDrZp+fbz8dg5q L9O+dBYohuLOvUdmylv+vu9ZSD1uz7qvyWQr3oBhWPZp/ttNabXHq/oKmeOsyxtBPA kdUWTZyD/isx884RtprXEYVzvhSJ2HDzoAhxahNsCrgxOhFF0s5WhC8lv/akPZRmRw 3eNPqeo94qInMmFaEAOgCejOGLYAKLL9j8NRbUIZ2SFngRMpnsH9mEUOX0Ume6hO/W YAvd4WjwQ20EQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Shuah Khan , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/5] selftests/damon/wss_estimation: test for up to 160 MiB working set size Date: Fri, 16 Jan 2026 18:07:25 -0800 Message-ID: <20260117020731.226785-3-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260117020731.226785-1-sj@kernel.org> References: <20260117020731.226785-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DAMON reads and writes Accessed bits of page tables without manual TLB flush for two reasons. First, it minimizes the overhead. Second, real systems that need DAMON are expected to be memory intensive enough to cause periodic TLB flushes. For test setups that use small test workloads, however, the system's TLB could be big enough to cover whole or most accesses of the test workload. In this case, no page table walk happens and DAMON cannot show any access from the test workload. The test workload for DAMON's working set size estimation selftest is such a case. It accesses only 10 MiB working set, and it turned out there are test setups that have TLBs large enough to cover the 10 MiB data accesses. As a result, the test fails depending on the test machine. Make it more reliable by trying larger working sets up to 160 MiB when it fails. Signed-off-by: SeongJae Park --- ...te_schemes_tried_regions_wss_estimation.py | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/damon/sysfs_update_schemes_tried_regio= ns_wss_estimation.py b/tools/testing/selftests/damon/sysfs_update_schemes_t= ried_regions_wss_estimation.py index 90ad7409a7a6..bf48ef8e5241 100755 --- a/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_= estimation.py +++ b/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_= estimation.py @@ -6,9 +6,8 @@ import time =20 import _damon_sysfs =20 -def main(): - # access two 10 MiB memory regions, 2 second per each - sz_region =3D 10 * 1024 * 1024 +def pass_wss_estimation(sz_region): + # access two regions of given size, 2 seocnds per each region proc =3D subprocess.Popen(['./access_memory', '2', '%d' % sz_region, '= 2000']) kdamonds =3D _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond( contexts=3D[_damon_sysfs.DamonCtx( @@ -36,20 +35,38 @@ def main(): =20 wss_collected.append( kdamonds.kdamonds[0].contexts[0].schemes[0].tried_bytes) + err =3D kdamonds.stop() + if err is not None: + print('kdamond stop failed: %s' % err) + exit(1) =20 wss_collected.sort() acceptable_error_rate =3D 0.2 for percentile in [50, 75]: sample =3D wss_collected[int(len(wss_collected) * percentile / 100= )] error_rate =3D abs(sample - sz_region) / sz_region - print('%d-th percentile (%d) error %f' % - (percentile, sample, error_rate)) + print('%d-th percentile error %f (expect %d, result %d)' % + (percentile, error_rate, sz_region, sample)) if error_rate > acceptable_error_rate: print('the error rate is not acceptable (> %f)' % acceptable_error_rate) print('samples are as below') print('\n'.join(['%d' % wss for wss in wss_collected])) - exit(1) + return False + return True + +def main(): + # DAMON doesn't flush TLB. If the system has large TLB that can cover + # whole test working set, DAMON cannot see the access. Test up to 160= MiB + # test working set. + sz_region_mb =3D 10 + max_sz_region_mb =3D 160 + while sz_region_mb <=3D max_sz_region_mb: + test_pass =3D pass_wss_estimation(sz_region_mb * 1024 * 1024) + if test_pass is True: + exit(0) + sz_region_mb *=3D 2 + exit(1) =20 if __name__ =3D=3D '__main__': main() --=20 2.47.3 From nobody Sun Feb 8 05:40:33 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22AA131159C; Sat, 17 Jan 2026 02:07:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768615660; cv=none; b=tT7D13dL7Zmy4cOAnXfoulZsjTeEu5YERKjwqGo8JF9J1utdsh2qkT4sQS9Fhbk7k1TeJt29nfNtIfIQ/kiUHMTSsJe9D4cJ6B6I+hZtuKVYrNU9kCs9/2kkRltC76EKat5itvQOnDQJEqqRTC5+TZrEYfoFmyXeOcXNebHbey0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768615660; c=relaxed/simple; bh=KPSyHpwr1RZ1sL9zrIc+8C+fgY9V82SnKK8ITdn75rs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cMItpn75CBCSnohcmvgCaVFMR2EONyeLqShx7w/3Ue8v1ePzbiE1aI6DYIaucQDZfJDSyou5NQqKPWIgIk/xPkiU7xdszw5WcTEdpJGikm6OrxbEEj3+FIYu6aQnUT9z4E3y9aCts4M+8wnQO/tYQikkK0Zv40QYzysEPqSF7BY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j7GLeKDj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="j7GLeKDj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE44BC4AF0B; Sat, 17 Jan 2026 02:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768615659; bh=KPSyHpwr1RZ1sL9zrIc+8C+fgY9V82SnKK8ITdn75rs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j7GLeKDjUJJag3xHYuo20Q9Oy/4IhpeJCwFSEsIEGhkJM4UAHZMtMrpDLcX7K4DU5 YvAv2YJEt6QyQmWxut7nZLrZe1Y+ClVlt7RlSET69B8PIq05SLwghW3kkb0Ir4VB1W mXI0rwNWHK8nJqReNPQquSZo9W/iW89hWsM5rZR3lgakkdQBdUmSTl7eNmRjX7M6iH g1Bi06uJVvP7tjK5tt9m4+WFC+MBU8ZpCCmX/PmnYTDjSK2Y9WO8ovN2v0JByO9btG 8BvDnVDYG1cyzjZTSSFWgxGq0rvUUqC9i25b5L6XAE2gwcJruZHChbLVaq4x6l5B2P 6Genz80mDUS9g== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Shuah Khan , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/5] selftests/damon/access_memory: add repeat mode Date: Fri, 16 Jan 2026 18:07:26 -0800 Message-ID: <20260117020731.226785-4-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260117020731.226785-1-sj@kernel.org> References: <20260117020731.226785-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 'access_memory' is an artificial memory access generator program that is used for a few DAMON selftests. It accesses a given number of regions one by one only once, and exits. Depending on systems, the test workload may exit faster than expected, making the tests unreliable. For reliable control of the artificial memory access pattern, add a mode to make it repeat running. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/access_memory.c | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/damon/access_memory.c b/tools/testing/= selftests/damon/access_memory.c index 56b17e8fe1be..567793b11107 100644 --- a/tools/testing/selftests/damon/access_memory.c +++ b/tools/testing/selftests/damon/access_memory.c @@ -8,6 +8,11 @@ #include #include =20 +enum access_mode { + ACCESS_MODE_ONCE, + ACCESS_MODE_REPEAT, +}; + int main(int argc, char *argv[]) { char **regions; @@ -15,10 +20,12 @@ int main(int argc, char *argv[]) int nr_regions; int sz_region; int access_time_ms; + enum access_mode mode =3D ACCESS_MODE_ONCE; + int i; =20 - if (argc !=3D 4) { - printf("Usage: %s