From nobody Mon Jun 8 07:21:49 2026 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (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 E3B0A7261A for ; Mon, 1 Jun 2026 03:24:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780284261; cv=none; b=ThCLXCPqZKyD78RaN6moqlNhrRGcFS4KSrvFvGbx17PtBjgemvIMUPnaIXBxTfxQVfcPtlQ3TNeDeKyEVX6IMgHABYuHZWTtm0J+xldE6A1/ChqPZhPbLHqFT3eZFYUojB97HsTmaJkWHBdEfLKUBiV1QBHnaXj8Ghih5fINlt8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780284261; c=relaxed/simple; bh=DGxVSbQst1w2I4LgcHpwOumpFk1YxGjQUD9BOEiqh4Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PwSYWlH3qklGVtaYgLijEe/2iC4+nboAmCyOIJc8BEw0OUUi7kBtz3rDlyDVaNxfDvh88B1PU/FDj4sn1EMfaLNABoyKBms4NpHmDMAaRka6jB8MWixM/2p/gCZbi8LMbmwlGfBrr86thLw8JYyU3aE/nknE7UlJeT6zm/BGScQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Hl2Ut3C4; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Hl2Ut3C4" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780284258; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A0eHW6gzjNPUtuJqQkMXg8OwcF2zJjUTNGVxRHFSBI0=; b=Hl2Ut3C4+vuq5qP49vk5424zEavISwmgYSN5PlBHStrCTykZ5stliQKvKHa655/N4sn9aC iXrpzrqtww4g72H49h3pQON10mwAHF7AHINgPIhHYdA41MabgcfoI5jV6NbxkiwveV3qt2 1TfWbS6iB+tUXAwXAflfGHKM8bzYrNc= From: Kunwu Chan To: sj@kernel.org, shuah@kernel.org Cc: damon@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Kunwu Chan , Wang Lian Subject: [PATCH v2 1/3] selftests/damon: prevent cross-context state pollution in DamonCtx Date: Mon, 1 Jun 2026 11:23:12 +0800 Message-ID: <20260601032314.424013-2-kunwu.chan@linux.dev> In-Reply-To: <20260601032314.424013-1-kunwu.chan@linux.dev> References: <20260601032314.424013-1-kunwu.chan@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Kunwu Chan DamonCtx.__init__() uses mutable default values for monitoring_attrs, targets, and schemes. In Python these are evaluated once at function definition time, so multiple DamonCtx instances can unintentionally share the same lists and DamonAttrs instance. Replace the mutable defaults with None sentinels and initialize the objects when needed. Co-developed-by: Wang Lian Signed-off-by: Wang Lian Signed-off-by: Kunwu Chan Reviewed-by: SeongJae Park --- tools/testing/selftests/damon/_damon_sysfs.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/= selftests/damon/_damon_sysfs.py index 8b12cc048440..2f6f2699db25 100644 --- a/tools/testing/selftests/damon/_damon_sysfs.py +++ b/tools/testing/selftests/damon/_damon_sysfs.py @@ -624,17 +624,23 @@ class DamonCtx: pause =3D None idx =3D None =20 - def __init__(self, ops=3D'paddr', monitoring_attrs=3DDamonAttrs(), tar= gets=3D[], - schemes=3D[], pause=3DFalse): + def __init__(self, ops=3D'paddr', monitoring_attrs=3DNone, targets=3DN= one, + schemes=3DNone, pause=3DFalse): self.ops =3D ops + if monitoring_attrs is None: + monitoring_attrs =3D DamonAttrs() self.monitoring_attrs =3D monitoring_attrs self.monitoring_attrs.context =3D self =20 + if targets is None: + targets =3D [] self.targets =3D targets for idx, target in enumerate(self.targets): target.idx =3D idx target.context =3D self =20 + if schemes is None: + schemes =3D [] self.schemes =3D schemes for idx, scheme in enumerate(self.schemes): scheme.idx =3D idx --=20 2.43.0 From nobody Mon Jun 8 07:21:49 2026 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (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 9F2AC7261A for ; Mon, 1 Jun 2026 03:24:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780284272; cv=none; b=M4IqJzhba6SDcDtRtxZ015S3zYD7E21sN0nKppyvqxYPY7GGr1VL5tgegNoNqMoUxwiUOoUN6RZU4rabPqF4BbjjzcjH0oHasxIe7k7MLSTlQpgQBwTv82T4WRbzCxNheIbF7uGF2hRrO57M/hLj8aVH1Lxw75BW7G/JL2TwyQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780284272; c=relaxed/simple; bh=yD1CcD0uANUt41ddJVjBX0yXejSTASYIhTv+ME8ByFA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WGjPf60GYvAKZjHQF0DNIoV/MbBSWLbxVTVmLvXizISkK4sJQqCzcCLQz8gJ/ETciujTUdiLXSTg0gXBt+XFl1RM50+xSz54pp20wGYgXcC4KUuUOo+5Tqctb6YMgTiveMVE0lSbm7Y5v9D9R5Z+Ab1Sbu5vRz6wzlA/AoKOqSY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=H2xUahCb; arc=none smtp.client-ip=91.218.175.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="H2xUahCb" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780284268; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zaY8XSpncw1tdxqTmSy3mDhJYgUUKeHixcd29qyX1Is=; b=H2xUahCbt1iXlMW5JNxoY9flDV8GU89RfU2uS/yDewhaLPy+mIOnA2jOK+bVt/MAzr8oL2 JAFvuW7BZach4p1MKh9jxkcZxwCvtJGylilX4bEQSd3b74tpTw0SOVC5Nox8FJzlYN2IER jl16BfWBb7c9yi0NnvkjuwOBKG0G/VM= From: Kunwu Chan To: sj@kernel.org, shuah@kernel.org Cc: damon@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Kunwu Chan , Wang Lian Subject: [PATCH v2 2/3] selftests/damon/damos_tried_regions: fix expectation output and join TypeError Date: Mon, 1 Jun 2026 11:23:13 +0800 Message-ID: <20260601032314.424013-3-kunwu.chan@linux.dev> In-Reply-To: <20260601032314.424013-1-kunwu.chan@linux.dev> References: <20260601032314.424013-1-kunwu.chan@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Kunwu Chan The expectation print has wrong operator precedence: '%' binds before the conditional expression, so the else branch prints 'not met' without the prefix 'expectation (>=3D 14) is'. Add parentheses to fix it. Also, '\n'.join() on the list of ints raises TypeError; convert to str in the list comprehension. Co-developed-by: Wang Lian Signed-off-by: Wang Lian Signed-off-by: Kunwu Chan Reviewed-by: SeongJae Park --- tools/testing/selftests/damon/damos_tried_regions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/damon/damos_tried_regions.py b/tools/t= esting/selftests/damon/damos_tried_regions.py index 3b347eb28bd2..d6472e6a6e08 100755 --- a/tools/testing/selftests/damon/damos_tried_regions.py +++ b/tools/testing/selftests/damon/damos_tried_regions.py @@ -55,10 +55,10 @@ def main(): collected_nr_regions.sort() sample =3D collected_nr_regions[4] print('50-th percentile nr_regions: %d' % sample) - print('expectation (>=3D 14) is %s' % 'met' if sample >=3D 14 else 'no= t met') + print('expectation (>=3D 14) is %s' % ('met' if sample >=3D 14 else 'n= ot met')) if collected_nr_regions[4] < 14: print('full nr_regions:') - print('\n'.join(collected_nr_regions)) + print('\n'.join(['%d' % x for x in collected_nr_regions])) exit(1) =20 if __name__ =3D=3D '__main__': --=20 2.43.0 From nobody Mon Jun 8 07:21:49 2026 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (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 3E0B21CEAC2 for ; Mon, 1 Jun 2026 03:24:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780284277; cv=none; b=T+WW+5WoW50K00jyvsVw2DWZemd/cyqrTo21FliuNPn/u6j9JUitcpsyxxVVIcPbtT62w3J3Egd21Gtg9YyEQlbLCX3AUFbIKYUAkE2FGO++p69v4CLMBtRk20L206QgmQ55m8dziuQQrLqtLh7OAUGYoZggHrCvLFsqEoFsGlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780284277; c=relaxed/simple; bh=/KH3aChOBfgFlGGyfxL03i9RqigtaHLERZayfOZo/vg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SJbgFC4eyydHUVd4sFGJtbBtKxM9z+SzfI+X5SQBytdmjYCAfCFfVL+2ZTbnMNk4CoR61+3rrvxQAzTpvbtF6lDBcOQvRGaq0sls7fNkQ+wB0VzPbDBEYQAP4dPOX1NjyIZZZ7+VYGgJqDkOoZgzyKKoPIfvC4dxBQWGEgFVr3c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=HgE+EHcj; arc=none smtp.client-ip=91.218.175.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="HgE+EHcj" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780284274; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BpJqpbF9ApLNylCyq0RsExKHsHO66f1ta9bSPuMNQvg=; b=HgE+EHcjd9c4DxL4XphF3dM/ndwLGCizdi8lItx1SrPwXrYb0ojr3vggiEfDPROoDdjIo4 h9ZewjJ0EUXsA7PB3zHQzti+N9cdyjcDxfE3dCbdsZBJdxempVZFSvLWXRV7xMKgerXYuz b+WxxGyyG/VOzV3D6+urxj1qmMuLJq4= From: Kunwu Chan To: sj@kernel.org, shuah@kernel.org Cc: damon@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Kunwu Chan , Wang Lian Subject: [PATCH v2 3/3] selftests/damon: fix dead code, skipped checks, and broken lookups Date: Mon, 1 Jun 2026 11:23:14 +0800 Message-ID: <20260601032314.424013-4-kunwu.chan@linux.dev> In-Reply-To: <20260601032314.424013-1-kunwu.chan@linux.dev> References: <20260601032314.424013-1-kunwu.chan@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Kunwu Chan 'hugeapge_size' in drgn_dump_damon_status.py was a dead elif branch. $fail_reason in sysfs.sh was undefined, silently emptying the error message. 'exit' instead of 'exist' in sysfs.sh skipped a file existence check. 'nohugeapge' in sysfs.py broke an action dict lookup. Fix other wrong strings in the same files. Co-developed-by: Wang Lian Signed-off-by: Wang Lian Signed-off-by: Kunwu Chan Reviewed-by: SeongJae Park --- tools/testing/selftests/damon/_damon_sysfs.py | 2 +- tools/testing/selftests/damon/damos_apply_interval.py | 2 +- tools/testing/selftests/damon/damos_quota_goal.py | 2 +- tools/testing/selftests/damon/drgn_dump_damon_status.py | 2 +- tools/testing/selftests/damon/sysfs.py | 4 ++-- tools/testing/selftests/damon/sysfs.sh | 6 +++--- .../sysfs_update_schemes_tried_regions_wss_estimation.py | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/= selftests/damon/_damon_sysfs.py index 2f6f2699db25..f6127081dfb2 100644 --- a/tools/testing/selftests/damon/_damon_sysfs.py +++ b/tools/testing/selftests/damon/_damon_sysfs.py @@ -837,7 +837,7 @@ class Kdamond: for goal in scheme.quota.goals: err =3D goal.stage() if err is not None: - print('commit_schemes_quota_goals failed stagign: = %s'% + print('commit_schemes_quota_goals failed staging: = %s'% err) exit(1) return write_file(os.path.join(self.sysfs_dir(), 'state'), diff --git a/tools/testing/selftests/damon/damos_apply_interval.py b/tools/= testing/selftests/damon/damos_apply_interval.py index f04d43702481..0f2f36584e48 100755 --- a/tools/testing/selftests/damon/damos_apply_interval.py +++ b/tools/testing/selftests/damon/damos_apply_interval.py @@ -56,7 +56,7 @@ def main(): # Because the second scheme was having the apply interval that is ten = times # lower than that of the first scheme, the second scheme should be tri= ed # about ten times more frequently than the first scheme. For possible - # timing errors, check if it was at least nine times more freuqnetly t= ried. + # timing errors, check if it was at least nine times more frequently t= ried. ratio =3D nr_tried_stats[1] / nr_tried_stats[0] if ratio < 9: print('%d / %d =3D %f (< 9)' % diff --git a/tools/testing/selftests/damon/damos_quota_goal.py b/tools/test= ing/selftests/damon/damos_quota_goal.py index f76e0412b564..661e4ba4765a 100755 --- a/tools/testing/selftests/damon/damos_quota_goal.py +++ b/tools/testing/selftests/damon/damos_quota_goal.py @@ -66,7 +66,7 @@ def main(): # effective quota was already minimum that cannot be more redu= ced if expect_increase is False and last_effective_bytes =3D=3D 1: continue - print('efective bytes not changed: %d' % goal.effective_bytes) + print('effective bytes not changed: %d' % goal.effective_bytes) exit(1) =20 increased =3D last_effective_bytes < goal.effective_bytes diff --git a/tools/testing/selftests/damon/drgn_dump_damon_status.py b/tool= s/testing/selftests/damon/drgn_dump_damon_status.py index 972948e6215f..26b207e44268 100755 --- a/tools/testing/selftests/damon/drgn_dump_damon_status.py +++ b/tools/testing/selftests/damon/drgn_dump_damon_status.py @@ -163,7 +163,7 @@ def damos_filter_to_dict(damos_filter): int(damos_filter.addr_range.end)] elif type_ =3D=3D 'target': dict_['target_idx'] =3D int(damos_filter.target_idx) - elif type_ =3D=3D 'hugeapge_size': + elif type_ =3D=3D 'hugepage_size': dict_['sz_range'] =3D [int(damos_filter.sz_range.min), int(damos_filter.sz_range.max)] return dict_ diff --git a/tools/testing/selftests/damon/sysfs.py b/tools/testing/selftes= ts/damon/sysfs.py index aa03a1187489..99412f0d31f3 100755 --- a/tools/testing/selftests/damon/sysfs.py +++ b/tools/testing/selftests/damon/sysfs.py @@ -119,7 +119,7 @@ def assert_access_pattern_committed(pattern, dump): 'max_nr_accesses', dump) assert_true(dump['min_age_region'] =3D=3D pattern.age[0], 'min_age_reg= ion', dump) - assert_true(dump['max_age_region'] =3D=3D pattern.age[1], 'miaxage_reg= ion', + assert_true(dump['max_age_region'] =3D=3D pattern.age[1], 'max_age_reg= ion', dump) =20 def assert_scheme_committed(scheme, dump): @@ -129,7 +129,7 @@ def assert_scheme_committed(scheme, dump): 'cold': 1, 'pageout': 2, 'hugepage': 3, - 'nohugeapge': 4, + 'nohugepage': 4, 'collapse': 5, 'lru_prio': 6, 'lru_deprio': 7, diff --git a/tools/testing/selftests/damon/sysfs.sh b/tools/testing/selftes= ts/damon/sysfs.sh index 78f4badb5beb..2eaaa5ae3c5e 100755 --- a/tools/testing/selftests/damon/sysfs.sh +++ b/tools/testing/selftests/damon/sysfs.sh @@ -3,7 +3,7 @@ =20 source _common.sh =20 -# Kselftest frmework requirement - SKIP code is 4. +# Kselftest framework requirement - SKIP code is 4. ksft_skip=3D4 =20 ensure_write_succ() @@ -28,7 +28,7 @@ ensure_write_fail() =20 if (echo "$content" > "$file") 2> /dev/null then - echo "writing $content to $file succeed ($fail_reason)" + echo "writing $content to $file succeeded ($reason)" echo "expected failure because $reason" exit 1 fi @@ -363,7 +363,7 @@ test_context() { context_dir=3D$1 ensure_dir "$context_dir" "exist" - ensure_file "$context_dir/avail_operations" "exit" 400 + ensure_file "$context_dir/avail_operations" "exist" 400 ensure_file "$context_dir/operations" "exist" 600 ensure_file "$context_dir/addr_unit" "exist" 600 ensure_file "$context_dir/pause" "exist" 600 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 35c724a63f6c..16fdc6e7fc56 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 @@ -7,7 +7,7 @@ import time import _damon_sysfs =20 def pass_wss_estimation(sz_region): - # access two regions of given size, 2 seocnds per each region + # access two regions of given size, 2 seconds per each region proc =3D subprocess.Popen( ['./access_memory', '2', '%d' % sz_region, '2000', 'repeat']) kdamonds =3D _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond( --=20 2.43.0