From nobody Sat Apr 4 00:05:54 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 C345336AB61; Sun, 22 Mar 2026 15:57: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=1774195060; cv=none; b=dy/LPtm5nxfFt5y+YHg6K2hmLk0urIzGxtiuys6CkTMlHfpPgs9uUN8YCVHcR2AZmlRUuOWMG0eQ+MgCkoZuTnAVQBz+eE6rug6EX85HgTRFaUAqWYY9X+ZWfbxA8A7fthzdzT6VTXPjvInMB1HTZ5vIFkBKUt5Pj9cQ7iE+md8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774195060; c=relaxed/simple; bh=dT0Co/dTQSMuQWLCRwci5Vw0M3Z0t6s+AmNwdu4waoM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Oahyl73N3/Sa57FCDpn4BwDrVCcafcZvb3BothS4eL9X5VFOMl/KpDfKRhSROdEZQ1G8mZ4v9m1V5SIyez5HhzD9+G4s6+RyGFufuu1pthkp/Dv8Yw+8fonGy/6ONO3+trTVE5bF/MQCoacwgt1F1jtkKLQz5bHrkCt9iZujljY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CQRMJZzA; 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="CQRMJZzA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C550C2BCC4; Sun, 22 Mar 2026 15:57:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774195060; bh=dT0Co/dTQSMuQWLCRwci5Vw0M3Z0t6s+AmNwdu4waoM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CQRMJZzAgy5OgtrWB6C6XjwLHceTrAXQUqzUppUpdMEfG2oSL//F9gE4sFVPETCwo wN1trbWGzeNMRD5Mw4+ex1fMDCn9SeDSP2Vh49gb3yAtuRmWkM+qZD5BjnuxpseAcB 43n+HtbZDDBSVXWeh3oZEzWCLy58ld0+8hX2ybPAAn47tw1YbPRXHDjPqQO5mBQO81 k9auOr/SF6gKBbjyq55E0y9i8mLUAbN5hLBiWMd7JJmLAuGuoM9/ywtWolInx7yhaK Bq3LB6hl0Dom9/8AFF5KM7i6LVj7bTBBujloM32/UPP56cO/lrv92FE9BtgNt3ukQS 09cuQUksGreAQ== From: SeongJae Park To: Cc: SeongJae Park , Shuah Khan , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v4 10/10] selftets/damon/sysfs.py: pause DAMON before dumping status Date: Sun, 22 Mar 2026 08:57:24 -0700 Message-ID: <20260322155728.81434-11-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260322155728.81434-1-sj@kernel.org> References: <20260322155728.81434-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" The sysfs.py test commits DAMON parameters, dump the internal DAMON state, and show if the parameters are committed as expected using the dumped state. While the dumping is ongoing, DAMON is alive. It can make internal changes including addition and removal of regions. It can therefore make a race that can result in false test results. Pause DAMON execution during the state dumping to avoid such races. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/sysfs.py | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tools/testing/selftests/damon/sysfs.py b/tools/testing/selftes= ts/damon/sysfs.py index e6d34ba05893f..5f00e97f019f4 100755 --- a/tools/testing/selftests/damon/sysfs.py +++ b/tools/testing/selftests/damon/sysfs.py @@ -193,18 +193,55 @@ def assert_ctx_committed(ctx, dump): assert_true(dump['pause'] =3D=3D ctx.pause, 'pause', dump) =20 def assert_ctxs_committed(kdamonds): + ctxs_paused_for_dump =3D [] + kdamonds_paused_for_dump =3D [] + # pause for safe state dumping + for kd in kdamonds.kdamonds: + for ctx in kd.contexts: + if ctx.pause is False: + ctx.pause =3D True + ctxs_paused_for_dump.append(ctx) + if not kd in kdamonds_paused_for_dump: + kdamonds_paused_for_dump.append(kd) + if kd in kdamonds_paused_for_dump: + err =3D kd.commit() + if err is not None: + print('pause fail (%s)' % err) + kdamonds.stop() + exit(1) + status, err =3D dump_damon_status_dict(kdamonds.kdamonds[0].pid) if err is not None: print(err) kdamonds.stop() exit(1) =20 + # resume contexts paused for safe state dumping + for ctx in ctxs_paused_for_dump: + ctx.pause =3D False + if kd in kdamonds_paused_for_dump: + err =3D kd.commit() + if err is not None: + print('resume fail (%s)' % err) + kdamonds.stop() + exit(1) + + # restore for comparison + for ctx in ctxs_paused_for_dump: + ctx.pause =3D True + ctxs =3D kdamonds.kdamonds[0].contexts dump =3D status['contexts'] assert_true(len(ctxs) =3D=3D len(dump), 'ctxs length', dump) for idx, ctx in enumerate(ctxs): assert_ctx_committed(ctx, dump[idx]) =20 + # restore for the caller + for kd in kdamonds.kdamonds: + for ctx in kd.contexts: + if ctx in ctxs_paused_for_dump: + ctx.pause =3D False + def main(): kdamonds =3D _damon_sysfs.Kdamonds( [_damon_sysfs.Kdamond( @@ -302,6 +339,7 @@ def main(): print('kdamond start failed: %s' % err) exit(1) kdamonds.kdamonds[0].contexts[0].targets[1].obsolete =3D True + kdamonds.kdamonds[0].contexts[0].pause =3D True kdamonds.kdamonds[0].commit() del kdamonds.kdamonds[0].contexts[0].targets[1] assert_ctxs_committed(kdamonds) --=20 2.47.3