From patchwork Tue Nov 1 22:03:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13918 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3234542wru; Tue, 1 Nov 2022 15:05:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ZyrsVansP3Iv3vWn+8YEEhN/4ZQHAG4ZoWMI+eAsSxJedk1WI7R9TYYy8yPSDTci4h8Oi X-Received: by 2002:a50:ed82:0:b0:461:ab45:df1a with SMTP id h2-20020a50ed82000000b00461ab45df1amr21184564edr.295.1667340345073; Tue, 01 Nov 2022 15:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667340345; cv=none; d=google.com; s=arc-20160816; b=VC5sBLznu0WV9/7P5bDQG5pEq6eCN1b/RzuV/kXsqEIwhA3BW9eTM/jXgocjyUKXxG LvxKQkCd4MHxiqFIt8pPeFTlivz9K+iJ2LevNDqVc5gW51l0tO3GQbIvJAwn96nVZXxx 41KvDaydTmmVfrtT0d4/j/TOBC4oWOU9wgZEqTSuT5sky/bkOLBD/MVlYSSl/mZH8icY ERCEbZ36e7euBS1DKuyRkNcyv15M97xrfpokknLUpdHBL27ETSL1V/N5yiGBNh6AsL3Z nBK4/iPddC9LEOlsof/+JBmxi6Ot0+1btJtTojpbj/jJvSHxn1E7TSSgH7tiGJlvbEz5 hSDQ== 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=EXkZ4TwVf7k625+CETvzJOgBQodzs6O4Nx6b81uQxAg=; b=lyjxRbiGigPkwp3cd6sMikT290+Pzl+4wj1HPLC9fTYo9PTqJCG4tnowBcCmbaEbEA iXT07AsOxHgI4mthCTavGvOExx3WP+TR+S3ulWfVlyOOQ7qTn+61OLzevf4xw73LHOg/ HiaUAmHt0jLqHRx+ufwwiHgTAsls0oxzPBeyogvLUkgsnQ5y7SQjK85KZhC6Q9ZsB+SS hzlSkrvwbxAzIwkJmnqdqhg01TZpIPeTKdmmeVXPS59wyj3+aBrv48ME6SSKK0Yv/X1J le2OmdaA2yxXCnLMyBuHx0lApDy0yc3PgpzdRxfbpYtAMd4GEOtebQU/C7HyV5ePKpcn OJhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RLI4dX1k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i20-20020a0564020f1400b0045d4015cdcesi13128678eda.51.2022.11.01.15.05.20; Tue, 01 Nov 2022 15:05:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RLI4dX1k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231215AbiKAWDu (ORCPT + 99 others); Tue, 1 Nov 2022 18:03:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230514AbiKAWDi (ORCPT ); Tue, 1 Nov 2022 18:03:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC10563C7 for ; Tue, 1 Nov 2022 15:03:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1D2A5B81F90 for ; Tue, 1 Nov 2022 22:03:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50CFBC43470; Tue, 1 Nov 2022 22:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340213; bh=RJxfjUA7jNYJ7rWPy3bqy3nlzFdR9jtjrg0QcbRrD0Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RLI4dX1ktExmpS86A8YCkyHR1D8R29/qqVpOFjBUDqtvYEmJugGewa7sIYD5WLI9R pBLkM+jK4FtBoIt2BcpKlGqFFuw6XU3fVbXHrSubLQ5kV8nE+QBaTqpKuwaLxclSeg ktyuyFdw5fDZvOgpmgUi5NsOXzvUosBUH+h1EaupHKSxWOLPZ7ZFjZGccgji22fdsq hMKSS3z8J/fXd3CGtSG7hdLUuc3VXOgFZrqQo/QTg9eGN2pFF13QbeLIuFSsqO95L4 0w7ORnyKfxlVwQN0L0jckgI/e93A8xNYx2UNFvn5BUjBy/pHCh7lS4mzsqex25YBBT 4W4WBOLWK5pNw== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 1/8] mm/damon/core: add a callback for scheme target regions check Date: Tue, 1 Nov 2022 22:03:21 +0000 Message-Id: <20221101220328.95765-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101220328.95765-1-sj@kernel.org> References: <20221101220328.95765-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748333069864292799?= X-GMAIL-MSGID: =?utf-8?q?1748333069864292799?= Getting DAMON monitoring results of only specific access pattern (e.g., getting address ranges of memory that not accessed at all for two minutes) can be useful for efficient monitoring of the system. The information can also be helpful for deep level investigation of DAMON-based operation schemes. For that, users need to record (in case of the user space users) or iterate (in case of the kernel space users) full monitoring results and filter it out for the specific access pattern. In case of the DAMOS investigation, users will even need to simulate DAMOS' quota and prioritization mechanisms. It's inefficient and complex. Add a new DAMON callback that will be called before each scheme is applied to each region. DAMON kernel API users will be able to do the query-like monitoring results collection, or DAMOS investigation in an efficient and simple way using it. Commits for providing the capability to the user space users will follow. Signed-off-by: SeongJae Park --- include/linux/damon.h | 5 +++++ mm/damon/core.c | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 620ada094c3b..35630634d790 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -357,6 +357,7 @@ struct damon_operations { * @after_wmarks_check: Called after each schemes' watermarks check. * @after_sampling: Called after each sampling. * @after_aggregation: Called after each aggregation. + * @before_damos_apply: Called before applying DAMOS action. * @before_terminate: Called before terminating the monitoring. * @private: User private data. * @@ -385,6 +386,10 @@ struct damon_callback { int (*after_wmarks_check)(struct damon_ctx *context); int (*after_sampling)(struct damon_ctx *context); int (*after_aggregation)(struct damon_ctx *context); + int (*before_damos_apply)(struct damon_ctx *context, + struct damon_target *target, + struct damon_region *region, + struct damos *scheme); void (*before_terminate)(struct damon_ctx *context); }; diff --git a/mm/damon/core.c b/mm/damon/core.c index 80d5937fe337..ceec75b88ef9 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -772,6 +772,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, unsigned long sz = damon_sz_region(r); struct timespec64 begin, end; unsigned long sz_applied = 0; + int err = 0; if (c->ops.apply_scheme) { if (quota->esz && quota->charged_sz + sz > quota->esz) { @@ -782,7 +783,10 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, damon_split_region_at(t, r, sz); } ktime_get_coarse_ts64(&begin); - sz_applied = c->ops.apply_scheme(c, t, r, s); + if (c->callback.before_damos_apply) + err = c->callback.before_damos_apply(c, t, r, s); + if (!err) + sz_applied = c->ops.apply_scheme(c, t, r, s); ktime_get_coarse_ts64(&end); quota->total_charged_ns += timespec64_to_ns(&end) - timespec64_to_ns(&begin); From patchwork Tue Nov 1 22:03:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13912 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3233482wru; Tue, 1 Nov 2022 15:04:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7mBULSDp5itUmzvFoGcgTmaatS2kcdeO0MkSbvLGIFYu5sfri2rrXS+iar0JDo0YooNVxF X-Received: by 2002:a17:902:cccd:b0:187:733:35d1 with SMTP id z13-20020a170902cccd00b00187073335d1mr19713353ple.26.1667340241596; Tue, 01 Nov 2022 15:04:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667340241; cv=none; d=google.com; s=arc-20160816; b=EnrujLgissCwSzSdyQKwSFnwouSqyeSROMBzELl75l9KLxiL2dOCJKK66v6XoToHjw Fw+sitZBNQPyleR2LDfFd5CqbH55YwyY0MXElGsDHmY5aSGiRnJxy32dVGW/PFrxBUjH HCTuRivbHryvtQ4zuiLHkAUnrigKyXZzN19HGFKgmAYQsBkkwWja28AvTXVm0cZqzaDx 3yqMenhxev+nFTX2KYHJWB3JKOcA0Z3874SjQ+T3VYhRhIY2p0UzxeTQ+fgk7c5334ws plpKOhVMKM/P2H49cw9FSnGyHyD6Ula3anXj3lwuprE3RcSswYdD/iHEJnkzgUe70l/j E+2Q== 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=O6KK2U5/3ncofYbeOs/tMg6vCGEKqqa6+Q4m/z1r/AY=; b=0SoNyg/AZH1LHQiVXBj5Rjgjd0Qyc5MO5gZowLdPsF9MG4RHIM44sL8H6fzMKJq5uP ruVw6sXV+AW6/wb/HRHT8tbeqz83kfy1db96kF7ZCVAipB2kohxBcOi61Ur9NE+OUaWd 4+LdWqPLxcejRnGAcrlAtRNufCJndBLO9vAdi2bQk26qx5LiGSv7jsUPTLnzaNPMLV1T X4cDnqbix1w+aS5Nm8evszoZQ0Uc4yIsXPgVyK6IkTBoy8UT+chRfGAnCNT789JaB5Kk 1wg8QEPuPHtrau7Upb+Z2E20NO5PJ/3kaWCKaPWN9l3VhAOz/eTdKnBcD6AyWx7U1C1T +bMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VRXQmr3m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u10-20020a170902e80a00b00186a1c4e64dsi15785921plg.236.2022.11.01.15.03.47; Tue, 01 Nov 2022 15:04:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VRXQmr3m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231158AbiKAWDj (ORCPT + 99 others); Tue, 1 Nov 2022 18:03:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230515AbiKAWDh (ORCPT ); Tue, 1 Nov 2022 18:03:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BE2F617A for ; Tue, 1 Nov 2022 15:03:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0215A61744 for ; Tue, 1 Nov 2022 22:03:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBCDEC433D7; Tue, 1 Nov 2022 22:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340214; bh=/1k1bBlsjxjo9k4yKNnny083mrtwv5FWU+9lM1PdzeQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VRXQmr3mV2mTLz+4+nYdZKAv6AO3TB8XVGLyNXGM0nSSgG5AbZTa1in/nOl8zUDsK BM92vEa7Ze75qXBbB4lvkORJhA+DhNlHnCwC2KBcRkSKqJNwEkmf5SJYpS+6QTK9Pf ypIr8YDbRCzZ77CmCjkUo8YvVKObinMT6rMhnU3ouu9wyFV6+3ALHP7cJpJZ6lXzaC pNkzIbhS9x51U7S/LPtmIwYfozv51FCau3jFvePiUbjPwIfofxT4tj3ggUwqD8qUNM 5w4BL/hXvdy5wFxZXHz/0Ile5zLQtAzu6woU5LPH2UNUyhdf2iEP35Ae/2Qm1EgU77 HhfKu3/Ino90w== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 2/8] mm/damon/sysfs-schemes: implement schemes/tried_regions directory Date: Tue, 1 Nov 2022 22:03:22 +0000 Message-Id: <20221101220328.95765-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101220328.95765-1-sj@kernel.org> References: <20221101220328.95765-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748332961484293272?= X-GMAIL-MSGID: =?utf-8?q?1748332961484293272?= For efficient and simple query-like DAMON monitoring results readings and deep level investigations of DAMOS, DAMON kernel API (include/linux/damon.h) users can use 'before_damos_apply' DAMON callback. However, DAMON sysfs interface users don't have such option. Add a directory, namely 'tried_regions', under each scheme directory to use it as the interface for the purpose. Note that this commit is implementing only the directory but the data filling. After the data filling change is made, users will be able to signal DAMON to fill the directory with the regions that corresponding scheme has tried to be applied. By setting the access pattern of the scheme, users could do the efficient query-like monitoring. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 7ea4bcce90cb..f9714ac62565 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -9,6 +9,36 @@ #include "sysfs-common.h" +/* + * scheme regions directory + */ + +struct damon_sysfs_scheme_regions { + struct kobject kobj; +}; + +static struct damon_sysfs_scheme_regions * +damon_sysfs_scheme_regions_alloc(void) +{ + return kzalloc(sizeof(struct damon_sysfs_scheme_regions), GFP_KERNEL); +} + +static void damon_sysfs_scheme_regions_release(struct kobject *kobj) +{ + kfree(container_of(kobj, struct damon_sysfs_scheme_regions, kobj)); +} + +static struct attribute *damon_sysfs_scheme_regions_attrs[] = { + NULL, +}; +ATTRIBUTE_GROUPS(damon_sysfs_scheme_regions); + +static struct kobj_type damon_sysfs_scheme_regions_ktype = { + .release = damon_sysfs_scheme_regions_release, + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = damon_sysfs_scheme_regions_groups, +}; + /* * schemes/stats directory */ @@ -635,6 +665,7 @@ struct damon_sysfs_scheme { struct damon_sysfs_quotas *quotas; struct damon_sysfs_watermarks *watermarks; struct damon_sysfs_stats *stats; + struct damon_sysfs_scheme_regions *tried_regions; }; /* This should match with enum damos_action */ @@ -743,6 +774,25 @@ static int damon_sysfs_scheme_set_stats(struct damon_sysfs_scheme *scheme) return err; } +static int damon_sysfs_scheme_set_tried_regions( + struct damon_sysfs_scheme *scheme) +{ + struct damon_sysfs_scheme_regions *tried_regions = + damon_sysfs_scheme_regions_alloc(); + int err; + + if (!tried_regions) + return -ENOMEM; + err = kobject_init_and_add(&tried_regions->kobj, + &damon_sysfs_scheme_regions_ktype, &scheme->kobj, + "tried_regions"); + if (err) + kobject_put(&tried_regions->kobj); + else + scheme->tried_regions = tried_regions; + return err; +} + static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme) { int err; @@ -759,8 +809,14 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme) err = damon_sysfs_scheme_set_stats(scheme); if (err) goto put_watermarks_quotas_access_pattern_out; + err = damon_sysfs_scheme_set_tried_regions(scheme); + if (err) + goto put_tried_regions_out; return 0; +put_tried_regions_out: + kobject_put(&scheme->tried_regions->kobj); + scheme->tried_regions = NULL; put_watermarks_quotas_access_pattern_out: kobject_put(&scheme->watermarks->kobj); scheme->watermarks = NULL; @@ -781,6 +837,7 @@ static void damon_sysfs_scheme_rm_dirs(struct damon_sysfs_scheme *scheme) kobject_put(&scheme->quotas->kobj); kobject_put(&scheme->watermarks->kobj); kobject_put(&scheme->stats->kobj); + kobject_put(&scheme->tried_regions->kobj); } static ssize_t action_show(struct kobject *kobj, struct kobj_attribute *attr, From patchwork Tue Nov 1 22:03:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13917 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3234008wru; Tue, 1 Nov 2022 15:04:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4URGDCIxGG/0b26myOL8ywe1M0Pd5z5u+LxbpuTYjUhpwjidY3FP5jeLQdkEBSYXSvsqd8 X-Received: by 2002:a17:907:97ca:b0:791:644c:491e with SMTP id js10-20020a17090797ca00b00791644c491emr20386657ejc.555.1667340287451; Tue, 01 Nov 2022 15:04:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667340287; cv=none; d=google.com; s=arc-20160816; b=SA3GWknjd/9sVl67ADhR/bkqMfvppYDmuW7KCiRRRJiN5qc8LlT2g19woIR8i8kOKg +Iv+D8EG8sIaMraUITGbwNKB4DWZTq0hQMwwwcfavChZvCTuxYPtMF/1zatNnHLHdACo 3BmOMP7i6lglmsPzzsKxFjAv80LFnEt+gWtuukYPJ3OMTn+RZx4b99p9F2eXL37Uryem JpINldcbPS0g4QOh8zZy/41bJOngcPaSYlL+ykH7DcYe8qGWD0pepvd7VUHl5T2BGXQV hyTtneeZvQeqFDp6XwKLzgOPcYqCtmm4SYddbaKzzl2HNOaFxHmhH7+r8fFGSjXn3CuX 2kNw== 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=v/dR5inH3s1H8zXhPrusz9pz7H2K1iwxE8H3Ys03MYY=; b=xbn2rpQ0v4rdJ6vNkwbpNfgDHCuYMN0lB//xJUQ4bHD3U/PsNEONTUaizUeRN5pnC1 do+8lGnH9+r/JgIOxpcd4ILKqD79RS8v7PfIDNPelcfPfrBoCzucX6vmhlTNUdCIDjE5 ZBEYglksxVGq9GTjI2rG4oTNBNCBjvqDs6qTS5NTAhxEUfMzJ3qpHXDI3vhoj9Ph2e9O rczbem2zZ+rvnN1mYKOVR9Rv143Ybsk/NWsyNi8zmF2211SLD5wZ84JFvFqEj6IeBGLt FthrjWwsT/pg0y8HoCvS9s9aQ14cng9NuHJY749XIF6x97P2rzLSWufgPtbAg/9TC77b Optw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UxJvwbxF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd13-20020a1709069b8d00b007adef1dceffsi4337780ejc.677.2022.11.01.15.04.23; Tue, 01 Nov 2022 15:04:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UxJvwbxF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231234AbiKAWD4 (ORCPT + 99 others); Tue, 1 Nov 2022 18:03:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230512AbiKAWDj (ORCPT ); Tue, 1 Nov 2022 18:03:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90CCE6589 for ; Tue, 1 Nov 2022 15:03:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4DE34B81F7A for ; Tue, 1 Nov 2022 22:03:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 928B3C43142; Tue, 1 Nov 2022 22:03:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340215; bh=XxGyls76cTczQSYbHGWLSQPHsDHsExVHyaRCBahnUas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UxJvwbxFB1J9f80vW7kpTG/zCmaSFESpIAdMc8Amk+KLCgH1unPsrgot7xb4h8Lu6 n3Edt8+y5wwQkg7sjdMBu6qFeJp2AdKB7Kv20dM+FXWs5fATQdEbLiyaficPI2HNKX PWGBcW+HSi9MgHefe2d+5wbv2t/VWmGl0M7KwSET0rVu27ZwAWt3NMPrl1XRLpakRF RE3FPATrQYmQ9l9CPKTeL/w3fQ4R6FWb2FfhA3aj8mcUsNtJVJq6mdeqiC/9nv7edv N6hxYRWyfbCgpL/oxudbsvef6y8ewHiQ/5Jv/E0vgB5CWt0Fo1AJVWYEvHpnyzPV74 C2/h2edjDoHgA== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 3/8] mm/damon/sysfs-schemes: implement scheme region directory Date: Tue, 1 Nov 2022 22:03:23 +0000 Message-Id: <20221101220328.95765-4-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101220328.95765-1-sj@kernel.org> References: <20221101220328.95765-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748333008944103415?= X-GMAIL-MSGID: =?utf-8?q?1748333008944103415?= Implement region directories under 'tried_regions' directory of each scheme DAMON sysfs directory. This directory will provide the address range, the monitored access frequency ('nr_accesses'), and the age of each DAMON region that corresponding DAMON-based operation scheme has tried to be applied. Note that this commit doesn't implement the code for filling the data but only the sysfs directory. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 123 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index f9714ac62565..1a8ab6341bf1 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -9,18 +9,138 @@ #include "sysfs-common.h" +/* + * scheme region directory + */ + +struct damon_sysfs_scheme_region { + struct kobject kobj; + struct damon_addr_range ar; + unsigned int nr_accesses; + unsigned int age; + struct list_head list; +}; + +static struct damon_sysfs_scheme_region *damon_sysfs_scheme_region_alloc( + struct damon_region *region) +{ + struct damon_sysfs_scheme_region *sysfs_region = kmalloc( + sizeof(*sysfs_region), GFP_KERNEL); + + if (!sysfs_region) + return NULL; + sysfs_region->kobj = (struct kobject){}; + sysfs_region->ar = region->ar; + sysfs_region->nr_accesses = region->nr_accesses; + sysfs_region->age = region->age; + INIT_LIST_HEAD(&sysfs_region->list); + return sysfs_region; +} + +static ssize_t start_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + struct damon_sysfs_scheme_region *region = container_of(kobj, + struct damon_sysfs_scheme_region, kobj); + + return sysfs_emit(buf, "%lu\n", region->ar.start); +} + +static ssize_t end_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + struct damon_sysfs_scheme_region *region = container_of(kobj, + struct damon_sysfs_scheme_region, kobj); + + return sysfs_emit(buf, "%lu\n", region->ar.end); +} + +static ssize_t nr_accesses_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_scheme_region *region = container_of(kobj, + struct damon_sysfs_scheme_region, kobj); + + return sysfs_emit(buf, "%u\n", region->nr_accesses); +} + +static ssize_t age_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + struct damon_sysfs_scheme_region *region = container_of(kobj, + struct damon_sysfs_scheme_region, kobj); + + return sysfs_emit(buf, "%u\n", region->age); +} + +static void damon_sysfs_scheme_region_release(struct kobject *kobj) +{ + struct damon_sysfs_scheme_region *region = container_of(kobj, + struct damon_sysfs_scheme_region, kobj); + + list_del(®ion->list); + kfree(region); +} + +static struct kobj_attribute damon_sysfs_scheme_region_start_attr = + __ATTR_RO_MODE(start, 0400); + +static struct kobj_attribute damon_sysfs_scheme_region_end_attr = + __ATTR_RO_MODE(end, 0400); + +static struct kobj_attribute damon_sysfs_scheme_region_nr_accesses_attr = + __ATTR_RO_MODE(nr_accesses, 0400); + +static struct kobj_attribute damon_sysfs_scheme_region_age_attr = + __ATTR_RO_MODE(age, 0400); + +static struct attribute *damon_sysfs_scheme_region_attrs[] = { + &damon_sysfs_scheme_region_start_attr.attr, + &damon_sysfs_scheme_region_end_attr.attr, + &damon_sysfs_scheme_region_nr_accesses_attr.attr, + &damon_sysfs_scheme_region_age_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(damon_sysfs_scheme_region); + +static struct kobj_type damon_sysfs_scheme_region_ktype = { + .release = damon_sysfs_scheme_region_release, + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = damon_sysfs_scheme_region_groups, +}; + /* * scheme regions directory */ struct damon_sysfs_scheme_regions { struct kobject kobj; + struct list_head regions_list; + int nr_regions; }; static struct damon_sysfs_scheme_regions * damon_sysfs_scheme_regions_alloc(void) { - return kzalloc(sizeof(struct damon_sysfs_scheme_regions), GFP_KERNEL); + struct damon_sysfs_scheme_regions *regions = kmalloc(sizeof(*regions), + GFP_KERNEL); + + regions->kobj = (struct kobject){}; + INIT_LIST_HEAD(®ions->regions_list); + regions->nr_regions = 0; + return regions; +} + +static void damon_sysfs_scheme_regions_rm_dirs( + struct damon_sysfs_scheme_regions *regions) +{ + struct damon_sysfs_scheme_region *r, *next; + + list_for_each_entry_safe(r, next, ®ions->regions_list, list) { + /* release function deletes it from the list */ + kobject_put(&r->kobj); + regions->nr_regions--; + } } static void damon_sysfs_scheme_regions_release(struct kobject *kobj) @@ -837,6 +957,7 @@ static void damon_sysfs_scheme_rm_dirs(struct damon_sysfs_scheme *scheme) kobject_put(&scheme->quotas->kobj); kobject_put(&scheme->watermarks->kobj); kobject_put(&scheme->stats->kobj); + damon_sysfs_scheme_regions_rm_dirs(scheme->tried_regions); kobject_put(&scheme->tried_regions->kobj); } From patchwork Tue Nov 1 22:03:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13914 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3233730wru; Tue, 1 Nov 2022 15:04:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Bp9pa0ViX1vy/XCxSF0GxzYbvkXihsHyhXT+6dV1gjbbUxaE65FJ4C9TxNPAwA5tp3NYP X-Received: by 2002:a17:906:7119:b0:7ad:fc15:24be with SMTP id x25-20020a170906711900b007adfc1524bemr1449980ejj.199.1667340263130; Tue, 01 Nov 2022 15:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667340263; cv=none; d=google.com; s=arc-20160816; b=DhMGVv4/+3/P/lmi4GWIkWsL6vlxm9lfKcwgJEWFalgZu0k+KhdRRjgup/MzgXoYdh xIm0OXywZdaKV18VPXiDG/K8BEh2mfRGsslvTAVU10sYVnkdn2OyK/YghBLYnwybGUF0 ya0Ib+Tgdp8jCNDeeYJgKvXF1mHYTz1m1XKivgqV/uGKTLwsAW0E+cQg6zgPGrYPgpds SZhz8JTGSwHZO0utiFZlAdK2nzBGe2xKdKGiEpdtNUCZ6Jk5LbaOHKyiI5zO3XQtqhwB 8ZUP+WZgHXr5V2qC2RmHXoQ5vFcctyX5un6Io5H9BNXpvFleQVMCg6Qd/qy1NUeotF3e Ssuw== 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=kfvO97qN1uZg1TjajpDB78wKYckrQS+z/rzngB3fjqU=; b=tw85NX3A8px6Yp35wIKvDLgdjEcamL72mvdxtcScnmJuQMEA2/r2OLgf7wctzHptap 0p/r5AHF+tMns8GpWnV1h4DQu4MH2wRJljHs5cxEoT1DImL1Czehb2Rf7mwXF5RMhSBU HK4MpfnRE3VV8cJOxI5lx/+/j5CXrIU1GVeJ5iyjm600WC9NE15ompIDFzwq7kJiy6nl bh8ODw6ZN0jh6B4vFtMdyuYHwrLqqHlkUDK55tNYoDUaJAhBFcJf7H4IImsLiryprF3R xSawcKgE/ObdkKk07F5EGzi/hBSW9i9eliHrV2zeDdJjTXO7iJ5k6cwfwNXVcD3i8AUZ 4cnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NY0KGL9p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k3-20020a170906a38300b0078e071ddcb0si10377792ejz.478.2022.11.01.15.03.58; Tue, 01 Nov 2022 15:04:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NY0KGL9p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231206AbiKAWDq (ORCPT + 99 others); Tue, 1 Nov 2022 18:03:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231129AbiKAWDi (ORCPT ); Tue, 1 Nov 2022 18:03:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBF436254 for ; Tue, 1 Nov 2022 15:03:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 35CD861732 for ; Tue, 1 Nov 2022 22:03:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38F21C433C1; Tue, 1 Nov 2022 22:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340215; bh=2CYTY0LTOD+j47uyqqEPkxAe2vTbM34BEl7VdIQiTbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NY0KGL9pnY8GRjz9mElbgeCD51TS1y9GeR2s5INOEzxXIMsYm/2meHVH0xEcDnXJm vJsPZSH+M3AOlPfc0krvSGWWkOjqWxnOuhMWcSqEexGLkB0ws0sdhuTwFGQpzxSKvH pZgpmh82gjcDbk1VX9MUb1UPnYRPZbSciNV6cy83JbBCsukHoLTMiuRzumD0Zj2lZF JtrTOtcScrMnHnKUJjq5LdQ/yxaKfA8VEx4CZXcpKoZV74AQY4HyHLzD049lyabwsI R4UACiazfXFyVEc44+Yjb2WuzAI1/x6axaxyqNVkyUHNKhC7b1mbHsLERNowe4NqhP 3kS43a1xs7LVg== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 4/8] mm/damon/sysfs: implement DAMOS tried regions update command Date: Tue, 1 Nov 2022 22:03:24 +0000 Message-Id: <20221101220328.95765-5-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101220328.95765-1-sj@kernel.org> References: <20221101220328.95765-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748332984025840649?= X-GMAIL-MSGID: =?utf-8?q?1748332984025840649?= Implement the code for filling the data of 'tried_regions' DAMON sysfs directory. With this commit, DAMON sysfs interface users can write a special keyword, 'update_schemes_tried_regions' to the corresponding 'state' file of the kdamond. Then, DAMON sysfs interface will collect the tried regions information using the 'before_damos_apply()' callback for one aggregation interval and populate scheme region directories with the values. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 6 ++++ mm/damon/sysfs-schemes.c | 75 ++++++++++++++++++++++++++++++++++++++++ mm/damon/sysfs.c | 57 ++++++++++++++++++++++++++++-- 3 files changed, 136 insertions(+), 2 deletions(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 4626b2784404..634a6e7fca78 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -44,3 +44,9 @@ int damon_sysfs_set_schemes(struct damon_ctx *ctx, void damon_sysfs_schemes_update_stats( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx); + +int damon_sysfs_schemes_update_regions_start( + struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx); + +int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 1a8ab6341bf1..dd4ecd093cd6 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1198,3 +1198,78 @@ void damon_sysfs_schemes_update_stats( sysfs_stats->qt_exceeds = scheme->stat.qt_exceeds; } } + +/* + * damon_sysfs_schemes that need to update its schemes regions dir. Protected + * by damon_sysfs_lock + */ +static struct damon_sysfs_schemes *damon_sysfs_schemes_for_damos_callback; +static int damon_sysfs_schemes_region_idx; + +/* + * DAMON callback that called before damos apply. While this callback is + * registered, damon_sysfs_lock should be held to ensure the regions + * directories exist. + */ +static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, + struct damon_target *t, struct damon_region *r, + struct damos *s) +{ + struct damos *scheme; + struct damon_sysfs_scheme_regions *sysfs_regions; + struct damon_sysfs_scheme_region *region; + struct damon_sysfs_schemes *sysfs_schemes = + damon_sysfs_schemes_for_damos_callback; + int schemes_idx = 0; + + damon_for_each_scheme(scheme, ctx) { + if (scheme == s) + break; + schemes_idx++; + } + sysfs_regions = sysfs_schemes->schemes_arr[schemes_idx]->tried_regions; + region = damon_sysfs_scheme_region_alloc(r); + list_add_tail(®ion->list, &sysfs_regions->regions_list); + sysfs_regions->nr_regions++; + if (kobject_init_and_add(®ion->kobj, + &damon_sysfs_scheme_region_ktype, + &sysfs_regions->kobj, "%d", + damon_sysfs_schemes_region_idx++)) { + kobject_put(®ion->kobj); + } + return 0; +} + +/* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ +int damon_sysfs_schemes_update_regions_start( + struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx) +{ + struct damos *scheme; + int schemes_idx = 0; + + damon_for_each_scheme(scheme, ctx) { + struct damon_sysfs_scheme *sysfs_scheme; + + sysfs_scheme = sysfs_schemes->schemes_arr[schemes_idx++]; + damon_sysfs_scheme_regions_rm_dirs( + sysfs_scheme->tried_regions); + } + + damon_sysfs_schemes_for_damos_callback = sysfs_schemes; + ctx->callback.before_damos_apply = damon_sysfs_before_damos_apply; + return 0; +} + +/* + * Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock. Caller + * should unlock damon_sysfs_lock which held before + * damon_sysfs_schemes_update_regions_start() + */ +int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx) +{ + damon_sysfs_schemes_for_damos_callback = NULL; + ctx->callback.before_damos_apply = NULL; + damon_sysfs_schemes_region_idx = 0; + return 0; +} diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 284daf274b3e..ffb5a84059d7 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -999,6 +999,11 @@ enum damon_sysfs_cmd { * files. */ DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS, + /* + * @DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS: Update schemes tried + * regions + */ + DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS, /* * @NR_DAMON_SYSFS_CMDS: Total number of DAMON sysfs commands. */ @@ -1011,6 +1016,7 @@ static const char * const damon_sysfs_cmd_strs[] = { "off", "commit", "update_schemes_stats", + "update_schemes_tried_regions", }; /* @@ -1193,6 +1199,16 @@ static int damon_sysfs_set_targets(struct damon_ctx *ctx, static void damon_sysfs_before_terminate(struct damon_ctx *ctx) { struct damon_target *t, *next; + struct damon_sysfs_kdamond *kdamond; + + /* damon_sysfs_schemes_update_regions_stop() might not yet called */ + kdamond = damon_sysfs_cmd_request.kdamond; + if (kdamond && damon_sysfs_cmd_request.cmd == + DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS && + ctx == kdamond->damon_ctx) { + damon_sysfs_schemes_update_regions_stop(ctx); + mutex_unlock(&damon_sysfs_lock); + } if (!damon_target_has_pid(ctx)) return; @@ -1225,6 +1241,27 @@ static int damon_sysfs_upd_schemes_stats(struct damon_sysfs_kdamond *kdamond) return 0; } +static int damon_sysfs_upd_schemes_regions_start( + struct damon_sysfs_kdamond *kdamond) +{ + struct damon_ctx *ctx = kdamond->damon_ctx; + + if (!ctx) + return -EINVAL; + return damon_sysfs_schemes_update_regions_start( + kdamond->contexts->contexts_arr[0]->schemes, ctx); +} + +static int damon_sysfs_upd_schemes_regions_stop( + struct damon_sysfs_kdamond *kdamond) +{ + struct damon_ctx *ctx = kdamond->damon_ctx; + + if (!ctx) + return -EINVAL; + return damon_sysfs_schemes_update_regions_stop(ctx); +} + static inline bool damon_sysfs_kdamond_running( struct damon_sysfs_kdamond *kdamond) { @@ -1277,10 +1314,12 @@ static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond) static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) { struct damon_sysfs_kdamond *kdamond; + static bool damon_sysfs_schemes_regions_updating; int err = 0; /* avoid deadlock due to concurrent state_store('off') */ - if (!mutex_trylock(&damon_sysfs_lock)) + if (!damon_sysfs_schemes_regions_updating && + !mutex_trylock(&damon_sysfs_lock)) return 0; kdamond = damon_sysfs_cmd_request.kdamond; if (!kdamond || kdamond->damon_ctx != c) @@ -1292,13 +1331,27 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) case DAMON_SYSFS_CMD_COMMIT: err = damon_sysfs_commit_input(kdamond); break; + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS: + if (!damon_sysfs_schemes_regions_updating) { + err = damon_sysfs_upd_schemes_regions_start(kdamond); + if (!err) { + damon_sysfs_schemes_regions_updating = true; + goto keep_lock_out; + } + } else { + err = damon_sysfs_upd_schemes_regions_stop(kdamond); + damon_sysfs_schemes_regions_updating = false; + } + break; default: break; } /* Mark the request as invalid now. */ damon_sysfs_cmd_request.kdamond = NULL; out: - mutex_unlock(&damon_sysfs_lock); + if (!damon_sysfs_schemes_regions_updating) + mutex_unlock(&damon_sysfs_lock); +keep_lock_out: return err; } From patchwork Tue Nov 1 22:03:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13916 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3234005wru; Tue, 1 Nov 2022 15:04:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6U/ydsXNBf0OxqxAIY5Xon8ZbvucwWRU0ZpEtAwB5wX62PyFDp1WPaaZwmwXtcqDClCZGS X-Received: by 2002:a17:907:94c1:b0:792:56d7:2879 with SMTP id dn1-20020a17090794c100b0079256d72879mr21031967ejc.144.1667340286989; Tue, 01 Nov 2022 15:04:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667340286; cv=none; d=google.com; s=arc-20160816; b=qQ/wX+6kDYrXs0UurR6oimaF/M/SP8W37HbFahM9CT9p+FnewJcD40mBXsRA6mdB09 ZTlu1O938JuqmqNoP/upjyaDU/2gbxRlcvnnqwA7lWwJDQInPhOKCm2/dPqhOChs/orm Wrkr4vCWS+fkdnKtlwbwB5qrQ/VqC/ux2hLxPI6J8oCAXNeh/Tr/QCtcbfwYOAlWydjQ tm/jIcQNTsIkbxokYyMOKG7gWkHFtB+BHDVPz5htUdJFeawtPQdf92VOoaRnv73jJlyZ E/6wIiesREJeJOam5WFsgmzZh6w4951VfjF7Ub66E5Babs2iP9+mdPKG0ma8+MNXrial iAXQ== 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=NhQMagr+R0nIjlkmsHqwTFmonaoJNXjcluUt4LNy3Wk=; b=tWctJ5MH8HzitT4I+vE/w0u5SrKBYRe/qVifSt+jwEhFedFAntyp20UTf6A9XL4FEv AmuMm+bl8OoxnsiTnN+Dfi6gaw8CNavEFW+mWkAaWENP3rWiuchXphSfBj/TP3TZ0rbL 9N6AbwipBrkhkYud2ZMF4HLiW9glGheb6Sk3xYwwuZWqfPPc2zXVZJ27efXE2EjeOHC6 PCRyr9vMgu9Ow8Gwoq/PFNK1xPZcE/CU6QPn4Snr2X+wVOJ+NfyMuVdos2XN76Vryw9X 4+Kraop6sIGefqdvNZy6EXDnxdVWllwaQPL9DskBvJcs1AUeMuaGgtUFQlIcB5ur7IMu kHHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L6wTjkBd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa14-20020a1709076d0e00b00730c1850171si13928194ejc.800.2022.11.01.15.04.21; Tue, 01 Nov 2022 15:04:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L6wTjkBd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231223AbiKAWDy (ORCPT + 99 others); Tue, 1 Nov 2022 18:03:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230357AbiKAWDj (ORCPT ); Tue, 1 Nov 2022 18:03:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 381866565 for ; Tue, 1 Nov 2022 15:03:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C799C61746 for ; Tue, 1 Nov 2022 22:03:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3191C4347C; Tue, 1 Nov 2022 22:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340216; bh=Lnuz++qjG0JC7do/edydo/RT8MRUCyAyDHoJawRr9C4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L6wTjkBdABD96HBqCndDJYbQguK9IQlUs+VxKiKGMy4zPGLQb9UTBcjMLxADqPLLn 6sy06r4zbGougpPdg5OvORgCvcptReeQ6E+q9e7zAkexbBYsZYrqsZRJseNemMsKCm g6Z2u6rybAbV3UgyaJ5gWo5RA/FBiztQF8/2giC+FpE0wkQvqJwxq+jTs0NDNXSzFk Kf/Gh0u+U3Zn2BUg4iqRWdGwnkAZOq6XGxSjfkFnyo0kj6OZnWwYjEDzO2aMFAbCoG W9r9NkOXZc2kq7qDXswlwTXKGKMjjUYv41tricygG6j9gXQaJ411SOwmRhRv+l77/j ohKUbZ83uBJtw== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 5/8] mm/damon/sysfs-schemes: implement DAMOS-tried regions clear command Date: Tue, 1 Nov 2022 22:03:25 +0000 Message-Id: <20221101220328.95765-6-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101220328.95765-1-sj@kernel.org> References: <20221101220328.95765-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748333009144368929?= X-GMAIL-MSGID: =?utf-8?q?1748333009144368929?= When there are huge number of DAMON regions that specific scheme actions are tried to be applied, directories and files under 'tried_regions' scheme directory could waste some memory. Add another special input keyword ('clear_schemes_tried_regions') for 'state' file of each kdamond sysfs directory that can be used for cleanup of the 'tried_regions' sub-directories. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 4 ++++ mm/damon/sysfs-schemes.c | 10 +++++++++- mm/damon/sysfs.c | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 634a6e7fca78..604a6cbc3ede 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -50,3 +50,7 @@ int damon_sysfs_schemes_update_regions_start( struct damon_ctx *ctx); int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); + +int damon_sysfs_schemes_clear_regions( + struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx); diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index dd4ecd093cd6..f0b616f5ffc1 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1241,7 +1241,7 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, } /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ -int damon_sysfs_schemes_update_regions_start( +int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx) { @@ -1255,7 +1255,15 @@ int damon_sysfs_schemes_update_regions_start( damon_sysfs_scheme_regions_rm_dirs( sysfs_scheme->tried_regions); } + return 0; +} +/* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ +int damon_sysfs_schemes_update_regions_start( + struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx) +{ + damon_sysfs_schemes_clear_regions(sysfs_schemes, ctx); damon_sysfs_schemes_for_damos_callback = sysfs_schemes; ctx->callback.before_damos_apply = damon_sysfs_before_damos_apply; return 0; diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index ffb5a84059d7..aeb0beb1da91 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1004,6 +1004,11 @@ enum damon_sysfs_cmd { * regions */ DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS, + /* + * @DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: Clear schemes tried + * regions + */ + DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS, /* * @NR_DAMON_SYSFS_CMDS: Total number of DAMON sysfs commands. */ @@ -1017,6 +1022,7 @@ static const char * const damon_sysfs_cmd_strs[] = { "commit", "update_schemes_stats", "update_schemes_tried_regions", + "clear_schemes_tried_regions", }; /* @@ -1262,6 +1268,17 @@ static int damon_sysfs_upd_schemes_regions_stop( return damon_sysfs_schemes_update_regions_stop(ctx); } +static int damon_sysfs_clear_schemes_regions( + struct damon_sysfs_kdamond *kdamond) +{ + struct damon_ctx *ctx = kdamond->damon_ctx; + + if (!ctx) + return -EINVAL; + return damon_sysfs_schemes_clear_regions( + kdamond->contexts->contexts_arr[0]->schemes, ctx); +} + static inline bool damon_sysfs_kdamond_running( struct damon_sysfs_kdamond *kdamond) { @@ -1343,6 +1360,9 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) damon_sysfs_schemes_regions_updating = false; } break; + case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: + err = damon_sysfs_clear_schemes_regions(kdamond); + break; default: break; } From patchwork Tue Nov 1 22:03:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13915 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3233986wru; Tue, 1 Nov 2022 15:04:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6TzczHHOj1+1AwMTACE9IGfs4vjZLEStsCYNQIzvFaGVzzOrBp8yDte99wmkYY1OiBTrdE X-Received: by 2002:a17:903:32cf:b0:186:e114:be9c with SMTP id i15-20020a17090332cf00b00186e114be9cmr22041723plr.136.1667340284819; Tue, 01 Nov 2022 15:04:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667340284; cv=none; d=google.com; s=arc-20160816; b=i9oqhHNQ7SeO5wTJC69bK3xjKhgGH/PsE7P8HOjR9LQp8o3gUdScuV6ppujJv8W8fR LjbFI/A1EFFejLyGZQwFX6HfvjxU81ecXvyiCqOye/NpiBwwbq2Ol8l5RiQtvYYk8PoI Mylcit+ltcWNs3AQDLswdn3AWdI5aYvRTXt0MOzgQaVcnLmUGG7l9QK6+0ZBA+FfZ9Jo 5iLuE6EtPkgSPix1de1mqCzrUm5Wzb3YDpDWwhg9rBnOWDIwTTYf8fPdM43YPonu6zVL /tEH1MUcKcrQG5EWXYAICYnkQkS0Peh5wC/dmIJ07g/BJ+sGdQ+YmmDHlklrY2+pcSoV JQgg== 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=0mnNHQHnS5UMONrCQ+JY25XGOE4490loOGbbhlBwmLA=; b=vnCg98vufuzZchZMnEj9WoPUQrgiQHf+p5DUCG8YkRmuReKMiyEgWI3Db45XWZq4Oo NXJTHne5Bx/O/5ewiyn9OfFae4SFiUXAsK4G+ByOHp7x7f6Gv+g1nekXMEVjfp8ocGO1 Zo/uDCYVt5gz+j1CKF/8Ukpz7c8/2FrfGlUs1Lpm3S7qxnDu93RiY0UvqHj5alsWEXRF SKWxCv53Mg/YfEFTU2ATeANYEXkh6gTkmLzmTbudMVTKDvW0t+sGLoI5axIrYABsYjVg Mdy9soDgO8NxJp7mViFBAW1Iov9EAYMT4mjLgNB9Rz2hwpjlEoK5vWPdeXnaDKJmoqzi MMOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BB9iuPFm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 14-20020a63174e000000b0045a5d846af1si13586620pgx.134.2022.11.01.15.04.30; Tue, 01 Nov 2022 15:04:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BB9iuPFm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231249AbiKAWD7 (ORCPT + 99 others); Tue, 1 Nov 2022 18:03:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231149AbiKAWDj (ORCPT ); Tue, 1 Nov 2022 18:03:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4BDE617A; Tue, 1 Nov 2022 15:03:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8241161733; Tue, 1 Nov 2022 22:03:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7192BC433B5; Tue, 1 Nov 2022 22:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340216; bh=vHgDcIM2X6HC9Xa44Y3Kmnj3zbAk0A48a3qye0uZNww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BB9iuPFmaCYxUJ2icGWtplwAv9fDjQQP8tssoMnF+QYSch4jkG2Gs9jcRHdDg0eLl UN8aSiWrnsriBYDwmlGxbAstIhanC5uEyC9Jlpqz+62z/zkh9J/rPvtRkVkQri7HTz vkQAMOPJG2EgQrODDLra5lazx51qMuIpWcddNcp2JSkKyg7YxGFaX6ZC+fU5aX61rP h6OeWNswACf+ieCA59Ivg5Jl6tF9P/qMwigIaQUxIlmwgrN5LNFsHwmCU8PibAHpaI lDTn7q6EgOXaDMN+LyyE4By4/ykc4vfJZ1mMCKzxY5Pf/etnSIXTU2t3JeollfAF/d JkLl+MMlB1/Mg== From: SeongJae Park To: Andrew Morton Cc: Shuah Khan , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 6/8] tools/selftets/damon/sysfs: test tried_regions directory existence Date: Tue, 1 Nov 2022 22:03:26 +0000 Message-Id: <20221101220328.95765-7-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101220328.95765-1-sj@kernel.org> References: <20221101220328.95765-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748333006188485305?= X-GMAIL-MSGID: =?utf-8?q?1748333006188485305?= Add a simple test case for ensuring tried_regions directory existence. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/sysfs.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/testing/selftests/damon/sysfs.sh b/tools/testing/selftests/damon/sysfs.sh index 89592c64462f..db4942383a50 100644 --- a/tools/testing/selftests/damon/sysfs.sh +++ b/tools/testing/selftests/damon/sysfs.sh @@ -80,6 +80,12 @@ test_range() ensure_file "$range_dir/max" "exist" 600 } +test_tried_regions() +{ + tried_regions_dir=$1 + ensure_dir "$tried_regions_dir" "exist" +} + test_stats() { stats_dir=$1 @@ -138,6 +144,7 @@ test_scheme() test_quotas "$scheme_dir/quotas" test_watermarks "$scheme_dir/watermarks" test_stats "$scheme_dir/stats" + test_tried_regions "$scheme_dir/tried_regions" } test_schemes() From patchwork Tue Nov 1 22:03:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13920 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3234691wru; Tue, 1 Nov 2022 15:06:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4n9YkImoPa4+SpdRPzPYNcrcoDBf2+8wSLBMORtYi/X2tNUXmwdFyaNtlcPMuo1hL0rB3n X-Received: by 2002:a17:907:3206:b0:780:a882:a9ac with SMTP id xg6-20020a170907320600b00780a882a9acmr20213934ejb.765.1667340361590; Tue, 01 Nov 2022 15:06:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667340361; cv=none; d=google.com; s=arc-20160816; b=vAnEvEMbZvap/55yrcSv8XcmNJL/g2+G1mrsZGn+YCOCscfgVglSHd0tCWZq4kS2f4 K/KAcTskM+17o8XqkdJlsPZuBIFNTP5BHZFCiV1M7ycEAmcYbFFrkmE8VsMQOUCWj+YR 7kdszgSuI5NDSUtWJpoW/dLSCeqM6YmyLMyrHH6s3ehoIRCr3+Gpx/PZcOR1tBJpjYmk quJ5m8VmX8oDaHYvRQIrBU6W5K1ICXqjWJwyTdbFCr0BQqiU8YVCvbN/y0NdDuUgFub/ SQPMZacM5v//k4dtujpJoqemfV8JXTDKG6RKDZOEZIz2Ep9eEiRI77Hs4aP49Vxh9E7G wpPA== 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=ZX1igYP/rs92xwNiIj8Ueo+nL/HoVT5aqpHabIfmrIY=; b=xoIUIy3OmQuZHzlXGkErFgcucKSG/vrVnJHTkvPkdo/v6o/wtvhogtugCNAezAu8gk l6HARFKZrNTBqLvQdRoX03ed4Sf+4cLjSJ9rqqwFTILsgQYB5lZrK2uGKKPlmDj+4h8K s2O0TLZ7lp5mrm4YdMpwqCpppMpeovQerTqhVohdx5HEMzcW1OnrDSqczT0rOjaiLZGL +9bOGDdLp1ppYaimH7rJp9mj5ommzVZxMNOu7MvQMnYrc4NzJ1TXB5s3uROo06ix6NwY KHwo5zVo81e33XgJ7E7VCTA2aktxjURa8JXHlKBQRBDL6sgMsDGSBCdvonTZwPZKJhDb Un+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gAuVFi8X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr12-20020a170907720c00b0073de493b83esi15927542ejc.147.2022.11.01.15.05.36; Tue, 01 Nov 2022 15:06:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gAuVFi8X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231262AbiKAWEY (ORCPT + 99 others); Tue, 1 Nov 2022 18:04:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231164AbiKAWDl (ORCPT ); Tue, 1 Nov 2022 18:03:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55B5B6565; Tue, 1 Nov 2022 15:03:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 07883B81F90; Tue, 1 Nov 2022 22:03:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C393C433C1; Tue, 1 Nov 2022 22:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340217; bh=XY/ulrYaYGf2HDwTIn5UM+YygVjoR1FVPIUX5UmsGLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gAuVFi8XC9immb+OBoh45a69etCiIxST3cQ8zlUrBziijVny5gzKm1g6mJqPwryDE gu2m/my5MjOsEff8QdTwpPM2gvreMqHywFlVaGUGE6HrZCS5jBn8HAUSAu7K0t+t8b 3+ATJxW4lPChNcbiIe/KTaGpulS+IsO62n4Zh6qaDCvakn40ifgWtX2ZMwmtuuMFis W2Dd1zQSIB/iAhpN+GeC9JlZtMW1pwuE/lQU7II4S32fjxG6RY/WSqOEzOeQ1hb4c0 9C9pYgxdYobujW+mCapDZEkkGu5CLw0gQj/h94WcbzWiluppkFQGpJWraXyg90HgV/ mpibBeqhmoKNQ== From: SeongJae Park To: Andrew Morton Cc: Jonathan Corbet , damon@lists.linux.dev, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 7/8] Docs/admin-guide/mm/damon/usage: document schemes//tried_regions sysfs directory Date: Tue, 1 Nov 2022 22:03:27 +0000 Message-Id: <20221101220328.95765-8-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101220328.95765-1-sj@kernel.org> References: <20221101220328.95765-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748333086844458063?= X-GMAIL-MSGID: =?utf-8?q?1748333086844458063?= Document 'tried_regions' directory in DAMON sysfs interface usage in the administrator guide. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 45 ++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst index c17e02e1e426..1a5b6b71efa1 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -88,6 +88,9 @@ comma (","). :: │ │ │ │ │ │ │ │ weights/sz_permil,nr_accesses_permil,age_permil │ │ │ │ │ │ │ watermarks/metric,interval_us,high,mid,low │ │ │ │ │ │ │ stats/nr_tried,sz_tried,nr_applied,sz_applied,qt_exceeds + │ │ │ │ │ │ │ tried_regions/ + │ │ │ │ │ │ │ │ 0/start,end,nr_accesses,age + │ │ │ │ │ │ │ │ ... │ │ │ │ │ │ ... │ │ │ │ ... │ │ ... @@ -125,7 +128,14 @@ in the state. Writing ``commit`` to the ``state`` file makes kdamond reads the user inputs in the sysfs files except ``state`` file again. Writing ``update_schemes_stats`` to ``state`` file updates the contents of stats files for each DAMON-based operation scheme of the kdamond. For details of the -stats, please refer to :ref:`stats section `. +stats, please refer to :ref:`stats section `. Writing +``update_schemes_tried_regions`` to ``state`` file updates the DAMON-based +operation scheme action tried regions directory for each DAMON-based operation +scheme of the kdamond. Writing ``clear_schemes_tried_regions`` to ``state`` +file clears the DAMON-based operating scheme action tried regions directory for +each DAMON-based operation scheme of the kdamond. For details of the +DAMON-based operation scheme action tried regions directory, please refer to +:ref:tried_regions section `. If the state is ``on``, reading ``pid`` shows the pid of the kdamond thread. @@ -166,6 +176,8 @@ You can set and get what type of monitoring operations DAMON will use for the context by writing one of the keywords listed in ``avail_operations`` file and reading from the ``operations`` file. +.. _sysfs_monitoring_attrs: + contexts//monitoring_attrs/ ------------------------------ @@ -255,8 +267,9 @@ to ``N-1``. Each directory represents each DAMON-based operation scheme. schemes// ------------ -In each scheme directory, four directories (``access_pattern``, ``quotas``, -``watermarks``, and ``stats``) and one file (``action``) exist. +In each scheme directory, five directories (``access_pattern``, ``quotas``, +``watermarks``, ``stats``, and ``tried_regions``) and one file (``action``) +exist. The ``action`` file is for setting and getting what action you want to apply to memory regions having specific access pattern of the interest. The keywords @@ -351,6 +364,32 @@ should ask DAMON sysfs interface to updte the content of the files for the stats by writing a special keyword, ``update_schemes_stats`` to the relevant ``kdamonds//state`` file. +.. _sysfs_schemes_tried_regions: + +schemes//tried_regions/ +-------------------------- + +When a special keyword, ``update_schemes_tried_regions``, is written to the +relevant ``kdamonds//state`` file, DAMON creates directories named integer +starting from ``0`` under this directory. Each directory contains files +exposing detailed information about each of the memory region that the +corresponding scheme's ``action`` has tried to be applied under this directory, +during next :ref:`aggregation interval `. The +information includes address range, ``nr_accesses``, , and ``age`` of the +region. + +The directories will be removed when another special keyword, +``clear_schemes_tried_regions``, is written to the relevant +``kdamonds//state`` file. + +tried_regions// +------------------ + +In each region directory, you will find four files (``start``, ``end``, +``nr_accesses``, and ``age``). Reading the files will show the start and end +addresses, ``nr_accesses``, and ``age`` of the region that corresponding +DAMON-based operation scheme ``action`` has tried to be applied. + Example ~~~~~~~ From patchwork Tue Nov 1 22:03:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13919 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3234682wru; Tue, 1 Nov 2022 15:06:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6HTJ/PWXSUVx6Fu7u/JNfZlCBVUEPhSaQOlIcNObpnp/563AKkMab/KEc1Z+NE4FAQ0l5R X-Received: by 2002:a17:907:2719:b0:782:b261:e9eb with SMTP id w25-20020a170907271900b00782b261e9ebmr21094194ejk.104.1667340361051; Tue, 01 Nov 2022 15:06:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667340361; cv=none; d=google.com; s=arc-20160816; b=d/i2RL5wY3veSP/9HquzJWoa+SjwyDRF3J4doTO0u7acdm3kixo55TnHCVNfVRwaKE 6fhJzWxHn+HhNHrZC4zVkeWO3ZW0CX8q9fNNap4/V/L93eW4IOmKmc67qTbZKytY2Ldv g94vK1gzonvkVRQziX0mcSwM1pytFcZE41JyVzdbHNbdR5qMV7AQM4+gnQEIIFkG/7ji ddrb9Xmmd7IJj6YwI61J/FFgsAycIfqs/hHQ++8qbP5U9xkhbDPGrZSxqzG77pi4FwRM gr/rhG07eyLQO81iQbGk/7V5lb2OIUNAFnvjGX4EzuoMaIoDBq0zqDna2WwMnQYSd7mF 0DWw== 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=1xE6LwUt8JFEW6cHp10wzKw8CtFRQTz0icIitbX2c/A=; b=O1YLPR8KEFoW6UrEobr+M0Cfy91gOMF7LzAk6Nj611wC0T3vAZeSxhK55Qxlj4eE26 jVjIO+ieqpBYNeiKpz4x0iGkgo6OOg+z+vBy2/jEjNPBH9rpMOQSfjZbXfGQ1vC3/cY3 IPiEUyhcOiBPLGR0SQfNQezPpwDxcx2l9nhcGIfBjO1zcI9/RRIZRef59ZAeswGNbzrn TB8EjUf6rsuGJ31Xchncy89PkYxmPg5a4ZGDZ0jOqYsat/UYti6wznIO0Swq7Y5UCYM3 Ljr/mv/o0yNU2XazD/cb4sQ77pWYEakbcJwO1MPN2d2CCq+zU/0OpMYpul6tZ58j0yPt FQKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d1CFkxeL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb30-20020a1709071c9e00b00783645da4e5si15175334ejc.582.2022.11.01.15.05.34; Tue, 01 Nov 2022 15:06:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d1CFkxeL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231200AbiKAWEW (ORCPT + 99 others); Tue, 1 Nov 2022 18:04:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231168AbiKAWDl (ORCPT ); Tue, 1 Nov 2022 18:03:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D08F363C7 for ; Tue, 1 Nov 2022 15:03:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8B53DB81E27 for ; Tue, 1 Nov 2022 22:03:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDF57C433D7; Tue, 1 Nov 2022 22:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667340218; bh=NEW3Do9blxs64Lr6AHVrrQw2/a54TWTrLKMR+YeGsds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d1CFkxeL+dqHmMQeH8SDS0lCGzwBkhf2aHgFfgMOEqNRvCflCYHQI12Oy5F8avJc3 Agchqu719Zx4qxQ1F9QY9Fmuu9lScWN27OlP+GSN8ENks8z6FLxr7PFcWxFVcFTwgj gA6AGQFnZ8ZCWiBLhAIvR1411jLd8UqsVpR/3edr9frW/3xlDwPnoik0xeNFjhX7nI tGGbpkm6EWWV+g9CuX2snpTvjQH70mGLcHELAUY+wfCG2fW3gocNniE8fHFu0uWy/l y+4kDCJjON198FMyUp6iPw83AtZSxfKqgh9DjTGVQG83gSze8ypd8Xtc/pKTHBXRCf WoKgOp7KKNYKg== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 8/8] Docs/ABI/damon: document 'schemes//tried_regions' sysfs directory Date: Tue, 1 Nov 2022 22:03:28 +0000 Message-Id: <20221101220328.95765-9-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101220328.95765-1-sj@kernel.org> References: <20221101220328.95765-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748333086126852392?= X-GMAIL-MSGID: =?utf-8?q?1748333086126852392?= Update DAMON ABI document for the 'tried_regions' directory of DAMON sysfs interface. Signed-off-by: SeongJae Park --- .../ABI/testing/sysfs-kernel-mm-damon | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentation/ABI/testing/sysfs-kernel-mm-damon index 08b9df323560..13397b853692 100644 --- a/Documentation/ABI/testing/sysfs-kernel-mm-damon +++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon @@ -27,6 +27,10 @@ Description: Writing 'on' or 'off' to this file makes the kdamond starts or makes the kdamond reads the user inputs in the sysfs files except 'state' again. Writing 'update_schemes_stats' to the file updates contents of schemes stats files of the kdamond. + Writing 'update_schemes_tried_regions' to the file updates + contents of 'tried_regions' directory of every scheme directory + of this kdamond. Writing 'clear_schemes_tried_regions' to the + file removes contents of the 'tried_regions' directory. What: /sys/kernel/mm/damon/admin/kdamonds//pid Date: Mar 2022 @@ -283,3 +287,31 @@ Date: Mar 2022 Contact: SeongJae Park Description: Reading this file returns the number of the exceed events of the scheme's quotas. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//tried_regions//start +Date: Oct 2022 +Contact: SeongJae Park +Description: Reading this file returns the start address of a memory region + that corresponding DAMON-based Operation Scheme's action has + tried to be applied. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//tried_regions//end +Date: Oct 2022 +Contact: SeongJae Park +Description: Reading this file returns the end address of a memory region + that corresponding DAMON-based Operation Scheme's action has + tried to be applied. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//tried_regions//nr_accesses +Date: Oct 2022 +Contact: SeongJae Park +Description: Reading this file returns the 'nr_accesses' of a memory region + that corresponding DAMON-based Operation Scheme's action has + tried to be applied. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//tried_regions//age +Date: Oct 2022 +Contact: SeongJae Park +Description: Reading this file returns the 'age' of a memory region that + corresponding DAMON-based Operation Scheme's action has tried + to be applied.