From patchwork Thu May 2 17:27:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13651935 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 0E9B4C25B10 for ; Thu, 2 May 2024 17:27:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 576286B0085; Thu, 2 May 2024 13:27:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4AEBC6B0088; Thu, 2 May 2024 13:27:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3297F6B0089; Thu, 2 May 2024 13:27:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0C1186B0085 for ; Thu, 2 May 2024 13:27:33 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BC26A1C001F for ; Thu, 2 May 2024 17:27:32 +0000 (UTC) X-FDA: 82074137544.18.921147F Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id 12BA318001C for ; Thu, 2 May 2024 17:27:29 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=WKebqnen; spf=pass (imf06.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714670850; 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=auK6IyGKuN98vjMNHugsawMOxztwrQD+fSFqrG9vhVs=; b=XF6cy79oI975AObU8y3CAKLVldZLT0PbMtuhV7+ezwPd1Bj9M9Lt+V5K1kzP14XW6ru/zP XwKf7fgbuDKe1aAmReVsGRcqW7D6+pWwF5URxFZbvEIipK7sH6KkqzPNtfNDPYdXRFq5vP sGgKFj1Zyn2JVbPAwbqY4D+LcQ50eP4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=WKebqnen; spf=pass (imf06.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714670850; a=rsa-sha256; cv=none; b=jcglYa3Mo1K1qcxfBsP3Qk6YCxB4mnSeqrAWCspRRUxTPNvC5kidfe1q6l8uzgsP50gUN6 oRxJ7ZdNS9pYtMLuObJ7qVLsfHt/iU1kuhrvrPd11XUpFLMUD2CK7h3hh7Mt2Nv1Ht17sb zCFIVN2KqADz0o7UbIpqrwjHfhkJWPo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4FFA561BFE; Thu, 2 May 2024 17:27:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A8C4C4AF19; Thu, 2 May 2024 17:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714670849; bh=eEWaWZuCUVNjcnEDhQvZezH6s4ajL/w8rs19eZgBqzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WKebqnenIBHYk1o6RYjJ4Y+xs13OsNlBIXuc5Czx/u47e/HiLgix36VAoQ9uJFdpG SNZoV1iJwX0OtmVdeAkGwqeEzZL3oVR1QZC4/1BFqiGBKwlw60MKOC+w8BIi99hoVN TXuT8eBlkg4ESgiLjFWPKtNAaDBg5t3CY/8Bcj+zOCRw+im61SDI3zrLxneFEiBYzE WMn9r7AKRefWgMq54Yi2fkRl9JHHJBZf7eJfRVQg1PeefOmn918RDR6IaN6d8Q4DZj mPcqgeeENXwB9X4aoceet90qSbZNkhKf7ZPDhUN1D7ylCSYDdt0Xn20j6KzmnJj0ET Dso/ZuNs3RBUg== 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 2/2] selftests/damon: add a test for DAMOS quota goal Date: Thu, 2 May 2024 10:27:18 -0700 Message-Id: <20240502172718.74166-3-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240502172718.74166-1-sj@kernel.org> References: <20240502172718.74166-1-sj@kernel.org> MIME-Version: 1.0 X-Stat-Signature: t8ed68cq7wui6w9uz5rmxnur44imuzs6 X-Rspam-User: X-Rspamd-Queue-Id: 12BA318001C X-Rspamd-Server: rspam05 X-HE-Tag: 1714670849-784538 X-HE-Meta: U2FsdGVkX187pmMFf3KHoYTcQ1qyAJjjLvQM5pPhizQZzUdF2Lx1RCmg1DYcEoobcUgU9B2uZnY4NpqmC3rN/3FEavzgY2kS9/yP6yOHkf3jrd0xCvlNS8pY7oV5MxadYePVeovkDnlUAJUfprIHUQaMSoNOGi16WdL0EaG4N7qXD/gs4zEKhhbXmloPIXtyZTNnreq2TAT90GuaKfCKdTggYpkOwKQKaVjypi93lGCHRha3cz35NgDyyuxvl7k0tMBoudOYBA5wBpiEL3B7WUApcMi27kClr2mkbkPL0z4ss0hDDSSMppjF5OFz11ZlhpAWy46DH/skA7cYjZVc4HL6BPBRctdKLKZvUrrUdTcVquSpyiuWarrZtzWYumJsWjhVPgxS+pftzi/EfM9dE4q3QEeI16cf0/wIbXu/sAulFFPritR9puAa8squ4HnUTRyKsjoAila8jajCXv9pAbKCn3Jy3asmMSwZOT4F8/2svCJlQbRI02jCEXVdX5o4ylh9yMUu+7BlT/sr9bbjgiKsFlXDkl/AWqlr3cG6ihlioSecFelhKZ+bVfdIrPAdyXNFTx9sPSOlW7ipeHBzhHL1KfjoW3rC2QBAgWoPZhP/iwZmTrBI0gczVpIRvMzFWBH1SC0/0FSF2vKUCPacSDSVrOeCZSESUyGjS39S802awRK2tXcZsah5QW31XedEerThAFUpIo4y68rJCMmoJQ1GhyDCecToGRSIOnniuYDd/31s2/lsZeQ0Qeiwv8YQPvTTKCgyksk/gRKxtRoYCCpEZi05F0vsmwkCPyJfAiuPkbaGtCCZsaRRCDPXwhG+FL0Y/imRq9s7CB+62Hn7P98ZDcZjuiWvwRLrjBbVc013hrLC7t7fd6Y55ssvV0g9G9O9EJJh7MAzm6O6gAW9jtWfky1eSYzkQx7OiqbHIvRxqhJb8VedYliZC26LTTKeltcNHSMalG9ebJXIFEs ekUXsrek d5Pdwxu9JG54xvUiiG8sBtlX5MFWcY4Q4EgOXejIXeSxBWSZ+8hATLrAqUPd2VrtiqqTC7veYFvUsM8ZsO0OWtXdjy2sH6YoEsO8/vio/Xy+Q0m5m56ahtHfxoPJJK9YSE3TLdFP87Wv8DkY+JBJPV9ugbhok8fAShg4T1D/IPQSIuK0tqmNQBtjvvUXOvHFrXGb8KZyMpSBm2q/ipiPsLpedRRniSRP27ii7e1qggi5Gwuo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.011868, 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 DAMOS quota goal. It tests the feature by setting a user_input metric based goal, change the current feedback, and check if the effective quota size is increased and decreased as expected. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/Makefile | 2 +- .../selftests/damon/damos_quota_goal.py | 77 +++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/damon/damos_quota_goal.py diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile index 789d6949c247..06c248880172 100644 --- a/tools/testing/selftests/damon/Makefile +++ b/tools/testing/selftests/damon/Makefile @@ -16,7 +16,7 @@ TEST_PROGS += debugfs_target_ids_pid_leak.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 damos_apply_interval.py +TEST_PROGS += damos_quota.py damos_quota_goal.py damos_apply_interval.py TEST_PROGS += reclaim.sh lru_sort.sh include ../lib.mk diff --git a/tools/testing/selftests/damon/damos_quota_goal.py b/tools/testing/selftests/damon/damos_quota_goal.py new file mode 100755 index 000000000000..18246f3b62f7 --- /dev/null +++ b/tools/testing/selftests/damon/damos_quota_goal.py @@ -0,0 +1,77 @@ +#!/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']) + + goal = _damon_sysfs.DamosQuotaGoal( + metric=_damon_sysfs.qgoal_metric_user_input, target_value=10000) + kdamonds = _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond( + contexts=[_damon_sysfs.DamonCtx( + ops='vaddr', + targets=[_damon_sysfs.DamonTarget(pid=proc.pid)], + schemes=[_damon_sysfs.Damos( + action='stat', + quota=_damon_sysfs.DamosQuota( + goals=[goal], reset_interval_ms=100), + )] # schemes + )] # contexts + )]) # kdamonds + + err = kdamonds.start() + if err != None: + print('kdamond start failed: %s' % err) + exit(1) + + score_values_to_test = [0, 15000, 5000, 18000] + while proc.poll() == None: + if len(score_values_to_test) == 0: + time.sleep(0.1) + continue + + goal.current_value = score_values_to_test.pop(0) + expect_increase = goal.current_value < goal.target_value + + err = kdamonds.kdamonds[0].commit_schemes_quota_goals() + if err is not None: + print('commit_schemes_quota_goals failed: %s' % err) + exit(1) + + err = kdamonds.kdamonds[0].update_schemes_effective_quotas() + if err is not None: + print('before-update_schemes_effective_quotas failed: %s' % err) + exit(1) + last_effective_bytes = goal.effective_bytes + + time.sleep(0.5) + + err = kdamonds.kdamonds[0].update_schemes_effective_quotas() + if err is not None: + print('after-update_schemes_effective_quotas failed: %s' % err) + exit(1) + + print('score: %s, effective quota: %d -> %d (%.3fx)' % ( + goal.current_value, last_effective_bytes, goal.effective_bytes, + goal.effective_bytes / last_effective_bytes + if last_effective_bytes != 0 else -1.0)) + + if last_effective_bytes == goal.effective_bytes: + print('efective bytes not changed: %d' % goal.effective_bytes) + exit(1) + + increased = last_effective_bytes < goal.effective_bytes + if expect_increase != increased: + print('expectation of increase (%s) != increased (%s)' % + (expect_increase, increased)) + exit(1) + last_effective_bytes = goal.effective_bytes + +if __name__ == '__main__': + main()