From patchwork Tue Dec 12 19:12:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 177522 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7944120vqy; Tue, 12 Dec 2023 11:12:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRUB2C0Hl/XmX6IQPnl8Z725QU2AO9k5+q5obwkpKvEp527hEFyDz9ipTpuk4nhHPUkYz2 X-Received: by 2002:a17:90a:5aa6:b0:282:d080:feed with SMTP id n35-20020a17090a5aa600b00282d080feedmr5591900pji.40.1702408352729; Tue, 12 Dec 2023 11:12:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702408352; cv=none; d=google.com; s=arc-20160816; b=cfb/iMRxa1ifCJdlsj+fjJZBbpmrR9LJOsIuKL0mS7o8mdVKihlzhVuw4HHtLaO+b9 pm5fjJjqEU/3UASUIgxpSfS1S5sJ6YWZlfiU4uUqsNk2ZCOcbTGoOBi9cfimqeu2GzRg mstVKZOvNyibwv5TRss2Nlp7b/3B0aPEonMzqHy5/J5wWd4G/gq10GWavvoa2dCr8leY avjtfTnN3INjwG9nJD0I7cNcOY9NyFh9kYlFqMIyawJRf7GyZRXXa9xNBwz28cxrKhJM dfTVYcM4X0i8T9V1mtFuFdr1X1VaimiUgBj0mgkTr66pgJPEyZuE8iBj5WeyEm1UC1aR /ajg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fi3wGtfhWzp/nJ5/3E+L/QGAOBlEEdfPp7Moh7rrm4k=; fh=9H4z7/o7y4OLn0xLmjdSk9Pth53+ED/R+iGnGlnIr7g=; b=k4mLGSY4G3do2Htm2NFhYPEie3dDHQx5YJ/1xJ+givqUt7tzRPWwt3eP8mJXVBWzk+ JG4GD4x0Cn/b/ZXlfsW7XTqX4E89KIFzczSlon8piWe5xipwvM9ekADEl5EmK3pwgCnE xYeGlVzKakotjdGnUT0uWkbiZNJhReYirYRTn1ORp4QWjSRI+AWck72gnc8PFTSYQ4ao N/t9z4hLHDo+291rFfs20NOHIQHrCpdZyn2EB/ErX/JTyeNIqrlhLWpVnAfD3hrV6Xzz PUSH/EFGHxwxVabLyQPFlFxwr3MT4mHYHdImyBjh2SF+jgxkK6kKgjCb3jNqVAFFWlob Ovxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=igSIjbck; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id bs10-20020a63280a000000b005c62393c133si7867924pgb.795.2023.12.12.11.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 11:12:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=igSIjbck; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E18F880477A7; Tue, 12 Dec 2023 11:12:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377091AbjLLTML (ORCPT + 99 others); Tue, 12 Dec 2023 14:12:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235132AbjLLTMH (ORCPT ); Tue, 12 Dec 2023 14:12:07 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 899ABAF for ; Tue, 12 Dec 2023 11:12:13 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A235CC433C7; Tue, 12 Dec 2023 19:12:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702408333; bh=GHi4Mu0bQn8zyIS9XnsaUAW8ixexoLEYfp8Ut/tF7Co=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=igSIjbckp2hVl7FoDQk0XpOqN8qpCWR+x4WM0LuOXFbwy7VEp+1mpdVGEp8BgivFk YWuKoyLk6+L92fw8DO6z/SjD/Age3Nw8aFN3sUTuRzQgQjSwqpMMH4MFQTfv9gsTfK 0yQ9XH+/wMbWvMMsVUweD+5+gttAd05TAPRCtqgaWwxz119gLLW0XT1drB4JssYga9 hUo9zJVevAPH1Y6xLxnsPPmQ6jbZ4y880MruyyjZJ+eCpF19hzXMTF25lBB45kswHv hg9DjEcyWnOzOwBRp0kdHamLzLcQIb5sDCdxJcPFu+s41K1wSzza5v7T1AmYPl9he3 9OpPFk5S2jV4A== 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 1/5] selftests/damon: implement a python module for test-purpose DAMON sysfs controls Date: Tue, 12 Dec 2023 19:12:02 +0000 Message-Id: <20231212191206.52917-2-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212191206.52917-1-sj@kernel.org> References: <20231212191206.52917-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Dec 2023 11:12:32 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785104540774034750 X-GMAIL-MSGID: 1785104540774034750 Implement a python module for DAMON sysfs controls. The module is aimed to be useful for writing DAMON functionality tests in future. Nonetheless, this module is only representing a subset of DAMON sysfs files. Following commits will implement more DAMON sysfs controls. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/_damon_sysfs.py | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 tools/testing/selftests/damon/_damon_sysfs.py diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/selftests/damon/_damon_sysfs.py new file mode 100644 index 000000000000..78101846ab66 --- /dev/null +++ b/tools/testing/selftests/damon/_damon_sysfs.py @@ -0,0 +1,102 @@ +# SPDX-License-Identifier: GPL-2.0 + +class DamosAccessPattern: + size = None + nr_accesses = None + age = None + scheme = None + + def __init__(self, size=None, nr_accesses=None, age=None): + self.size = size + self.nr_accesses = nr_accesses + self.age = age + + if self.size == None: + self.size = [0, 2**64 - 1] + if self.nr_accesses == None: + self.nr_accesses = [0, 2**64 - 1] + if self.age == None: + self.age = [0, 2**64 - 1] + +class Damos: + action = None + access_pattern = None + # todo: Support quotas, watermarks, stats, tried_regions + idx = None + context = None + + def __init__(self, action='stat', access_pattern=DamosAccessPattern()): + self.action = action + self.access_pattern = access_pattern + self.access_pattern.scheme = self + +class DamonTarget: + pid = None + # todo: Support target regions if test is made + idx = None + context = None + + def __init__(self, pid): + self.pid = pid + +class DamonAttrs: + sample_us = None + aggr_us = None + update_us = None + min_nr_regions = None + max_nr_regions = None + context = None + + def __init__(self, sample_us=5000, aggr_us=100000, update_us=1000000, + min_nr_regions=10, max_nr_regions=1000): + self.sample_us = sample_us + self.aggr_us = aggr_us + self.update_us = update_us + self.min_nr_regions = min_nr_regions + self.max_nr_regions = max_nr_regions + +class DamonCtx: + ops = None + monitoring_attrs = None + targets = None + schemes = None + kdamond = None + idx = None + + def __init__(self, ops='paddr', monitoring_attrs=DamonAttrs(), targets=[], + schemes=[]): + self.ops = ops + self.monitoring_attrs = monitoring_attrs + self.monitoring_attrs.context = self + + self.targets = targets + for idx, target in enumerate(self.targets): + target.idx = idx + target.context = self + + self.schemes = schemes + for idx, scheme in enumerate(self.schemes): + scheme.idx = idx + scheme.context = self + +class Kdamond: + state = None + pid = None + contexts = None + idx = None # index of this kdamond between siblings + kdamonds = None # parent + + def __init__(self, contexts=[]): + self.contexts = contexts + for idx, context in enumerate(self.contexts): + context.idx = idx + context.kdamond = self + +class Kdamonds: + kdamonds = [] + + def __init__(self, kdamonds=[]): + self.kdamonds = kdamonds + for idx, kdamond in enumerate(self.kdamonds): + kdamond.idx = idx + kdamond.kdamonds = self From patchwork Tue Dec 12 19:12:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 177523 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7944138vqy; Tue, 12 Dec 2023 11:12:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQB9X8HKPGJaSV+7b4WRVBZBTp6Onb1Kr2WdlPV87R00ZaSjV3GoFKmiL71WuhfGfAwusE X-Received: by 2002:a05:6a20:3d81:b0:190:c314:35f8 with SMTP id s1-20020a056a203d8100b00190c31435f8mr2988199pzi.46.1702408353837; Tue, 12 Dec 2023 11:12:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702408353; cv=none; d=google.com; s=arc-20160816; b=wtI14Iq6APKKBIYmrecPZkhVyAsFH2xl4KVk8ZWqneOOIwAHj/SpuXrdRanWFl1Y2K mzpC8GhfMXXxMkNLlqdPX7xGdNT3TsO33/c/cLWqxrwOYKYtxKz8/rcnbquw6YnKsbEZ tVLAA9XHrCzFz/59LooNduJ5v1AbEdbILApbu6THxJ27ZbpCAZvQGkN/tvoVC3YNQwYE 4V3XrzIWeVRujPaoPwjL6RCao6Np8NmHEgeOEOzJthitpcdxuF4n5yoohzUjJLsNv9pC Nkq3vFmsC3/vUuSVndWMxzWlqAaJODnvDLFvkAh0Uz+/4gMMerkMJXz/FzD4zLdl2Lwf KFeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Llj595fCp/6fkqvOsmjH1Ip3cww+RZOnknJ+I9nFpd4=; fh=9H4z7/o7y4OLn0xLmjdSk9Pth53+ED/R+iGnGlnIr7g=; b=PMQ+yTuEDIKa4VpL+OIYAKHXSB6bAtX9btNLvjVW0u5PYMAn3Hvd9EJ6TUS13aJ7cp 2LnucQefNXz9z3TPiDXs/PMZCS/LUiNAG7/x+HAF1e+kibVuSUq8KBIurFLKIATJUD1P ASNZQIZHNpppHVxIrKDoPc1Qi1Q9d/SlIuRx7Mc21Puf8KvZeF/GwG2iiVphRROq3o6K +QStq0z0/k1dCZO9L/bt5UCqcd5ZusAJE+Gm1ShJb3L44bQ0NIyGCaf3bUvxpb4U534j 745zb3rjhqo+4Xd29K585nhATEFgxOxejDBR/P5FYWAnNLpOMyF2f6B5GN14w3j3o/bq i84A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LRYglFPH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id a17-20020a656411000000b005c692162984si8081421pgv.666.2023.12.12.11.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 11:12:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LRYglFPH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 5859380239B7; Tue, 12 Dec 2023 11:12:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377126AbjLLTMN (ORCPT + 99 others); Tue, 12 Dec 2023 14:12:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235135AbjLLTMK (ORCPT ); Tue, 12 Dec 2023 14:12:10 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4FDFBD for ; Tue, 12 Dec 2023 11:12:15 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0459C433CA; Tue, 12 Dec 2023 19:12:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702408335; bh=DR2Fa3ovjeZyoem+oDl1suN899iJhJUC8UTSzsABCII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LRYglFPHtFeydr48Km9Sa9erA75e8UthD942v4D8hIgASGiY2dwkC4QPS0tMb9Gcr 9e2sSgB1CAt6n4QLv8UCVbDWbcOw6TbbftaAttRkPsNY82glveOXuyIzrqT3T85D8c isiteR6bbcdJbOmGNTNw4+eY0U/SNqwAnB2f0vaneU2EigtbDeED26FrMoPMcIEHwe 3vstJeiNPH1GEP96vBMXZ6C0hZ2L9Y1ZlrfwWCqZEFyUvc0HyyBG4a9plrX1lETL7F /QYp97YiJKgnXVIy0g5DDefUk3RrahxMjmtj6c4K/VEoC7nXueQd0yeepxcdwX0uHe Et1+MU2vMFUUw== 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/5] selftests/damon/_damon_sysfs: implement kdamonds start function Date: Tue, 12 Dec 2023 19:12:03 +0000 Message-Id: <20231212191206.52917-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212191206.52917-1-sj@kernel.org> References: <20231212191206.52917-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 12 Dec 2023 11:12:27 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785104542274763650 X-GMAIL-MSGID: 1785104542274763650 Extend the tests-writing-purpose DAMON sysfs control module to support the kdamonds start functionality. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/_damon_sysfs.py | 206 ++++++++++++++++++ 1 file changed, 206 insertions(+) diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/selftests/damon/_damon_sysfs.py index 78101846ab66..6b99f87a5f1e 100644 --- a/tools/testing/selftests/damon/_damon_sysfs.py +++ b/tools/testing/selftests/damon/_damon_sysfs.py @@ -1,5 +1,28 @@ # SPDX-License-Identifier: GPL-2.0 +import os + +sysfs_root = '/sys/kernel/mm/damon/admin' + +def write_file(path, string): + "Returns error string if failed, or None otherwise" + string = '%s' % string + try: + with open(path, 'w') as f: + f.write(string) + except Exception as e: + return '%s' % e + return None + +def read_file(path): + '''Returns the read content and error string. The read content is None if + the reading failed''' + try: + with open(path, 'r') as f: + return f.read(), None + except Exception as e: + return None, '%s' % e + class DamosAccessPattern: size = None nr_accesses = None @@ -18,6 +41,35 @@ class DamosAccessPattern: if self.age == None: self.age = [0, 2**64 - 1] + def sysfs_dir(self): + return os.path.join(self.scheme.sysfs_dir(), 'access_pattern') + + def stage(self): + err = write_file( + os.path.join(self.sysfs_dir(), 'sz', 'min'), self.size[0]) + if err != None: + return err + err = write_file( + os.path.join(self.sysfs_dir(), 'sz', 'max'), self.size[1]) + if err != None: + return err + err = write_file(os.path.join(self.sysfs_dir(), 'nr_accesses', 'min'), + self.nr_accesses[0]) + if err != None: + return err + err = write_file(os.path.join(self.sysfs_dir(), 'nr_accesses', 'max'), + self.nr_accesses[1]) + if err != None: + return err + err = write_file( + os.path.join(self.sysfs_dir(), 'age', 'min'), self.age[0]) + if err != None: + return err + err = write_file( + os.path.join(self.sysfs_dir(), 'age', 'max'), self.age[1]) + if err != None: + return err + class Damos: action = None access_pattern = None @@ -30,6 +82,39 @@ class Damos: self.access_pattern = access_pattern self.access_pattern.scheme = self + def sysfs_dir(self): + return os.path.join( + self.context.sysfs_dir(), 'schemes', '%d' % self.idx) + + def stage(self): + err = write_file(os.path.join(self.sysfs_dir(), 'action'), self.action) + if err != None: + return err + err = self.access_pattern.stage() + if err != None: + return err + + # disable quotas + err = write_file(os.path.join(self.sysfs_dir(), 'quotas', 'ms'), '0') + if err != None: + return err + err = write_file( + os.path.join(self.sysfs_dir(), 'quotas', 'bytes'), '0') + if err != None: + return err + + # disable watermarks + err = write_file( + os.path.join(self.sysfs_dir(), 'watermarks', 'metric'), 'none') + if err != None: + return err + + # disable filters + err = write_file( + os.path.join(self.sysfs_dir(), 'filters', 'nr_filters'), '0') + if err != None: + return err + class DamonTarget: pid = None # todo: Support target regions if test is made @@ -39,6 +124,18 @@ class DamonTarget: def __init__(self, pid): self.pid = pid + def sysfs_dir(self): + return os.path.join( + self.context.sysfs_dir(), 'targets', '%d' % self.idx) + + def stage(self): + err = write_file( + os.path.join(self.sysfs_dir(), 'regions', 'nr_regions'), '0') + if err != None: + return err + return write_file( + os.path.join(self.sysfs_dir(), 'pid_target'), self.pid) + class DamonAttrs: sample_us = None aggr_us = None @@ -55,6 +152,40 @@ class DamonAttrs: self.min_nr_regions = min_nr_regions self.max_nr_regions = max_nr_regions + def interval_sysfs_dir(self): + return os.path.join(self.context.sysfs_dir(), 'monitoring_attrs', + 'intervals') + + def nr_regions_range_sysfs_dir(self): + return os.path.join(self.context.sysfs_dir(), 'monitoring_attrs', + 'nr_regions') + + def stage(self): + err = write_file(os.path.join(self.interval_sysfs_dir(), 'sample_us'), + self.sample_us) + if err != None: + return err + err = write_file(os.path.join(self.interval_sysfs_dir(), 'aggr_us'), + self.aggr_us) + if err != None: + return err + err = write_file(os.path.join(self.interval_sysfs_dir(), 'update_us'), + self.update_us) + if err != None: + return err + + err = write_file( + os.path.join(self.nr_regions_range_sysfs_dir(), 'min'), + self.min_nr_regions) + if err != None: + return err + + err = write_file( + os.path.join(self.nr_regions_range_sysfs_dir(), 'max'), + self.max_nr_regions) + if err != None: + return err + class DamonCtx: ops = None monitoring_attrs = None @@ -79,6 +210,46 @@ class DamonCtx: scheme.idx = idx scheme.context = self + def sysfs_dir(self): + return os.path.join(self.kdamond.sysfs_dir(), 'contexts', + '%d' % self.idx) + + def stage(self): + err = write_file( + os.path.join(self.sysfs_dir(), 'operations'), self.ops) + if err != None: + return err + err = self.monitoring_attrs.stage() + if err != None: + return err + + nr_targets_file = os.path.join( + self.sysfs_dir(), 'targets', 'nr_targets') + content, err = read_file(nr_targets_file) + if err != None: + return err + if int(content) != len(self.targets): + err = write_file(nr_targets_file, '%d' % len(self.targets)) + if err != None: + return err + for target in self.targets: + err = target.stage() + if err != None: + return err + + nr_schemes_file = os.path.join( + self.sysfs_dir(), 'schemes', 'nr_schemes') + content, err = read_file(nr_schemes_file) + if int(content) != len(self.schemes): + err = write_file(nr_schemes_file, '%d' % len(self.schemes)) + if err != None: + return err + for scheme in self.schemes: + err = scheme.stage() + if err != None: + return err + return None + class Kdamond: state = None pid = None @@ -92,6 +263,27 @@ class Kdamond: context.idx = idx context.kdamond = self + def sysfs_dir(self): + return os.path.join(self.kdamonds.sysfs_dir(), '%d' % self.idx) + + def start(self): + nr_contexts_file = os.path.join(self.sysfs_dir(), + 'contexts', 'nr_contexts') + content, err = read_file(nr_contexts_file) + if err != None: + return err + if int(content) != len(self.contexts): + err = write_file(nr_contexts_file, '%d' % len(self.contexts)) + if err != None: + return err + + for context in self.contexts: + err = context.stage() + if err != None: + return err + err = write_file(os.path.join(self.sysfs_dir(), 'state'), 'on') + return err + class Kdamonds: kdamonds = [] @@ -100,3 +292,17 @@ class Kdamonds: for idx, kdamond in enumerate(self.kdamonds): kdamond.idx = idx kdamond.kdamonds = self + + def sysfs_dir(self): + return os.path.join(sysfs_root, 'kdamonds') + + def start(self): + err = write_file(os.path.join(self.sysfs_dir(), 'nr_kdamonds'), + '%s' % len(self.kdamonds)) + if err != None: + return err + for kdamond in self.kdamonds: + err = kdamond.start() + if err != None: + return err + return None From patchwork Tue Dec 12 19:12:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 177521 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7944090vqy; Tue, 12 Dec 2023 11:12:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IGXyyMAlirV3SyMsGjYyi7vu/l5BcY1l17LCJBejaL1cJCpAnkDOShqQOS/JL2aMDpi1THs X-Received: by 2002:a17:90a:73cf:b0:28a:d508:5f5 with SMTP id n15-20020a17090a73cf00b0028ad50805f5mr659683pjk.54.1702408349700; Tue, 12 Dec 2023 11:12:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702408349; cv=none; d=google.com; s=arc-20160816; b=MM54EkT6odoJEpW7KvzFIYyyKyhkOzGOmgOwjKEIzQvH8nzbuag8oQaygg4TO+hbqg NjMuXlL7ytfKyTgAbEBpYdt84AIX0nsMdER6ucKPmR4WBpehYlQg4q0l1jvaMdMEE1ZG wYR069cI39blJWjTSNX7Xpla0A7LyUzYoWQ2awau3iPggowN7wFgKZisGVmBjAU0rayJ JBe8m+tfVr0aPU48hNkMHTrm6L/zLJ7Hp7BBjHmW8ywdDRKQfKlDPWuWHT7kF456fQae D2XqHddu3S7Q+sKYzyFlN1ZcPxIxt8/BAAoIM8jLd5ISmvJiwfDYi2nbvnl1GsEA9oB6 Kxew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gRWLBAxz+7SsKpxgT28rVVWe7oCM8SAKhqIhIhMn5oU=; fh=9H4z7/o7y4OLn0xLmjdSk9Pth53+ED/R+iGnGlnIr7g=; b=QxEFIkIbNdxbGd8WbhRehuedMt+I1h1DB3fsvria0A5kA54zlSG/nQrSczYwovPjsH 7gkH/zrN2YWt/xmjCvFvVxlGRaI2ZSBuRxDl2wuw/SNziLuI6ny7x8qQtVRFYFOoJRsg Jh8Qqs0ME2zs75FOMo8O4WUyYj5qW0oJDNrXCEwS7lP5D39FsziBESwGCfFnd9xBMl6O LHC5E0CSn4wS493j4ELUGvc7myxaN9HopXHd8QQiwgSh93UCYsyu0WJgiApsSmYCMEaO xTEjf2uDnV2g6YWS12MkNmsu5XtOE86L3t+LDd7PW+pnh9VtEBfWHY2G6ajd459udBoP RGJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rwumpu7p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id cv13-20020a17090afd0d00b00285177b43d3si9557884pjb.111.2023.12.12.11.12.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 11:12:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rwumpu7p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B702C804779D; Tue, 12 Dec 2023 11:12:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235135AbjLLTMP (ORCPT + 99 others); Tue, 12 Dec 2023 14:12:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230370AbjLLTMK (ORCPT ); Tue, 12 Dec 2023 14:12:10 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FE75D2 for ; Tue, 12 Dec 2023 11:12:17 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48521C433C9; Tue, 12 Dec 2023 19:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702408336; bh=KLuaGh8EwddqX7r2J8YW9fbCxq8vkVUE+TA3xcNvnkw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rwumpu7pqmpvnDomf+Hqsnh0almVLDis4X1s3RgGsNDBz1ZNxaQgGZbkGcHD2x/om J9NHY7Nzm0oEjemCVbKBPT7iOAW3johkbPXm490MuyodKOhYIuS5rsfTARZVtZU1E5 O0kOzVSh0a+F09ETl+b3CSjG7q+9sd3xzsgXymt5ebJVzKRQJFLuL/Kao+V7ppEse+ eg2aB2v3Z5oWVnQDpYZqszt1gRobfnX8MahYjx5ZdRL1mJJw+IPIoRr07D4ilPKjIV Bft87B19yWmf4YZud7k7g/adUKpw/LAVDb87F0MOmJoi+ySJPPFGcHbGB5tIFddkKL TRJHV+KZqehZQ== 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 3/5] selftests/damon/_damon_sysfs: implement updat_schemes_tried_bytes command Date: Tue, 12 Dec 2023 19:12:04 +0000 Message-Id: <20231212191206.52917-4-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212191206.52917-1-sj@kernel.org> References: <20231212191206.52917-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Dec 2023 11:12:27 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785104537489628387 X-GMAIL-MSGID: 1785104537489628387 Implement update_schemes_tried_bytes command of DAMON sysfs interface in _damon_sysfs.py. It is not only making the update, but also read the updated value from the sysfs interface and store it in the Kdamond python objects so that the user of the module can easily get the value. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/_damon_sysfs.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/selftests/damon/_damon_sysfs.py index 6b99f87a5f1e..e98cf4b6a4b7 100644 --- a/tools/testing/selftests/damon/_damon_sysfs.py +++ b/tools/testing/selftests/damon/_damon_sysfs.py @@ -76,6 +76,7 @@ class Damos: # todo: Support quotas, watermarks, stats, tried_regions idx = None context = None + tried_bytes = None def __init__(self, action='stat', access_pattern=DamosAccessPattern()): self.action = action @@ -284,6 +285,19 @@ class Kdamond: err = write_file(os.path.join(self.sysfs_dir(), 'state'), 'on') return err + def update_schemes_tried_bytes(self): + err = write_file(os.path.join(self.sysfs_dir(), 'state'), + 'update_schemes_tried_bytes') + if err != None: + return err + for context in self.contexts: + for scheme in context.schemes: + content, err = read_file(os.path.join(scheme.sysfs_dir(), + 'tried_regions', 'total_bytes')) + if err != None: + return err + scheme.tried_bytes = int(content) + class Kdamonds: kdamonds = [] From patchwork Tue Dec 12 19:12:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 177525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7944328vqy; Tue, 12 Dec 2023 11:12:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4txyss13dG2VAax1S7mLieFSCloywXJG+i+skuR2lWjrCImRqoiWWRhL5T6jbiWYCQ7al X-Received: by 2002:a17:902:da8b:b0:1d0:6ffd:e2b6 with SMTP id j11-20020a170902da8b00b001d06ffde2b6mr7036973plx.80.1702408370157; Tue, 12 Dec 2023 11:12:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702408370; cv=none; d=google.com; s=arc-20160816; b=BT55FZB7FKhFhv4XRzy4RTRlUHEU6oksHjtqs6ownQg15mzl9Tv1buQbGAoUpSur6t ubvs+nEDB6SOUmfgIdD+h5wP3OKbfsmRSToKuGo7poPdKUB3v+FGVCnivmzq/3FcfiNP C5GB8i4q1+VM/Zla8yENJsQl2ZpSuai8ixqzhiHF+IwrxBesVB5kvUeZy12L0msu3po0 HyjigvpH9eCC19Va/vDoTRVlf0MSUkDJyBMr0gakwBgOk/E5be6iNUoVM8wxZ2QAJMLd YPTtxCdy6gnKjrm2BgZIfWN9ZBN1RSABqLJmnDa3BENZWKHVho1sRCD9llwKciuOl/xN 8SiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3VJ726YN6plBtchnpzMPTU6q7cVzWCsC5Cn68VzccxA=; fh=9H4z7/o7y4OLn0xLmjdSk9Pth53+ED/R+iGnGlnIr7g=; b=oDgUQY4fmMAKIit0AUwxlNKf0Z2DV3lKRgyDxtHZJZLE+ChgHdD95ztxQYY4egNdDM w+6fPLAcMK1352jzECwc7hqYOf08E8AROJ3OQu0prNEeN9ALltNdrU/PNqoo0PD9ngyx 7W5kd7msz92XjaGVm3VH0zwhVUZLfK0jEPp4wytYfTWNXVFOz+cE3Duez9oLkROA1E2R F3LMujr+YN4kgfpMS4XPKkLH3pEUnjpHBoYNOP9c5ppLS5z3lzR7qzstriVB3hqWmkWD B+erdhKFjVcwqyDhNN+k7fOpZkfz+RsWOoZrMiQ6MeLNxv0PNLyMuWXxCBEbV4/qDCgn EX8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ogvwZ8Mn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id x3-20020a170902ea8300b001d07490028bsi8173052plb.178.2023.12.12.11.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 11:12:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ogvwZ8Mn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 2449C80A90E2; Tue, 12 Dec 2023 11:12:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377197AbjLLTMS (ORCPT + 99 others); Tue, 12 Dec 2023 14:12:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377118AbjLLTMM (ORCPT ); Tue, 12 Dec 2023 14:12:12 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0F60AF for ; Tue, 12 Dec 2023 11:12:18 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAEBAC433C8; Tue, 12 Dec 2023 19:12:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702408338; bh=Nae8nBQge9ILU6mOkKP2BWSbfolFXrAD4ZUt2jzv2tE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ogvwZ8MntEnfHRb+BB81wAbNlQrUsGfiI02mB3lXfwqqxzVxq0LV2k+kUXz9bjedX xpR74JJercrj9aD09mx99JV8Cx44NCcQHbEEsd2yHf+iJyduUkZrw2xRveOHsBqS0S neGGA6Gg72oX/Rr6gP8WitqOUuCIYSSOvdwQ/7k8wyfrwcx0CaH9KVzMhYfDB8HTuq knP81Jn2ELPbWLrbC7o3RDxOGraCLtOJsiqrSi3AClriuVx4Aijrvqm4Bz+OJJnr53 Tep0z/RiPk92+WwbzKVlV3HSOXsIvFvx12hXqzbOuj5hIOfYx0oPWubYFS075bgYm0 CEauJGxnArJ2w== 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/5] selftests/damon: add a test for update_schemes_tried_regions sysfs command Date: Tue, 12 Dec 2023 19:12:05 +0000 Message-Id: <20231212191206.52917-5-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212191206.52917-1-sj@kernel.org> References: <20231212191206.52917-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 12 Dec 2023 11:12:47 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785104558686696667 X-GMAIL-MSGID: 1785104558686696667 Add a selftest for verifying the accuracy of DAMON's access monitoring functionality. The test starts a program of artificial access pattern, monitor the access pattern using DAMON, and check if DAMON finds expected amount of hot data region (working set size) with only acceptable error rate. Note that the acceptable error rate is set with only naive assumptions and small number of tests. Hence failures of the test may not always mean DAMON is broken. Rather than that, those could be a signal to better understand the real accuracy level of DAMON in wider environments. Based on further finding, we could optimize DAMON or adjust the expectation of the test. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/Makefile | 2 + tools/testing/selftests/damon/access_memory.c | 41 ++++++++++++++ ...te_schemes_tried_regions_wss_estimation.py | 55 +++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 tools/testing/selftests/damon/access_memory.c create mode 100755 tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_estimation.py diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile index d2105d41ea25..1363987709c6 100644 --- a/tools/testing/selftests/damon/Makefile +++ b/tools/testing/selftests/damon/Makefile @@ -4,6 +4,7 @@ TEST_GEN_FILES += huge_count_read_write TEST_GEN_FILES += dbgfs_target_ids_read_before_terminate_race TEST_GEN_FILES += dbgfs_target_ids_pid_leak +TEST_GEN_FILES += access_memory TEST_FILES = _chk_dependency.sh _debugfs_common.sh TEST_PROGS = debugfs_attrs.sh debugfs_schemes.sh debugfs_target_ids.sh @@ -11,6 +12,7 @@ TEST_PROGS += debugfs_empty_targets.sh debugfs_huge_count_read_write.sh TEST_PROGS += debugfs_duplicate_context_creation.sh TEST_PROGS += debugfs_rm_non_contexts.sh TEST_PROGS += sysfs.sh sysfs_update_removed_scheme_dir.sh +TEST_PROGS += sysfs_update_schemes_tried_regions_wss_estimation.py TEST_PROGS += reclaim.sh lru_sort.sh TEST_PROGS += dbgfs_target_ids_read_before_terminate_race.sh TEST_PROGS += dbgfs_target_ids_pid_leak.sh diff --git a/tools/testing/selftests/damon/access_memory.c b/tools/testing/selftests/damon/access_memory.c new file mode 100644 index 000000000000..585a2fa54329 --- /dev/null +++ b/tools/testing/selftests/damon/access_memory.c @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Artificial memory access program for testing DAMON. + */ + +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + char **regions; + clock_t start_clock; + int nr_regions; + int sz_region; + int access_time_ms; + int i; + + if (argc != 4) { + printf("Usage: %s