From patchwork Wed Feb 7 20:31:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 198084 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2489184dyb; Wed, 7 Feb 2024 12:33:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNNy/nWGSXRqkKSaIMtaZ0TcP9+DJHfdSiKCYQeP5pd8pUtyPkQ29Mi4VxWuxe3EJqt76R X-Received: by 2002:a17:902:d2c4:b0:1d9:5ef3:e5ea with SMTP id n4-20020a170902d2c400b001d95ef3e5eamr7242205plc.50.1707338005958; Wed, 07 Feb 2024 12:33:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707338005; cv=pass; d=google.com; s=arc-20160816; b=koxMhs9XDw3dhB5TRhsznqJrNoyxj8rjShcpG7NPRppfYrnp+pybnZY73S0KZW7Hwa P41CeulhDK/HjmOMSM9+CwehcuMeYaZvCEowtCPPuqqCL2EcpdMyx0Sr4JEDMiGJ3uht pqZD64rmxoXGv1x5eJWUmiEFsFe7+rqH72rmMXslfpT1A+ordArK1lMSp/BWAkocviOW iC3k+3M92b2xC4b1ljrdOWlXhV/zR1gfakz0/hYYofpuAJLo7HAOLKwAvRySzS28Vep9 mp/f0a2FEJOulGM/fcF3V4eLsE4gT5AgbGVzEzjIplVRjkcOnNDwdYuRxEn174PVYtcS pOCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=TxVl+5+Ve/BE1UaSuZaYB3tpzYwZOtnPjXlc6UL5oTQ=; fh=THE7p0/r86XGCbx/chOKvWOOBBICQmDdp5bPU9m+/10=; b=VA6CjnpvQd8Rb9MHaaAfchitHRTZek4v6ypJ4rs/GbaI/rD1JBDnlbqIWb0ijuYQ6z vN5roQeK+RopbHdMhhAcGGTkUMmHQdd7Sfdh10gS4SYGWyGU5h7aK44P5YnOHYGbdrCz Rq8TIbKbID5m42BcbUx5wXE1gxHDNgQqiKqqQ7krdfie23Us6IF47b+ygV/5FKSzf1zE XEdopMixrl/abxKHK+39834Q335O5i2SV95QVUIQhMyK3ZBCV0ZeS6A3WE2WfPY0tUxe /TvQ+6icUwz5oxvLSQL/ZHbJFjdjqonOvZHCWooJ8movnEhu6QDT8+9mr7sVuaDMXATI 6EbA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="JKgp/zT8"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57031-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57031-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXo8lPCQEw6JEU4gep4d27TWNbY17MZcIkYH5J6eAqqzNPQCrrbhiWnjCjqNAcvDm9xqUn/c/eVAtUcG+kqCGIhULqVlg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z11-20020a170903018b00b001d8f7d2a3fdsi2544214plg.321.2024.02.07.12.33.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 12:33:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57031-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="JKgp/zT8"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57031-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57031-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B7D442856CB for ; Wed, 7 Feb 2024 20:33:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 552CB12BF28; Wed, 7 Feb 2024 20:31:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JKgp/zT8" 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 55337129A68; Wed, 7 Feb 2024 20:31:44 +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=1707337905; cv=none; b=awO4IAA7rrCQJGXGv+rhbdSqduL24SZfTY9EHHeof/iAlJn40jU2JviX8innoJbCh9Vu9Tw5MQKhWmS3Ceql+i08C3ul7ph7W5ml9UJ6zYxmXPHcfVlWmXbmbl2xkZsAm+vQJ9+s1QoJhxEass8L0P8EZf9Rh0ygQCJhH+DqNlY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707337905; c=relaxed/simple; bh=eTfAT8I3Zrsng6f7SuRxQKWrP7lIEivzKE3OpfIwwxI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NNNZ/v6HpOXAaHXJM3QzUFepWuf/A15ZJo7OyimKO9JELZ03TPL00eWZ+nVp1J+sqOaxyKmllJ3fsQPso9dkFu3+KaNz/CAOiyotME3GfWZF/DDW8THfaW4sWIZm6n3UgVHBVYlL0iPdsssUAWI4G+5qemv5DPXKolLuEiqHk+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JKgp/zT8; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 374E9C4166D; Wed, 7 Feb 2024 20:31:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707337904; bh=eTfAT8I3Zrsng6f7SuRxQKWrP7lIEivzKE3OpfIwwxI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JKgp/zT8soGxMNVpEjgN4T11q/PH3dSEMmOCuxrZk1KHb+x4aO+vHKx3WghdJTjjI U1vxJoRUqSA7K4mUYmEwBW/w7cVZ/AzEVXOVi2WJGSqr85PnQHEVDdbCphy53Hiobe ewQwBW7Pj5BnELlzpz1x6bHuaUUXU1pXc7qQN322bFOVRh4Xb0IFrPID3NY1DlUp7b SnTkVHx91YfY8ZxZosB/ENWyTggk4AGpTLXidmrJmcjX6q21CdrSENztmqzzCi4WBs AUnNKvucq+cG0+WD5BN7QIV7fUw/7zlR91K8CILvWsb1THqfz3lx4WtJWh7OFb7FSi 3SpnJ3QJj9rXQ== 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 5/8] selftests/damon: add a test for DAMOS apply intervals Date: Wed, 7 Feb 2024 12:31:31 -0800 Message-Id: <20240207203134.69976-6-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790273656517730257 X-GMAIL-MSGID: 1790273656517730257 Add a selftest for DAMOS apply intervals. It runs two schemes having different apply interval agains an artificial memory access workload, and check if the scheme with smaller apply interval was applied more frequently. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/Makefile | 2 +- .../selftests/damon/damos_apply_interval.py | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/damon/damos_apply_interval.py diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile index 9c3783f1a39d..b545fedafb3b 100644 --- a/tools/testing/selftests/damon/Makefile +++ b/tools/testing/selftests/damon/Makefile @@ -12,7 +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 += damos_quota.py damos_apply_interval.py TEST_PROGS += reclaim.sh lru_sort.sh include ../lib.mk diff --git a/tools/testing/selftests/damon/damos_apply_interval.py b/tools/testing/selftests/damon/damos_apply_interval.py new file mode 100755 index 000000000000..f04d43702481 --- /dev/null +++ b/tools/testing/selftests/damon/damos_apply_interval.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 + 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]), + # aggregation interval (100 ms) is used + apply_interval_us=0), + # use 10ms apply interval + _damon_sysfs.Damos( + access_pattern=_damon_sysfs.DamosAccessPattern( + # >= 25% access rate, >= 200ms age + nr_accesses=[5, 20], age=[2, 2**64 - 1]), + # explicitly set 10 ms apply interval + apply_interval_us=10 * 1000) + ] # 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_stats() + if err != None: + print('stats update failed: %s' % err) + exit(1) + schemes = kdamonds.kdamonds[0].contexts[0].schemes + nr_tried_stats = [s.stats.nr_tried for s in schemes] + if nr_tried_stats[0] == 0 or nr_tried_stats[1] == 0: + print('scheme(s) are not tried') + exit(1) + + # 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 tried + # about ten times more frequently than the first scheme. For possible + # timing errors, check if it was at least nine times more freuqnetly tried. + ratio = nr_tried_stats[1] / nr_tried_stats[0] + if ratio < 9: + print('%d / %d = %f (< 9)' % + (nr_tried_stats[1], nr_tried_stats[0], ratio)) + exit(1) + +if __name__ == '__main__': + main()