From patchwork Sat Dec 2 00:08: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: 172725 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1495562vqy; Fri, 1 Dec 2023 16:10:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGQejPn6oDZ+x4rSZW0D0gOVPJtF9MSOGGTimxyE/eO3fwHOXh5zVXsiOHgO0LuOG8ClYER X-Received: by 2002:a05:6e02:de5:b0:35d:59a2:2bf with SMTP id m5-20020a056e020de500b0035d59a202bfmr350522ilj.95.1701475856375; Fri, 01 Dec 2023 16:10:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701475856; cv=none; d=google.com; s=arc-20160816; b=d7/wKKQmjANSsMDf04bNeoG0OuYFmAnqeDSgpiTscLGVh3u+qU8h4mTw1+CpztjLFl idOl0B8l8uYMYu/rHb8NGjTiUEsnFnNr9ld2fojv3zLGAQwwIWZPr+vyz/dcI9WGKfdh QYaNB6La9v7AK9vvWliTWdfJHbCgLi25wer7D0MCxcz6mnUX2mwCTCKfDWAswA8z7b9Q aZMXKsHZsMsVshzlWdX/b3j4gjTjprcjefAjjV6bk33hd2Pc6lEgppXVIbuD2uHsoKaO SMMNvAEcqsOXwj9Z3EV+GSmNR9KNppyNCwHpe+MY9ahPVGbGBOt2BYysuAQFKgzvk4g3 OPJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=OsypTyUMi/Yh1aH0wXO7Cp4Fx6Odu0Zkog1frADmOxo=; fh=W+de0FjxL1MlRh6Ly02q9tA2/xTz2DOJsg1VkI/mHfI=; b=Z3M668SKL3pU6+3txV6mj7LLURjz9Cugl8JT5yQ30QAq2LRYubSY75S7ok6ZApWS5Y MJMzLXVzW9eEGHD5u78hx7OmNX+safseCGrFyTnGqZkbCv9zjibQ7bDEeUws/Q5SbPKr meoX+064axErthxFotn0FrI7SY29cvnmbFg49v4K59CP8yyFmr78znm3PD6GhRUiikhj 25PtwrnNso5XPPqH/u68zG2bHr7FrXc1B5Oq3mrK62TfMU/idSaZZrqEmCEhBPCaS7iW 2qSDpHn7xrxgs5naWnLP3lxxkJzbAzfSF0CHpImbMAmXmFAl8SgDDrYpBy/yP8xZRHbv TkTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=ftiBRtoD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id bj10-20020a056a02018a00b005c622d45e68si4516470pgb.549.2023.12.01.16.10.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 16:10:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=ftiBRtoD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id DBEDD80CCD28; Fri, 1 Dec 2023 16:10:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441940AbjLBAKU (ORCPT + 99 others); Fri, 1 Dec 2023 19:10:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235375AbjLBAKE (ORCPT ); Fri, 1 Dec 2023 19:10:04 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C0F41FC1 for ; Fri, 1 Dec 2023 16:09:07 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C2B1C433C8; Sat, 2 Dec 2023 00:08:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701475690; bh=GC7hLao6eamt5j9k8hcen8vPzgOkrgeme7Xf5lpgbH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ftiBRtoD5yl3wEraHqbN9wNqd+G6GNBLIgbbxpKOrAHe8oFCL7SBEpqsjBQ3FBZjl kJ0M6ueGJRGdyNixjGCs/yCwrSiN7nBkW5cf+rEdlaQjsoqvMrJtS6mUTqdMYIUrWG duoCJbg0mJe1uhfD2luVEvn0EEQBvfItemXsQ8n24Xxtl1H/RsVHr3Kj0QU4Wz+mUM 9zSYm9L2V6rsZyDO5M2QQmhJldTJuxZGroKBuSpCk5DHoBxirlz8Csr0eOaiPeLFmM MHlCMPu6dHhXS7RgkofjSyJaxpu2deByYIQbzJC6XJolAfJ8xa8JM9pIzZOPL0nDHA LsMkoitTUar3g== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , Shuah Khan , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/5] selftests/damon: add a DAMON interface wrapper python module Date: Sat, 2 Dec 2023 00:08:02 +0000 Message-Id: <20231202000806.46210-2-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231202000806.46210-1-sj@kernel.org> References: <20231202000806.46210-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, 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 agentk.vger.email To: unlisted-recipients:; (no To-header on input) 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 (agentk.vger.email [0.0.0.0]); Fri, 01 Dec 2023 16:10:36 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784126747390403889 X-GMAIL-MSGID: 1784126747390403889 DAMON sysfs interface supports almost every DAMON functionality. For that, it provides a number of files and hierarchies that not simple to be manually manipulated, or writing shell script every time. For the reason, DAMON is not having good functionality selftests. Adding an existing DAMON user space tool and using it could also be a way, but it would add unnecessarily huge change that not essential for the test purpose. Write a minimum python module that can further extended to be used as an easy-to-use DAMON functionality test purpose DAMON user interface wrapper. Note that this commit is implementing only basic data structures for representing the sysfs files. More operations will be implemented by following commits, as needed for specific real test cases. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/_damon.py | 102 ++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 tools/testing/selftests/damon/_damon.py diff --git a/tools/testing/selftests/damon/_damon.py b/tools/testing/selftests/damon/_damon.py new file mode 100644 index 000000000000..78101846ab66 --- /dev/null +++ b/tools/testing/selftests/damon/_damon.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 Sat Dec 2 00:08: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: 172727 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1495667vqy; Fri, 1 Dec 2023 16:11:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IE/2lE0kQBQjZjlTUNlqOvv5jbpCiOkgzkI2CWPLoykI0hCmp3wRGEfDlF5aQmLdbT0QR/e X-Received: by 2002:a05:6870:7a09:b0:1ea:d76b:1457 with SMTP id hf9-20020a0568707a0900b001ead76b1457mr535718oab.7.1701475872735; Fri, 01 Dec 2023 16:11:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701475872; cv=none; d=google.com; s=arc-20160816; b=Vl2iHf13kT4XGulHAr/QVLDJUOQYEW0s5WCK8iZ+tEW8y+LnjgeM/YMA2jHKorUGmQ jxH9HbOBHkTaOVHKa40gXT0kXNpTa4Vpzs1SO9sOENl1Dhesuc33S4uhz9aRwLjts3Oa /3iefzt91DqPgc7Z8EpyP24IG6M4SNrFyeM7nVaxCOGKmgJBEq6lZ5v3JRN/2Sd6WOZV iVX4r/hO0Ef/h5Hjtf/muZ9Q1riagxbCHQopuWVFBufoqemU71CH0XGSTaPKY6I+OcAU H68UMpl4nue9zzJXwYqJ9LlB2RmhRKJxbcQCDUhgq2B5PobcQlLlFbpT1h6jbF+kT8MV C0Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=geJbZJJvBae4jqe1AheshTuaF1oJvqnxOcUWPSWBKx8=; fh=W+de0FjxL1MlRh6Ly02q9tA2/xTz2DOJsg1VkI/mHfI=; b=V8+A85peWCvrRtU+nAaM/TY5inpLOXiiD+C9EoavmAS36h3YF4WG7gPfs5e7e9AK88 YQdG/TLrimRtDgdQVLWnxTx0DsS9qwnU1p1g2E1UY4PHiQz6skDomrLGzf1mlhYHAzuZ o3VbbUcBcOenLWlNqcuzpjS/WtlMnmkjRi6mLbFTsZjPPVCC+yeONg9LOpDa+yDahLF4 BzZzhYex95wEVODL1yQbkuvqZN6Y2LvSBPk4f6wkOKyJdbmyqONbz6spvqaU+eREF/eW ji0gc98DwTyxg+F4ugGQ21htbOk4GCq44cH8Fe1rjPVhHLC8RTITp8O9OtUa64vaV6EO 1Brw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b="St1SM/T6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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. [23.128.96.37]) by mx.google.com with ESMTPS id 14-20020a63000e000000b005b8f45e32c8si4114638pga.776.2023.12.01.16.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 16:11:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b="St1SM/T6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 5BBA0806290D; Fri, 1 Dec 2023 16:11:11 -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 S1442013AbjLBALC (ORCPT + 99 others); Fri, 1 Dec 2023 19:11:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442086AbjLBAKp (ORCPT ); Fri, 1 Dec 2023 19:10:45 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2A1B3858 for ; Fri, 1 Dec 2023 16:09:07 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF60BC433D9; Sat, 2 Dec 2023 00:08:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701475691; bh=AwGT0TApqer7c6nSE0CIfNlDk2EEXmB7q5dDIYgH5bg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=St1SM/T6xISZDuqc/o8B1ANd9sw6LFQh8VK/f7EoOzTNUR4g7rzXiS1hZynIoPxES +nMkWRfV8caIcUBS38lTfH0DLfRc7n2PovLMBPtG7LJEzDmix7RmY0KUJsbX5bIPO5 GzEClqUyvi0tYdRq7Ekmt0QY2g0MGASEcBPdlUvVT+7/WsPmTtzUCKmVpib1y3Yu/1 B6nAGYY4WjDdUDk5tmZZ8jD2cVq1koMg0oxvSz7odEdd1TWGrzXxSeMrU1tjBQP9fR ZH7SVUwKuWrzURd6+3x387eEKnNktbMqJoeAtaux/7rvndIhARQB0ynXH+g1r8fay5 xYkJVtP412jrQ== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , Shuah Khan , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/5] selftests/damon/_damon: implement sysfs-based kdamonds start function Date: Sat, 2 Dec 2023 00:08:03 +0000 Message-Id: <20231202000806.46210-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231202000806.46210-1-sj@kernel.org> References: <20231202000806.46210-1-sj@kernel.org> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) 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]); Fri, 01 Dec 2023 16:11:11 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784126764466974226 X-GMAIL-MSGID: 1784126764466974226 Extend the test-writing-purpose DAMON sysfs wrapper Python module to support turning DAMON on with basic parameter inputs. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/_damon.py | 206 ++++++++++++++++++++++++ 1 file changed, 206 insertions(+) diff --git a/tools/testing/selftests/damon/_damon.py b/tools/testing/selftests/damon/_damon.py index 78101846ab66..6b99f87a5f1e 100644 --- a/tools/testing/selftests/damon/_damon.py +++ b/tools/testing/selftests/damon/_damon.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 Sat Dec 2 00:08: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: 172728 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1498931vqy; Fri, 1 Dec 2023 16:18:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4FFkl5Z8CI3BRAVCdy/MvuKGQ6AN+a9zvYv16c4dQ+DBuF6vN/fGUWchy3ORRVCITpkLO X-Received: by 2002:a05:6a00:1787:b0:6ce:2731:a084 with SMTP id s7-20020a056a00178700b006ce2731a084mr357392pfg.51.1701476310283; Fri, 01 Dec 2023 16:18:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701476310; cv=none; d=google.com; s=arc-20160816; b=urlvwfR2/MlBa6cEGfut+8yDySYwlZrbguFcwmzH5pePzDeFS76BQPHlJ7mDOtTmNZ BnJ9f8P/psv93sj7fIYxT2XrQXymY5IBjeWpf/vedw58DQeRLUJr3y6wKrdkpHDUhIwL 5tp3NjIvVlWSYEBzR+7LTDFw7bXr7lm8mNcApQEZi7oku/lCtQABgJEIVD3teS/GWEih VPi3UwuDr6jVysesNQdmZvGcVyPEl/5frK3cZAr6cw7SlhCbjFbJUWmhBZxiBpl2lz7D nBi7l4bT7NjhdCurd5QNJG6ehOvfkitz1oUTF54U10u6ey1auSozRB/RrZ63yMj8m+QF EF2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=HB7YT4DZo+K0VqrRFyhIZVeyqMtkSZH657BYvby+SPg=; fh=W+de0FjxL1MlRh6Ly02q9tA2/xTz2DOJsg1VkI/mHfI=; b=UdDTVFSYNlMW4HyKhmOHtRDn6m/GRH+ghIcXq7f1+yh0d89LnH34vt3M9pem1iUGFv JzyyW5Nlc4q3Qv8uSyYhfsqDWXfeUOv5MuqzZcRl25opY56uze/ublCgj8CA3vblYTb9 cI0SKFekwpuxJjsM1jz4DRLDKGUEjg/61+iHYIOjYXA+PR5NiKc0Hjbl/5eRTqUDBKYo 4LjVW/RXcSjm3XnjzC16gdDn4vyGX6N+ESi+uH1YvyYx+UyV94VU7pdnUz3ZaoZMcg/w Aq++P767XWbeE9+Ta35Bh0qOgflgwG/26FpWMdY7YU/5lbFpt6DKI7ZPwoXoZTeS6oRT K4VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=uXPiW5Mb; 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 bd5-20020a656e05000000b005b9a467330esi4532253pgb.707.2023.12.01.16.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 16:18:30 -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=fail header.i=@kernel.org header.s=k20201202 header.b=uXPiW5Mb; 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 08CE680747A8; Fri, 1 Dec 2023 16:18:29 -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 S1441961AbjLBAST (ORCPT + 99 others); Fri, 1 Dec 2023 19:18:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235320AbjLBASM (ORCPT ); Fri, 1 Dec 2023 19:18:12 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FB6CD6C for ; Fri, 1 Dec 2023 16:09:08 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90E4BC433CC; Sat, 2 Dec 2023 00:08:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701475692; bh=dA3cXZTPwGuBFjfk7vBFspKqwxyw85dB6htp3+62oIU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uXPiW5MbtvQcnrRYD9LYG6mn7RPYtIY3MPhQVnAIMhOAdgc6mI0apmxk5JCelCtZv 6Ef9xyeOkzma+9AS+KiXQD8I/La8iDXltv9baKzkgE40yj4y6v44bDlF1mayazsOI3 SZFeTh4Tmcj02tZnymikNK28FWnUE/o8TbsvA9jgSaCvsqcaXZZVQW4sGpyxYe9loS 65NI2gsSjyWNLTNdcdhF48SDc0MkwKk/ahnphuUPocqrvxadSAe2Ob54OKR3XrkyhS WA+RUPrD1WxoIt4tCTJQpKbfR3p09U/4BYqfCsjWEzLdX8FSzD8WCxE124eZnpBkaY E1BPJj/Hl8xpA== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , Shuah Khan , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/5] selftests/damon/_damon: implement sysfs updat_schemes_tried_bytes command Date: Sat, 2 Dec 2023 00:08:04 +0000 Message-Id: <20231202000806.46210-4-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231202000806.46210-1-sj@kernel.org> References: <20231202000806.46210-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 To: unlisted-recipients:; (no To-header on input) 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]); Fri, 01 Dec 2023 16:18:29 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784127223718375002 X-GMAIL-MSGID: 1784127223718375002 Implement update_schemes_tried_bytes command in the test-writing-purpose DAMON sysfs interface wrapper Python module. It is not only making the update, but also read the updated value from the sysfs interface and store on the Kdamond python objects so that user of the module can get it by reading the field of the object. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/_damon.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/testing/selftests/damon/_damon.py b/tools/testing/selftests/damon/_damon.py index 6b99f87a5f1e..e98cf4b6a4b7 100644 --- a/tools/testing/selftests/damon/_damon.py +++ b/tools/testing/selftests/damon/_damon.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 Sat Dec 2 00:08: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: 172724 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1495441vqy; Fri, 1 Dec 2023 16:10:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHg/OKREw5ImKVTGNc3YYfqEjRrhP9xXj2SFkV8bXvW8Dm4xpF0NWzYC5WcsQQ8gMTtp6M5 X-Received: by 2002:a05:6a20:3d95:b0:189:bde9:71aa with SMTP id s21-20020a056a203d9500b00189bde971aamr499317pzi.48.1701475839224; Fri, 01 Dec 2023 16:10:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701475839; cv=none; d=google.com; s=arc-20160816; b=Brj5t3Vca0E6NGcYD1hrw6faduCXXqjIezw5DAtQTGznc28HlN73BbD1SH2N30irQ5 evrF1/Pm24AgRHb/jIZJVi4s+dNgCk6RYpwhxe2U3f8b6dfpC00ubhaPB0bfxEfIzU2s Iqz7fGxvJRpWPyDBHFs/BXrWLtWy0+8O8TMOX/bC94uRMHP6JCgkD9lqpn7NoQAe4KUL 9mnDXxqDoH7Snr4E5DlKnET73qtx+q7P/kbwgQh19ZwWnot8KfVZlOwo+FNDXcLZJI0v wVioodCWO3BWsT9B2idILJfDsHk53ICddmHRYBAnys3UyroepHtIBSlU4E3ZzBzsz/MY 9VjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=FzQSkGprvCjYi1PSKTyL9VXCZYB/89pkL/cEpZOg+KI=; fh=W+de0FjxL1MlRh6Ly02q9tA2/xTz2DOJsg1VkI/mHfI=; b=WrkVg/gLARFqgRUfqmjRZsE26ctCasYhQkqRk7Wesc0LCr3yJLxvk4e2GtMzjTpeKf 2RsL+nyHLa/wH936PYkYb152Q8iRTxkiAXZedPsMDxbP6CMppjoCSeVbb6WcUy4ha1n7 8MVvVdD6LsxUiLYpBAWKbsMtDY1u70L1j/YCVo5APtwSjiP2YjTsMMnCpqinJflF+RAx FUZJIxri0jeDhbV3ilXpxZEFySVwQQoYwcgSZ3D8P/XFWsJkUpnuIxKBX+x6SZfzULry gVaAGmusea+f/4A9n54Xq/z/XDfOsyMZyPjGTHTOlPOfn3gw8b6Wnk85oBvwxkKK4u6e CyQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=eS0GQJL0; 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 bw29-20020a056a02049d00b005c62447fde6si4384765pgb.98.2023.12.01.16.10.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 16:10:39 -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=fail header.i=@kernel.org header.s=k20201202 header.b=eS0GQJL0; 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 F2628809BE43; Fri, 1 Dec 2023 16:10:35 -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 S1442003AbjLBAKW (ORCPT + 99 others); Fri, 1 Dec 2023 19:10:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235382AbjLBAKE (ORCPT ); Fri, 1 Dec 2023 19:10:04 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09EDB386F for ; Fri, 1 Dec 2023 16:09:10 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4343FC433CB; Sat, 2 Dec 2023 00:08:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701475692; bh=RPGqDNVbRfHZdHfv52ZXw/68V6PB6K+dkXKHSqnAU/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eS0GQJL0HFbLi29VHlV8HHJ66TzvYLdR6ptWgktTsJ+ve9HpARkVXJ/lTBvWM6PZ0 PcWeIAFDosQS6fItHLeCOtbITCASeM/mpK+1bIDecMd3ZDk/GHSdwSI8rnxo4RmEM6 /owzTnEWigKz9PIuqsPveep8ynF6jpKJAPEq+17cmIjo57c/pnE1yffaPTz36+nU3y OovjM/a6n6c2AdBjkFzAk9sPQdD0WWldR607zXYsbdhafadiPe8M1QDMtrlJrVqFvq k2Ig07layGEKD0GjJSSonWptIfJPglIdFsIUjlUhxMw+0sxb4t6zaS7yXbnIipwjtx r0vwISU4ttEjg== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , Shuah Khan , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 4/5] selftests/damon: add a test for update_schemes_tried_regions sysfs command Date: Sat, 2 Dec 2023 00:08:05 +0000 Message-Id: <20231202000806.46210-5-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231202000806.46210-1-sj@kernel.org> References: <20231202000806.46210-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, 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 To: unlisted-recipients:; (no To-header on input) 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]); Fri, 01 Dec 2023 16:10:36 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784126729768332946 X-GMAIL-MSGID: 1784126729768332946 Add a basic test for verifying accuracy of DAMON's access monitoring functionality. The test starts a program of artificial access pattern, monitor the accesses using DAMON, and check if DAMON gets working set size with reasonable amount of error rate. Note that the acceptable error rate is set with only a naive assumption. Failure of this test may not always mean DAMON is broken, and we could adjust it in future. 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 | 48 +++++++++++++++++++ 3 files changed, 91 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