From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3F8F3DB334 for ; Tue, 2 Jun 2026 13:12:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780405944; cv=none; b=mRJ90mYC8rd9IFz4Tn+VkOMT+Y8dRbBs0vFug6UyUIfprbPuAzd2t8UZFrioUXDLz5r7AstqwNe3nMwzk0xD+I7WLMEdetrYQKioqWG0FZcKV/xvF/lC7+U9iSqphyM8eCxzSdOpuKAdG4rmF/L+e7zF7Z3dTIZsOmhWxli95OU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780405944; c=relaxed/simple; bh=lvc7mybribNI0qKM6N5/FmJL7igj+yb2/P4ASaICf40=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oSuj/JcbKIlOl47PwALAlC41mOSTYatYfb7M9q4yIJ0Y3pQ7CI8TgQbupflcWL7r+9+q/za4hZGtH2FNjfyV8UtbGUckUK+oMaFHWDikNPMjmJqa3GGii/LdppAV7cxRXEnCQiewSr/bHlO5dJx4SdhFeBIWkzRM+pM3DukfrXA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FXTslTRY; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FXTslTRY" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-490ac357c55so20158745e9.1 for ; Tue, 02 Jun 2026 06:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780405941; x=1781010741; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xufbH6/LW8nomXQ4PybUK63N3KgJQEA2McZ4fEZ1QJw=; b=FXTslTRYMCiY9qEA0U0k6qvwVI/rZBZuRnj0VL9LI3fSKc3sbFDkQRUR/dgWEE36l+ Njdg8p0f0wh6tNu+Nwl8AMGgnUumL0Do0zkERSIXNzR0MO/c+/8wFjO56HKKTBQrvIN0 xf3fh9eJ2elqk0edS8JQlD4JrN3sJzNJCMSwN0hpdFDzUAS7RHt9KJh9qS6ZNEu9xUol 7AZqjaRHIpzVU9Cd6I7LGlwEQ6OE5U+87yliNdx+Dc5rnRyXOovf4WxgPHLlHUvnISFP 9aPbZJuPMzf6EUCeAGOrj52R1BxtZdBKUGHKXvW8MWpGcL46Yx8bId9ANOOSmDRt9g4q i8wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780405941; x=1781010741; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=xufbH6/LW8nomXQ4PybUK63N3KgJQEA2McZ4fEZ1QJw=; b=Y+ykTRHkBXZyZJfBkZig2Yns54X7r8SIBQERD6IUecnQc5P8LkJEf3Gra76SoDsGmt O/D2jB/dbEiiVxMni7m+k1B9BDuX7o9Btsb4ps8U/83DqYl8Egak6KTuY7OT4i6d31eN VVl6VsVZRgbSgvMeDYjxfC+e5YvSVZUj4EKOKTB+Tmzw0jyoodb3mhe2ZYFfOcljLGP+ 4tghXlNbVf90YY8YYvqp4d1O5w55VS9e63isztwGCegT5Gnqjz03MOe8AG9lyfzYWvEt 7T4iOg6Z0K+SxHephJ9dYy3KtGEtPz4zjoOF5TxMVDBmkiNqqGueMRA1Og5rlt419w0R ukqA== X-Forwarded-Encrypted: i=1; AFNElJ/jGfnsW8dvTfolQHZ3toBky+U54/neOWtfQpGb6BsmdrvVtzZQMX6O3GRsvIxdIYBcpD5urZpGOA0xB2s=@vger.kernel.org X-Gm-Message-State: AOJu0Yyz3L2I9MtNs5N4XCOzEXQnBqWnat1x7LKdFxrxXq/1m/WBLc+1 sB5Dbu0o7ybF/VwdH6p8Qf2t2/yWF0QBSUhmFAB3lnfDpBnXvTC1pcKw X-Gm-Gg: Acq92OEjtKqD4hhPhkYS7XRZc+bYl0cim4tSkb1yNAK9qAi/G6I5JmKX4qm/LvuUh2I Xn8dcrgng4JW+Dx6+RFiiDjtYFxRW4UADm6MhxP936Ut+rEXf68EjEsRHneZ7blM4Hn8jIGdQBZ DgEJ9XAVrC9yoqrTJDgwpmol0vFmHjgtEsnJX3y03O8a6iIRfpaoauY6lZw8qLY3Wq3cQscIDob tATcAjpF5YrqVtQ8nOvysGt03R2UrUsI/tbiN9CZAT7F8S6RRI4Kx8awdy7MRP1Ok2WHZ2UqBUN 25Fd76yQuN7K1gb4VnIweR1k8UbuD3BR5SdJmwWOy2kHz3Zj99lWh8oLUi0L5KCizrcIrp6cN9A SUpXLBSnjaTUKpkn1PJjywGAG6NOUnENhlReDaXUEY4wqT1SPo5H3pnNB2lr1YO2MoLnZAfz2qt qD5fkaCcFYVg+9ts8QrfBDNNXzfj9sZtPFNe3qjwSCJg== X-Received: by 2002:a05:600c:5915:b0:490:958f:2a5e with SMTP id 5b1f17b1804b1-490b071aa9dmr56258675e9.13.1780405940691; Tue, 02 Jun 2026 06:12:20 -0700 (PDT) Received: from x1.tail0e71db.ts.net ([46.140.7.198]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45ef34c3081sm33234665f8f.15.2026.06.02.06.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 06:12:20 -0700 (PDT) From: Ruslan Valiyev To: SeongJae Park Cc: Shuah Khan , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linuxoid@gmail.com Subject: [PATCH 2/2] selftests/damon/sysfs_refresh: test kdamond refresh_ms Date: Tue, 2 Jun 2026 15:12:17 +0200 Message-ID: <20260602131217.2210912-3-linuxoid@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260602131217.2210912-1-linuxoid@gmail.com> References: <20260602131217.2210912-1-linuxoid@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Writing a non-zero value to a kdamond's 'refresh_ms' sysfs file should make DAMON periodically update the read-only sysfs files on its own, without the user writing update keywords such as 'update_schemes_stats' to the 'state' file. This behavior has no test coverage. Add a test that starts a kdamond with refresh_ms set and a 'stat' scheme whose default access pattern matches every monitored region, then polls the scheme's 'nr_tried' stats file directly, without requesting an update. The value can become non-zero only via the periodic refresh, so the test confirms refresh_ms works; with refresh_ms disabled the stat stays zero and the test fails. Signed-off-by: Ruslan Valiyev --- tools/testing/selftests/damon/Makefile | 1 + .../testing/selftests/damon/sysfs_refresh.py | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100755 tools/testing/selftests/damon/sysfs_refresh.py diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile index 2180c328a8252..ece244e5c5b95 100644 --- a/tools/testing/selftests/damon/Makefile +++ b/tools/testing/selftests/damon/Makefile @@ -13,6 +13,7 @@ TEST_PROGS += sysfs.py TEST_PROGS += sysfs_update_schemes_tried_regions_wss_estimation.py TEST_PROGS += damos_quota.py damos_quota_goal.py damos_apply_interval.py TEST_PROGS += damos_tried_regions.py damon_nr_regions.py +TEST_PROGS += sysfs_refresh.py TEST_PROGS += reclaim.sh lru_sort.sh # regression tests (reproducers of previously found bugs) diff --git a/tools/testing/selftests/damon/sysfs_refresh.py b/tools/testing/selftests/damon/sysfs_refresh.py new file mode 100755 index 0000000000000..012b7e8f509f5 --- /dev/null +++ b/tools/testing/selftests/damon/sysfs_refresh.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import os +import subprocess +import time + +import _damon_sysfs + +def main(): + # Continuously access a memory region for far longer than the test needs, + # so the kdamond always has a live target to monitor while we poll. + sz_region = 10 * 1024 * 1024 + proc = subprocess.Popen( + ['./access_memory', '1', '%d' % sz_region, '60000', 'repeat']) + + # A 'stat' scheme with the default (maximally wide) access pattern matches + # every monitored region, so its 'nr_tried' stat increases as the kdamond + # runs. refresh_ms should make DAMON update the schemes' stats files under + # sysfs on its own, without a manual 'update_schemes_stats' request. + kdamond = _damon_sysfs.Kdamond( + refresh_ms=100, + contexts=[_damon_sysfs.DamonCtx( + ops='vaddr', + targets=[_damon_sysfs.DamonTarget(pid=proc.pid)], + schemes=[_damon_sysfs.Damos(action='stat')], + )]) + kdamonds = _damon_sysfs.Kdamonds([kdamond]) + + err = kdamonds.start() + if err is not None: + # Kernels older than the refresh_ms feature have no such file; treat + # that as unsupported rather than a failure. + if not os.path.exists(os.path.join(kdamond.sysfs_dir(), 'refresh_ms')): + proc.terminate() + proc.wait() + print('kdamond has no refresh_ms file; skipping') + exit(_damon_sysfs.ksft_skip) + proc.terminate() + proc.wait() + print('kdamond start failed: %s' % err) + exit(1) + + scheme = kdamond.contexts[0].schemes[0] + nr_tried_path = os.path.join(scheme.sysfs_dir(), 'stats', 'nr_tried') + + try: + # Poll the stat file directly. We never request an update (e.g. + # 'update_schemes_stats'), so 'nr_tried' can become non-zero only + # through the periodic refresh that refresh_ms enables. + nr_tried = 0 + deadline = time.monotonic() + 10 + while time.monotonic() < deadline: + if proc.poll() is not None: + print('the access_memory target exited unexpectedly') + exit(1) + content, err = _damon_sysfs.read_file(nr_tried_path) + if err is not None: + print('reading %s failed: %s' % (nr_tried_path, err)) + exit(1) + nr_tried = int(content) + if nr_tried > 0: + break + time.sleep(0.1) + finally: + kdamonds.stop() + proc.terminate() + proc.wait() + + if nr_tried == 0: + print('refresh_ms did not auto-update the schemes stats') + exit(1) + +if __name__ == '__main__': + main() -- 2.43.0