From patchwork Wed Feb 7 20:31:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13549056 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 C9A59C4828D for ; Wed, 7 Feb 2024 20:31:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20D326B0089; Wed, 7 Feb 2024 15:31:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 16E916B0087; Wed, 7 Feb 2024 15:31:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB5716B0089; Wed, 7 Feb 2024 15:31:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C5B7C6B0085 for ; Wed, 7 Feb 2024 15:31:50 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7548A1A091B for ; Wed, 7 Feb 2024 20:31:50 +0000 (UTC) X-FDA: 81766153980.02.D51F673 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf01.hostedemail.com (Postfix) with ESMTP id 16EC64001C for ; Wed, 7 Feb 2024 20:31:47 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DJJijCfm; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf01.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707337908; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HQsnQiHECGwZ+IIGXPseCKHddRHgG9/ugyekSKU9W1c=; b=VjMjZa1nPnsaPcX2Cph7WxFuOaQjGep6+KbDtbwHV+feH3Ek2o0Mc8bDi4P2R1dAkaRRB/ gJw8OVyAiCCT+Y4TluqzEUT0/cJniwD6Y4O8zeWNOfQZPaH7aeXv55RlnHZXINGEZsUPKe rIiYcGWWPHiUwwqKm+M7yk09XihBPuQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DJJijCfm; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf01.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707337908; a=rsa-sha256; cv=none; b=wU3OFFHhBwIzMXGsZaQNa/w8lzuSdJ+6FXKyLmspXcXenl0h/Dlov9hA3TEjHeH3C1b2F+ xgpf+/u3/gbifmsR2GCr8IhrFK3hZCmhvl/QhvObBTMDFXd/jDYcJaYu0dLx9/qKKqb4gB N1E7N9MbtOh6kaENqSAk34KC8UX24+E= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id B8CC2CE1B03; Wed, 7 Feb 2024 20:31:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68A8FC43390; Wed, 7 Feb 2024 20:31:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707337904; bh=tz9uTb84Z42Yizp5Acw7rjIK4AMaxjqMzKQOqT/pm1M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DJJijCfmw4GrlAMLBl2nP9yduJUcln0mxAT/q50sI+tVVLy2pIDCclwCxcNfCEWOG 3uKNB+jqzsufuPDqf9L25wuWkXRB3clhwftLcRVBOtVOUEmEO9S8Q181dKzi37GUII aqtGfAyzwMiz0iE/qwfGcVHcQG99augNwfn8zblNS3xRUJtTnuyvWkcp3DDkMVQTLs 2F6ltet+/rUSxJuNO9aQjEUVy5vntT50wmjVCQ5ejj5fIqXFLj17s8lHTiCjCMpop+ bFWBaRWR7yfvnKot97njjwyosyXavwoeSgfyjAKNiOO1EH1z03lsyKV/Ew16tLZBML aePPCZfS9eubA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Shuah Khan , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/8] selftests/damon: add a test for DAMOS quota Date: Wed, 7 Feb 2024 12:31:30 -0800 Message-Id: <20240207203134.69976-5-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240207203134.69976-1-sj@kernel.org> References: <20240207203134.69976-1-sj@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: fhgkoh479r55rqghas93919rt3yxaisr X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 16EC64001C X-HE-Tag: 1707337907-366060 X-HE-Meta: U2FsdGVkX18t8Fa5pP31bGXoS4Q06rHt8bIt9uvQLh+skEaxqKp2iVkt8s83PmVHVyZXz7eInWZ9fpuEbDOn+9LdAj3j9savY8gxkHG5dZQBdkjBdm3CfrKE58PfF0cTkbg1iQG1JF8+qFuj+V+AEFlLju8t/WOgDud755LH+ipJxqDlpjXBojEk8kfFWWgUSmqc6mefBtLpsq12j+ukyme0+X4guO2ceLMbfwtqDUiOYf+70tbY8sXM/eB8yP5PTquW17bhANfCFXTrto6fhombEGlGnEQlQHySCrKI9koGrJmTXkBLqW8q9r/7PLACONjHMTUjUBhSHGaZ0tKqIcjFP5jP4+wp9C6ATddIBUf0D5CBY+P4WhgaO+WaFZm9tlXQ+zAT2HOO2XZGejDNKIX3/luaplWEtKivVYWBxkESmQvCV4mjUUtqDbu1vhd9MFrmDkZVa9YA0BBLpRfdEEBX9fqPIWxs3JP+XktVox+X6j/utO6vBaTosqTN1yVeQQYVAlzqFS8BfGMyJP2jKDryiqGQB9s5Q0ToPMFvy4hRQ/2RfptYHu4o7kBHW+3md7BPrVKlhIOpr/bxYG8DNpvvEW9x3MvCWlmZui/N7uZgfh7K3KVP0h73qTdZcNWGIh2GTVJ6tklUIWBQ6YqvuSF8G/IeNY+HJqgYvbf4Y62LlQrZRlnopNHCRXBPll1AMDUkaXvX0duuB1xivB6Q4Ax/O6skloP3XKmJZ7NEasBNi6C1DBO/Ph5QbVmDsf6ZfV/i0lX9RVCkH69+o0CzYuQ4ApEoYyHWunAIOH5Jssk32NS4T48boHf5k37AAsPE6dt+Fee/uFtOR6atuozWn0n6fz7YQnVEpEf1aNimPgJa/O4u+fQiaW1Dp1+QTgTTp940DDTNVPnnWSJRBE9Wn9bm/t81+VSzURiKWGLrLLeA+Tqn9m6cy/2BwMQy09n1no4n+yJRjw1eix5k4Xl om/iilTA DxW+jJNLqe4aFzE2dD8Tz2BzFef16ecbe7MvUZcw8yitGJnjpLe90K6Dg5qgR46OeGc2Mr67e0tcVsV/VKgJxoEjDX7bb2bYgXZtGPQOYtVInrZd3tsx2GC4D5yTbME8FCe3E5z+HzZ42K7XwDWMjqmfEgkf1xN7U4Bv43bJ2bLHyOx3Sys8nTM4ppCK2bR9Cs0nIKKf8uQg/k1BDCirED0t1nMW4lEFpHhy8pKkwaHdQVFZTXbaOdDAjOiCB+fuDuz84 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a selftest for verifying the DAMOS quota feature. The test is very similar to sysfs_update_schemes_tried_regions_wss_estimation.py. It starts an artificial workload of 20 MiB working set, run DAMON to find the working set size, but with 1 MiB/100 ms size quota. Then, it collect the DAMON-found working set size every 100 ms and check if the quota was always applied as expected. For the confirmation, the tests shows the stat-applied region size and the qt_exceeds stat. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/Makefile | 1 + tools/testing/selftests/damon/damos_quota.py | 67 ++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100755 tools/testing/selftests/damon/damos_quota.py diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile index 8a1cc2bf1864..9c3783f1a39d 100644 --- a/tools/testing/selftests/damon/Makefile +++ b/tools/testing/selftests/damon/Makefile @@ -12,6 +12,7 @@ TEST_PROGS += debugfs_rm_non_contexts.sh TEST_PROGS += sysfs.sh sysfs_update_removed_scheme_dir.sh TEST_PROGS += sysfs_update_schemes_tried_regions_hang.py TEST_PROGS += sysfs_update_schemes_tried_regions_wss_estimation.py +TEST_PROGS += damos_quota.py TEST_PROGS += reclaim.sh lru_sort.sh include ../lib.mk diff --git a/tools/testing/selftests/damon/damos_quota.py b/tools/testing/selftests/damon/damos_quota.py new file mode 100755 index 000000000000..7d4c6bb2e3cd --- /dev/null +++ b/tools/testing/selftests/damon/damos_quota.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import subprocess +import time + +import _damon_sysfs + +def main(): + # access two 10 MiB memory regions, 2 second per each + sz_region = 10 * 1024 * 1024 + proc = subprocess.Popen(['./access_memory', '2', '%d' % sz_region, '2000']) + + # Set quota up to 1 MiB per 100 ms + sz_quota = 1024 * 1024 # 1 MiB + quota_reset_interval = 100 # 100 ms + kdamonds = _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond( + contexts=[_damon_sysfs.DamonCtx( + ops='vaddr', + targets=[_damon_sysfs.DamonTarget(pid=proc.pid)], + schemes=[_damon_sysfs.Damos( + access_pattern=_damon_sysfs.DamosAccessPattern( + # >= 25% access rate, >= 200ms age + nr_accesses=[5, 20], age=[2, 2**64 - 1]), + quota=_damon_sysfs.DamosQuota( + sz=sz_quota, reset_interval_ms=quota_reset_interval) + )] # schemes + )] # contexts + )]) # kdamonds + + err = kdamonds.start() + if err != None: + print('kdamond start failed: %s' % err) + exit(1) + + wss_collected = [] + nr_quota_exceeds = 0 + while proc.poll() == None: + time.sleep(0.1) + err = kdamonds.kdamonds[0].update_schemes_tried_bytes() + if err != None: + print('tried bytes update failed: %s' % err) + exit(1) + err = kdamonds.kdamonds[0].update_schemes_stats() + if err != None: + print('stats update failed: %s' % err) + exit(1) + + scheme = kdamonds.kdamonds[0].contexts[0].schemes[0] + wss_collected.append(scheme.tried_bytes) + nr_quota_exceeds = scheme.stats.qt_exceeds + + wss_collected.sort() + for wss in wss_collected: + if wss > sz_quota: + print('quota is not kept: %s > %s' % (wss, sz_quota)) + print('collected samples are as below') + print('\n'.join(['%d' % wss for wss in wss_collected])) + exit(1) + + if nr_quota_exceeds < len(wss_collected): + print('quota is not always exceeded: %d > %d' % + (len(wss_collected), nr_quota_exceeds)) + exit(1) + +if __name__ == '__main__': + main()