From patchwork Tue Jun 25 18:05:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13711790 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 46B18C2BBCA for ; Tue, 25 Jun 2024 18:05:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC8086B009E; Tue, 25 Jun 2024 14:05:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E71066B009F; Tue, 25 Jun 2024 14:05:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C774C6B00A1; Tue, 25 Jun 2024 14:05:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A3B7E6B009F for ; Tue, 25 Jun 2024 14:05:51 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 55844160469 for ; Tue, 25 Jun 2024 18:05:51 +0000 (UTC) X-FDA: 82270189302.16.EE17D3F Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf09.hostedemail.com (Postfix) with ESMTP id 76258140021 for ; Tue, 25 Jun 2024 18:05:49 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CkQxuGZQ; spf=pass (imf09.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=1719338729; 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=ToGiGzJSGLsESutubIhiPMJBkNnFffebkP2gqfJ3X7g=; b=Vl/jWTuElXcUpPha3Te0cdwGskBOXYF3KxFe71K4cFdRPuz0DZ4yM8jM7X/p0A8AfZDrQn YVMVGDO9VFRMjXW5ta3d5NNFpGHGkNYQa2lfzWKTy5ljBOWwPvW8FA5vRzWd1ljNBoJK7Y +/4jAUuA6eeXvxPQrkKtAezje/8ZBvE= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CkQxuGZQ; spf=pass (imf09.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=1719338729; a=rsa-sha256; cv=none; b=Aic/7FKBXfPO7heBgwKCy1VwbD3sQ222codc79V5snMt+8EHYvUvap6Cb4HeFBcHS2JJpD Hc6P78cL0VkeOyNlli860u69Mv4o4+M92WswbEv2kN+VuVSmQnKvef3KGRfrdP1CogTCL5 IY10mbC4ggCV4B629Ejb+wuxPngtjSI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AB2E261730; Tue, 25 Jun 2024 18:05:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05CABC4AF0B; Tue, 25 Jun 2024 18:05:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719338748; bh=NVtILSH+9XYglOUzDKTB4NeWGCqUXF9j4Ar1OAT5e/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CkQxuGZQDXDSFVVkxd+cWTiZYH9I8X/TYlIjNbrGHDCeUjCwfc99G2TAMubyPKLvE Ttbt8FSCaARYyIm2t69Cc620QeD8bOnvdvMoQaKIrG++rqPy9RgvXqPkvOcaA29ECE qQLYRrC545HJC3vFtMGhbLcrAgJG0bOYNcS+uUmEtO/2CKjZxiHesf8Ni8g+NUeQba r4A4E2J3oZhGyQbU6XX2X2jRn3KK/GPF3fxXzorBTTMJX5vbPDjqkve/6oXz28464T 1BRM/pV6sXNzmGMUBXXbF2gA5mxQUBbswUOoU7b4Dlj5iLuYH5OOwgKBvwp8ye/AsO IIUNQcghvm0Jg== 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 6/8] selftests/damon: implement test for min/max_nr_regions Date: Tue, 25 Jun 2024 11:05:36 -0700 Message-Id: <20240625180538.73134-7-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240625180538.73134-1-sj@kernel.org> References: <20240625180538.73134-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 76258140021 X-Stat-Signature: wzeg6gibq6xj6gd4uzqaha9bm5rsrjja X-Rspam-User: X-HE-Tag: 1719338749-46545 X-HE-Meta: U2FsdGVkX18h1ha+8LzesCg+fSbMrHfWt8vge/qPejnzeNtD53Sc/3c2pOjHJbQ+/uR3IVvDU3rRBo9aVNX6Vza5gMvKCK6GYfCDFHJjfowf+jhMso+lRNkdn7vIEye7BEqVpQ+ckrAYKKNmOhPW3ZCoytpv8KmYRQHfEVBbALQx43bRkHTZY04S7SlC2IAxtb45wAmXhuiNd3UFJF5qYM/QI8Ti3+Zq8zEhXbHHCnXRvroEZ/BdxcNHzBqkIEIUP4J7B0XXQROAEQ7bpURudaEWTIsdCi8VWVwvwH0SyFFbQZaWSHxb5WPfDHLbpRNALMIe7dCHJRkTv3j1I+WNlvudGleFKLhVd2IrZznPPP9Jzs2Pd7KCUy+lwlEu1OWZBYtofolOnCjjst0f+MfodZtJX984D3IbAjh2gnPezBQU3Pi1QHBowKBXnT0uUAfmdsvUACAmqzbYoLFnT+hm/nnsyR1EucsM32XAK6Ez2Qii0sHAdiXiNK3r9MR97WOKq/eVcOSFSpR5jyZbjSQwyUG4YqOtaZ5ZANu+A9W2OpjnM5+vw2CxOv4b5PebDjHzZ6gD6klgR3O625eXIoCmpx9sOFXezobEq/dsTy+nKGpkvTxUcP7jnEpIuc1f7lbDV9gY5zCIpgKQemk/ii0ZiE+VGID0NA3Jijk8fYnDNycsl4XsMUY8kpIWYZ0RTyUMdj1ovlWNss0Tn+U39R5pkg8/HexBZkMNYZxe6Rx2oZx+PypjTv8TU/0+efdRp2PxfhFuhDSgRRkaRNFTWXSlD0nkIFz9CmwpVK2IAU9AiEPhu393uoREcR+XGhJXeWHDOwIdjFmmUctyA4PWoJoAFLu+PLVpuBqj3CtLuYEcxZtH4R42SiUqmR2LP/sZF4RwSrbf7QMv8dWAXw7M11I3vOhBFStF6pp08Couln9EL5gWvbagSI+tGnGFigD0U2FSPoaTU6PuLP6Q7h3plQn 2e31BGDp 4dEj5zqr/oVhvQgBrb5zCgBJ+a+x9PKrKIcoB/9LTjqADtyOGqifKNe32N28E9CnhKRHG5fXdIumpYPE7OKo0r5P0tmFHUB+z9wBPgrR5Gk3MXaLuT39WUrcp6y+AaMSQfSGOpYgCCaevx9wRgCWUZhzKL9058xOgKHHLpJ44T/W6ByDD/+JOH4SMePstn8lL/MT+dbzr3yDd2ZG9M426rUZlZlu1PxgDK5vOlovHdFjjsvUqPiK6y62Ip/q0Pdghq3obQ3xbxPBK+j0dxefU6ZXMQIKImowzskPKpex86wUQii7vuTODmiW2SGERhI0XiiGa X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Implement a kselftest for DAMON's {min,max}_nr_regions' parameters. The test ensures both the minimum and the maximum number of regions limit is respected even if the workload's real number of regions is less than the minimum or larger than the maximum limits. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/Makefile | 2 +- .../selftests/damon/damon_nr_regions.py | 85 +++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/damon/damon_nr_regions.py diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile index 356b4e9a515d..1e2e98cc809d 100644 --- a/tools/testing/selftests/damon/Makefile +++ b/tools/testing/selftests/damon/Makefile @@ -13,7 +13,7 @@ TEST_PROGS = debugfs_attrs.sh debugfs_schemes.sh debugfs_target_ids.sh TEST_PROGS += sysfs.sh 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 +TEST_PROGS += damos_tried_regions.py damon_nr_regions.py TEST_PROGS += reclaim.sh lru_sort.sh # regression tests (reproducers of previously found bugs) diff --git a/tools/testing/selftests/damon/damon_nr_regions.py b/tools/testing/selftests/damon/damon_nr_regions.py new file mode 100644 index 000000000000..dd2735923c59 --- /dev/null +++ b/tools/testing/selftests/damon/damon_nr_regions.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import subprocess +import time + +import _damon_sysfs + +def test_nr_regions(real_nr_regions, min_nr_regions, max_nr_regions): + ''' + Create process of the given 'real_nr_regions' regions, monitor it using + DAMON with given '{min,max}_nr_regions' monitoring parameter. + + Exit with non-zero return code if the given {min,max}_nr_regions is not + kept. + ''' + sz_region = 10 * 1024 * 1024 + proc = subprocess.Popen(['./access_memory_even', '%d' % real_nr_regions, + '%d' % sz_region]) + + # stat every monitored regions + kdamonds = _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond( + contexts=[_damon_sysfs.DamonCtx( + monitoring_attrs=_damon_sysfs.DamonAttrs( + min_nr_regions=min_nr_regions, + max_nr_regions=max_nr_regions), + ops='vaddr', + targets=[_damon_sysfs.DamonTarget(pid=proc.pid)], + schemes=[_damon_sysfs.Damos(action='stat', + )] # schemes + )] # contexts + )]) # kdamonds + + err = kdamonds.start() + if err is not None: + proc.terminate() + print('kdamond start failed: %s' % err) + exit(1) + + collected_nr_regions = [] + while proc.poll() is None: + time.sleep(0.1) + err = kdamonds.kdamonds[0].update_schemes_tried_regions() + if err is not None: + proc.terminate() + print('tried regions update failed: %s' % err) + exit(1) + + scheme = kdamonds.kdamonds[0].contexts[0].schemes[0] + if scheme.tried_regions is None: + proc.terminate() + print('tried regions is not collected') + exit(1) + + nr_tried_regions = len(scheme.tried_regions) + if nr_tried_regions <= 0: + proc.terminate() + print('tried regions is not created') + exit(1) + collected_nr_regions.append(nr_tried_regions) + if len(collected_nr_regions) > 10: + break + proc.terminate() + kdamonds.stop() + + test_name = 'nr_regions test with %d/%d/%d real/min/max nr_regions' % ( + real_nr_regions, min_nr_regions, max_nr_regions) + if (collected_nr_regions[0] < min_nr_regions or + collected_nr_regions[-1] > max_nr_regions): + print('fail %s' % test_name) + print('number of regions that collected are:') + for nr in collected_nr_regions: + print(nr) + exit(1) + print('pass %s ' % test_name) + +def main(): + # test min_nr_regions larger than real nr regions + test_nr_regions(10, 20, 100) + + # test max_nr_regions smaller than real nr regions + test_nr_regions(15, 3, 10) + +if __name__ == '__main__': + main()