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: 198083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2489099dyb; Wed, 7 Feb 2024 12:33:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVT2gqT6ED3M/J+kaFQorslBHTnEncocPrfibO0NyTs/5igZKKYzOPtO1Eo1BGBRtOY1U3Sy9waSXrW+8KymUJeQ9A/IA== X-Google-Smtp-Source: AGHT+IFYFpWGWaA9nEkxHcYBsqmNVJvwBvUC3wrxtQcNbLpjYr2qHSE+Stip27e+qNtYr4JFOgor X-Received: by 2002:a05:6512:3da6:b0:511:5fc7:7b84 with SMTP id k38-20020a0565123da600b005115fc77b84mr4439534lfv.59.1707337990271; Wed, 07 Feb 2024 12:33:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707337990; cv=pass; d=google.com; s=arc-20160816; b=FXZb3XLvKdCTU0PGE/XIgZCOay8LIWiNqi+JUEJINIfc5eXd02UUAaSmDp8j0zsj2o dXiBjLzb69DY2yRToyTPzGv2KYVyQlfKRwENfLIfPTnrB4amsQacV90vjnSz/xuaDzTL Fn/uaHFgEaAOCBv4qdeqDp0cjwO01un6bcnK3xtIZGMBOJlBCOxBxJBd8X6zk2AgF9Ag crYx01tgEEf8D66eG7oO8DO4ed0lkjdBdY/2VyQgZkSv4Uurr2CnWDPphZm6G+Xiab4P U6j4UGGof3GcwKnVsLCVBKB4GR5aKFppYMTveGmTZTu2vLhaOWioZkvrxY+5SChbC1cB 4HOA== 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=HQsnQiHECGwZ+IIGXPseCKHddRHgG9/ugyekSKU9W1c=; fh=KSXGIq7RP4at3pKjS9umK8kOrP1BToub/FnISto8xo4=; b=qJ12gKLMvqTCoDB+zU17i7h91hC9j3Rbj0fR7TO2IevWId1pci0GpzjxXbX/makMQj 10qiGanxESbkglXQ1YWJrZTsgnC/Kglz7blxlmRCXEZYAnKVsYq5aZBqWh4blsUMNA9F A045I8eAkVQvmY6X5xPCg/YnOHmn8ueLKJLfuNd2n+MLGA+s8tfCK/zpuYRsfXX1JV94 a2HZa0/nLMLCQJDqAgg0lOP9z55a2b1IR0d7BonjuX6eXTB2C8Vr/2/HhxxjMe79DCBC 2pc9qhkErZWJPpDpraDK0T+7zDCZayADRsA0ofsJV4N4c1HwlwuPzrRPalaY8gIz5495 higA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DJJijCfm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57030-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57030-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXNUt0zA3W7iMknD+5qjGpIMjyoqhxdAwPw/uupnN+je890ODIm6JyD0gM1Akcc0lPSE2ceeBB23ZCSkPUo+AWG0pjmUg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gg12-20020a170906e28c00b00a386d2c9e06si1248031ejb.487.2024.02.07.12.33.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 12:33:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57030-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DJJijCfm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57030-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57030-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 am.mirrors.kernel.org (Postfix) with ESMTPS id A8FF01F25EB8 for ; Wed, 7 Feb 2024 20:33:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48A1212B179; Wed, 7 Feb 2024 20:31:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DJJijCfm" 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 7903012881A; 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=1707337904; cv=none; b=ITU4Vo46XdOZgVOjjUCowmSgklietYGtXcOt01sLPG7/v2dPeR0cp9wfA/7Oq4cZ3OsqleZVpvOD3cRq+mXP/QuKueSF5mMDX2acYGlfPmLkBDgq8OVOWdQzYanHC022gJmpRUGYXS3i2j7KAazcFtZ/aGVJKpndxBEyTdz0ex0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707337904; c=relaxed/simple; bh=tz9uTb84Z42Yizp5Acw7rjIK4AMaxjqMzKQOqT/pm1M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N/7h+7c4CkVjmy8ecwRqas+Ush5ZWxiMb1lKWqmF+9/PUkOZ9CVkSqFbP2nGMqdniYJiokikrGLMB/WD5rhCsogl5tJ6E9u3NPkx/AqoNRNX8sN7jct0hmmxQQaAdGZaVssytySOhgmwKt4uAfM8w1RxaSl0t6pfuqWPqongbMM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DJJijCfm; arc=none smtp.client-ip=10.30.226.201 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> 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: 1790273640748914065 X-GMAIL-MSGID: 1790273640748914065 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()