From: SeongJae Park <sj@kernel.org>
To: akpm@linux-foundation.org
Cc: corbet@lwn.net, skhan@linuxfoundation.org, rientjes@google.com,
xhao@linux.alibaba.com, linux-damon@amazon.com,
linux-mm@kvack.org, linux-doc@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
SeongJae Park <sj@kernel.org>
Subject: [PATCH 10/12] mm/damon/sysfs: Support DAMOS stats
Date: Wed, 23 Feb 2022 15:20:49 +0000 [thread overview]
Message-ID: <20220223152051.22936-11-sj@kernel.org> (raw)
In-Reply-To: <20220223152051.22936-1-sj@kernel.org>
This commit makes DAMON sysfs interface supports the DAMOS stats
feature. Specifically, this commit adds 'stats' directory under each
scheme directory, and makes kdamond 'state' file writing
('update_schemes_stats') to update the contents of the files under the
'stats' directory.
As a result, the files hierarchy becomes as below:
/sys/kernel/mm/damon/admin
│ kdamonds/nr
│ │ 0/state,pid
│ │ │ contexts/nr
│ │ │ │ 0/operations
│ │ │ │ │ monitoring_attrs/intervals/sample_us,aggr_us,update_us
│ │ │ │ │ │ nr_regions/min,max
│ │ │ │ │ targets/nr
│ │ │ │ │ │ 0/pid
│ │ │ │ │ │ │ regions/nr
│ │ │ │ │ │ │ │ 0/start,end
│ │ │ │ │ │ │ │ ...
│ │ │ │ │ │ ...
│ │ │ │ │ schemes/nr
│ │ │ │ │ │ 0/action
│ │ │ │ │ │ │ access_pattern/
│ │ │ │ │ │ │ │ sz/min,max
│ │ │ │ │ │ │ │ nr_accesses/min,max
│ │ │ │ │ │ │ │ age/min,max
│ │ │ │ │ │ │ quotas/ms,sz,reset_interval_ms
│ │ │ │ │ │ │ │ weights/sz,nr_accesses,age
│ │ │ │ │ │ │ watermarks/metric,interval_us,high,mid,low
│ │ │ │ │ │ │ stats/ <- NEW DIRECTORY
│ │ │ │ │ │ │ │ nr_tried,sz_tried,nr_applied,sz_applied,qt_exceeds
│ │ │ │ │ │ ...
│ │ │ │ ...
│ │ ...
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/sysfs.c | 215 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 215 insertions(+)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 9e54ed7316c6..a4ad6b473b0a 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -115,6 +115,170 @@ static struct kobj_type damon_sysfs_ul_range_ktype = {
.default_groups = damon_sysfs_ul_range_groups,
};
+/*
+ * schemes/stats directory
+ */
+
+struct damon_sysfs_stats {
+ struct kobject kobj;
+ unsigned long nr_tried;
+ unsigned long sz_tried;
+ unsigned long nr_applied;
+ unsigned long sz_applied;
+ unsigned long qt_exceeds;
+};
+
+static struct damon_sysfs_stats *damon_sysfs_stats_alloc(void)
+{
+ return kzalloc(sizeof(struct damon_sysfs_stats), GFP_KERNEL);
+}
+
+static ssize_t damon_sysfs_stats_nr_tried_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ struct damon_sysfs_stats *stats = container_of(kobj,
+ struct damon_sysfs_stats, kobj);
+
+ return sysfs_emit(buf, "%lu\n", stats->nr_tried);
+}
+
+static ssize_t damon_sysfs_stats_nr_tried_store(struct kobject *kobj,
+ struct kobj_attribute *attr, const char *buf, size_t count)
+{
+ struct damon_sysfs_stats *stats = container_of(kobj,
+ struct damon_sysfs_stats, kobj);
+ int err = kstrtoul(buf, 0, &stats->nr_tried);
+
+ if (err)
+ return -EINVAL;
+ return count;
+}
+
+static ssize_t damon_sysfs_stats_sz_tried_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ struct damon_sysfs_stats *stats = container_of(kobj,
+ struct damon_sysfs_stats, kobj);
+
+ return sysfs_emit(buf, "%lu\n", stats->sz_tried);
+}
+
+static ssize_t damon_sysfs_stats_sz_tried_store(struct kobject *kobj,
+ struct kobj_attribute *attr, const char *buf, size_t count)
+{
+ struct damon_sysfs_stats *stats = container_of(kobj,
+ struct damon_sysfs_stats, kobj);
+ int err = kstrtoul(buf, 0, &stats->sz_tried);
+
+ if (err)
+ return -EINVAL;
+ return count;
+}
+
+static ssize_t damon_sysfs_stats_nr_applied_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ struct damon_sysfs_stats *stats = container_of(kobj,
+ struct damon_sysfs_stats, kobj);
+
+ return sysfs_emit(buf, "%lu\n", stats->nr_applied);
+}
+
+static ssize_t damon_sysfs_stats_nr_applied_store(struct kobject *kobj,
+ struct kobj_attribute *attr, const char *buf, size_t count)
+{
+ struct damon_sysfs_stats *stats = container_of(kobj,
+ struct damon_sysfs_stats, kobj);
+ int err = kstrtoul(buf, 0, &stats->nr_applied);
+
+ if (err)
+ return -EINVAL;
+ return count;
+}
+
+static ssize_t damon_sysfs_stats_sz_applied_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ struct damon_sysfs_stats *stats = container_of(kobj,
+ struct damon_sysfs_stats, kobj);
+
+ return sysfs_emit(buf, "%lu\n", stats->sz_applied);
+}
+
+static ssize_t damon_sysfs_stats_sz_applied_store(struct kobject *kobj,
+ struct kobj_attribute *attr, const char *buf, size_t count)
+{
+ struct damon_sysfs_stats *stats = container_of(kobj,
+ struct damon_sysfs_stats, kobj);
+ int err = kstrtoul(buf, 0, &stats->sz_applied);
+
+ if (err)
+ return -EINVAL;
+ return count;
+}
+
+static ssize_t damon_sysfs_stats_qt_exceeds_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ struct damon_sysfs_stats *stats = container_of(kobj,
+ struct damon_sysfs_stats, kobj);
+
+ return sysfs_emit(buf, "%lu\n", stats->qt_exceeds);
+}
+
+static ssize_t damon_sysfs_stats_qt_exceeds_store(struct kobject *kobj,
+ struct kobj_attribute *attr, const char *buf, size_t count)
+{
+ struct damon_sysfs_stats *stats = container_of(kobj,
+ struct damon_sysfs_stats, kobj);
+ int err = kstrtoul(buf, 0, &stats->qt_exceeds);
+
+ if (err)
+ return -EINVAL;
+ return count;
+}
+
+static void damon_sysfs_stats_release(struct kobject *kobj)
+{
+ kfree(container_of(kobj, struct damon_sysfs_stats, kobj));
+}
+
+static struct kobj_attribute damon_sysfs_stats_nr_tried_attr =
+ __ATTR(nr_tried, 0400, damon_sysfs_stats_nr_tried_show,
+ damon_sysfs_stats_nr_tried_store);
+
+static struct kobj_attribute damon_sysfs_stats_sz_tried_attr =
+ __ATTR(sz_tried, 0400, damon_sysfs_stats_sz_tried_show,
+ damon_sysfs_stats_sz_tried_store);
+
+static struct kobj_attribute damon_sysfs_stats_nr_applied_attr =
+ __ATTR(nr_applied, 0400, damon_sysfs_stats_nr_applied_show,
+ damon_sysfs_stats_nr_applied_store);
+
+static struct kobj_attribute damon_sysfs_stats_sz_applied_attr =
+ __ATTR(sz_applied, 0400, damon_sysfs_stats_sz_applied_show,
+ damon_sysfs_stats_sz_applied_store);
+
+static struct kobj_attribute damon_sysfs_stats_qt_exceeds_attr =
+ __ATTR(qt_exceeds, 0400, damon_sysfs_stats_qt_exceeds_show,
+ damon_sysfs_stats_qt_exceeds_store);
+
+static struct attribute *damon_sysfs_stats_attrs[] = {
+ &damon_sysfs_stats_nr_tried_attr.attr,
+ &damon_sysfs_stats_sz_tried_attr.attr,
+ &damon_sysfs_stats_nr_applied_attr.attr,
+ &damon_sysfs_stats_sz_applied_attr.attr,
+ &damon_sysfs_stats_qt_exceeds_attr.attr,
+ NULL,
+};
+ATTRIBUTE_GROUPS(damon_sysfs_stats);
+
+static struct kobj_type damon_sysfs_stats_ktype = {
+ .release = damon_sysfs_stats_release,
+ .sysfs_ops = &kobj_sysfs_ops,
+ .default_groups = damon_sysfs_stats_groups,
+};
+
/*
* watermarks directory
*/
@@ -666,6 +830,7 @@ struct damon_sysfs_scheme {
struct damon_sysfs_access_pattern *access_pattern;
struct damon_sysfs_quotas *quotas;
struct damon_sysfs_watermarks *watermarks;
+ struct damon_sysfs_stats *stats;
};
/* This should match with enum damos_action */
@@ -756,6 +921,22 @@ static int damon_sysfs_scheme_set_watermarks(struct damon_sysfs_scheme *scheme)
return err;
}
+static int damon_sysfs_scheme_set_stats(struct damon_sysfs_scheme *scheme)
+{
+ struct damon_sysfs_stats *stats = damon_sysfs_stats_alloc();
+ int err;
+
+ if (!stats)
+ return -ENOMEM;
+ err = kobject_init_and_add(&stats->kobj, &damon_sysfs_stats_ktype,
+ &scheme->kobj, "stats");
+ if (err)
+ kobject_put(&stats->kobj);
+ else
+ scheme->stats = stats;
+ return err;
+}
+
static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme)
{
int err;
@@ -769,8 +950,14 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme)
err = damon_sysfs_scheme_set_watermarks(scheme);
if (err)
goto put_quotas_access_pattern_out;
+ err = damon_sysfs_scheme_set_stats(scheme);
+ if (err)
+ goto put_watermarks_quotas_access_pattern_out;
return 0;
+put_watermarks_quotas_access_pattern_out:
+ kobject_put(&scheme->watermarks->kobj);
+ scheme->watermarks = NULL;
put_quotas_access_pattern_out:
kobject_put(&scheme->quotas->kobj);
scheme->quotas = NULL;
@@ -787,6 +974,7 @@ static void damon_sysfs_scheme_rm_dirs(struct damon_sysfs_scheme *scheme)
damon_sysfs_quotas_rm_dirs(scheme->quotas);
kobject_put(&scheme->quotas->kobj);
kobject_put(&scheme->watermarks->kobj);
+ kobject_put(&scheme->stats->kobj);
}
static ssize_t damon_sysfs_scheme_action_show(struct kobject *kobj,
@@ -2163,6 +2351,31 @@ static int damon_sysfs_turn_damon_off(struct damon_sysfs_kdamond *kdamond)
*/
}
+static int damon_sysfs_update_schemes_stats(struct damon_sysfs_kdamond *kdamond)
+{
+ struct damon_ctx *ctx = kdamond->damon_ctx;
+ struct damos *scheme;
+ int schemes_idx = 0;
+
+ if (!ctx)
+ return -EINVAL;
+ mutex_lock(&ctx->kdamond_lock);
+ damon_for_each_scheme(scheme, ctx) {
+ struct damon_sysfs_schemes *sysfs_schemes;
+ struct damon_sysfs_stats *sysfs_stats;
+
+ sysfs_schemes = kdamond->contexts->contexts_arr[0]->schemes;
+ sysfs_stats = sysfs_schemes->schemes_arr[schemes_idx++]->stats;
+ sysfs_stats->nr_tried = scheme->stat.nr_tried;
+ sysfs_stats->sz_tried = scheme->stat.sz_tried;
+ sysfs_stats->nr_applied = scheme->stat.nr_applied;
+ sysfs_stats->sz_applied = scheme->stat.sz_applied;
+ sysfs_stats->qt_exceeds = scheme->stat.qt_exceeds;
+ }
+ mutex_unlock(&ctx->kdamond_lock);
+ return 0;
+}
+
static ssize_t damon_sysfs_kdamond_state_store(struct kobject *kobj,
struct kobj_attribute *attr, const char *buf, size_t count)
{
@@ -2176,6 +2389,8 @@ static ssize_t damon_sysfs_kdamond_state_store(struct kobject *kobj,
ret = damon_sysfs_turn_damon_on(kdamond);
else if (sysfs_streq(buf, "off"))
ret = damon_sysfs_turn_damon_off(kdamond);
+ else if (sysfs_streq(buf, "update_schemes_stats"))
+ ret = damon_sysfs_update_schemes_stats(kdamond);
else
ret = -EINVAL;
mutex_unlock(&damon_sysfs_lock);
--
2.17.1
next prev parent reply other threads:[~2022-02-23 15:21 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-23 15:20 [PATCH 00/12] Introduce DAMON sysfs interface SeongJae Park
2022-02-23 15:20 ` [PATCH 01/12] mm/damon/core: Allow non-exclusive DAMON start/stop SeongJae Park
2022-02-23 15:20 ` [PATCH 02/12] mm/damon/core: Add number of each enum type values SeongJae Park
2022-02-23 15:20 ` [PATCH 03/12] mm/damon: Implement a minimal stub for sysfs-based DAMON interface SeongJae Park
2022-02-23 16:09 ` Greg KH
2022-02-23 16:45 ` SeongJae Park
2022-02-23 17:13 ` SeongJae Park
2022-02-23 18:33 ` Greg KH
2022-02-23 19:03 ` SeongJae Park
2022-02-25 7:21 ` xhao
2022-02-25 8:10 ` SeongJae Park
2022-02-23 15:20 ` [PATCH 04/12] mm/damon/sysfs: Link DAMON for virtual address spaces monitoring SeongJae Park
2022-02-23 15:20 ` [PATCH 05/12] mm/damon/sysfs: Support physical address space monitoring SeongJae Park
2022-02-23 15:20 ` [PATCH 06/12] mm/damon/sysfs: Support DAMON-based Operation Schemes SeongJae Park
2022-02-23 15:20 ` [PATCH 07/12] mm/damon/sysfs: Support DAMOS quotas SeongJae Park
2022-02-23 15:20 ` [PATCH 08/12] mm/damon/sysfs: Support schemes prioritization weights SeongJae Park
2022-02-23 15:20 ` [PATCH 09/12] mm/damon/sysfs: Support DAMOS watermarks SeongJae Park
2022-02-23 15:20 ` SeongJae Park [this message]
2022-02-23 15:20 ` [PATCH 11/12] selftests/damon: Add a test for DAMON sysfs interface SeongJae Park
2022-02-23 15:20 ` [PATCH 12/12] Docs/admin-guide/mm/damon/usage: Document " SeongJae Park
2022-02-23 16:07 ` [PATCH 00/12] Introduce " Greg KH
2022-02-23 16:44 ` SeongJae Park
2022-02-25 7:32 ` xhao
2022-02-25 8:05 ` SeongJae Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220223152051.22936-11-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=linux-damon@amazon.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=skhan@linuxfoundation.org \
--cc=xhao@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox