* [RFC PATCH v2 01/10] mm/damon: document damos_quota_goal->nid use case
2025-10-09 21:20 [RFC PATCH v2 00/10] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
@ 2025-10-09 21:20 ` SeongJae Park
2025-10-09 21:20 ` [RFC PATCH v2 02/10] mm/damon: add DAMOS quota goal type for per-memcg per-node memory usage SeongJae Park
` (8 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: SeongJae Park @ 2025-10-09 21:20 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm
damos_quota_goal kerneldoc comment is not explaining when @metric is
used. Update the comment for that.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
include/linux/damon.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index cae8c613c5fc..dc9c310e0e75 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -176,6 +176,9 @@ enum damos_quota_goal_metric {
* If @metric is DAMOS_QUOTA_USER_INPUT, @current_value should be manually
* entered by the user, probably inside the kdamond callbacks. Otherwise,
* DAMON sets @current_value with self-measured value of @metric.
+ *
+ * If @metric is DAMOS_QUOTA_NODE_MEM_{USED,FREE}_BP, @nid represents the node
+ * id of the target node to account the used/free memory.
*/
struct damos_quota_goal {
enum damos_quota_goal_metric metric;
--
2.39.5
^ permalink raw reply [flat|nested] 13+ messages in thread* [RFC PATCH v2 02/10] mm/damon: add DAMOS quota goal type for per-memcg per-node memory usage
2025-10-09 21:20 [RFC PATCH v2 00/10] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
2025-10-09 21:20 ` [RFC PATCH v2 01/10] mm/damon: document damos_quota_goal->nid use case SeongJae Park
@ 2025-10-09 21:20 ` SeongJae Park
2025-10-09 21:20 ` [RFC PATCH v2 03/10] mm/damon/core: implement DAMOS_QUOTA_NODE_MEMCG_USED_BP SeongJae Park
` (7 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: SeongJae Park @ 2025-10-09 21:20 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm
Define a new DAMOS quota auto-tuning target metric for per-cgroup
per-node memory usage. For specifying the cgroup of the interest, add a
field, namely memcg_id, to damos_quota_goal struct.
Note that this commit is only implementing the interface. The handling
of the interface (the metric value calculation) will be implemented in
the following commit.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
include/linux/damon.h | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index dc9c310e0e75..0d63ceb7e6ef 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -147,6 +147,7 @@ enum damos_action {
* @DAMOS_QUOTA_SOME_MEM_PSI_US: System level some memory PSI in us.
* @DAMOS_QUOTA_NODE_MEM_USED_BP: MemUsed ratio of a node.
* @DAMOS_QUOTA_NODE_MEM_FREE_BP: MemFree ratio of a node.
+ * @DAMOS_QUOTA_NODE_MEMCG_USED_BP: MemUsed ratio of a node for a cgroup.
* @NR_DAMOS_QUOTA_GOAL_METRICS: Number of DAMOS quota goal metrics.
*
* Metrics equal to larger than @NR_DAMOS_QUOTA_GOAL_METRICS are unsupported.
@@ -156,6 +157,7 @@ enum damos_quota_goal_metric {
DAMOS_QUOTA_SOME_MEM_PSI_US,
DAMOS_QUOTA_NODE_MEM_USED_BP,
DAMOS_QUOTA_NODE_MEM_FREE_BP,
+ DAMOS_QUOTA_NODE_MEMCG_USED_BP,
NR_DAMOS_QUOTA_GOAL_METRICS,
};
@@ -166,6 +168,7 @@ enum damos_quota_goal_metric {
* @current_value: Current value of @metric.
* @last_psi_total: Last measured total PSI
* @nid: Node id.
+ * @memcg_id: Memcg id.
* @list: List head for siblings.
*
* Data structure for getting the current score of the quota tuning goal. The
@@ -179,6 +182,9 @@ enum damos_quota_goal_metric {
*
* If @metric is DAMOS_QUOTA_NODE_MEM_{USED,FREE}_BP, @nid represents the node
* id of the target node to account the used/free memory.
+ *
+ * If @metric is DAMOS_QUOTA_NODE_MEMCG_USED_BP, @nid and @memcg_id represents
+ * the node id and the cgroup to account the used memory for.
*/
struct damos_quota_goal {
enum damos_quota_goal_metric metric;
@@ -187,7 +193,10 @@ struct damos_quota_goal {
/* metric-dependent fields */
union {
u64 last_psi_total;
- int nid;
+ struct {
+ int nid;
+ unsigned short memcg_id;
+ };
};
struct list_head list;
};
--
2.39.5
^ permalink raw reply [flat|nested] 13+ messages in thread* [RFC PATCH v2 03/10] mm/damon/core: implement DAMOS_QUOTA_NODE_MEMCG_USED_BP
2025-10-09 21:20 [RFC PATCH v2 00/10] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
2025-10-09 21:20 ` [RFC PATCH v2 01/10] mm/damon: document damos_quota_goal->nid use case SeongJae Park
2025-10-09 21:20 ` [RFC PATCH v2 02/10] mm/damon: add DAMOS quota goal type for per-memcg per-node memory usage SeongJae Park
@ 2025-10-09 21:20 ` SeongJae Park
2025-10-17 18:20 ` SeongJae Park
2025-10-09 21:20 ` [RFC PATCH v2 04/10] mm/damon/sysfs-schemes: implement path file under quota goal directory SeongJae Park
` (6 subsequent siblings)
9 siblings, 1 reply; 13+ messages in thread
From: SeongJae Park @ 2025-10-09 21:20 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm
Implement the handling of the new DAMOS quota goal metric for per-memcg
per-node memory usage, namely DAMOS_QUOTA_NODE_MEMCG_USED_BP. The
metric value is calculated as the sum of active/inactive anon/file pages
of the given cgroup for a given NUMA node.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/core.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 93848b4c6944..1eacf78aa358 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -10,6 +10,7 @@
#include <linux/damon.h>
#include <linux/delay.h>
#include <linux/kthread.h>
+#include <linux/memcontrol.h>
#include <linux/mm.h>
#include <linux/psi.h>
#include <linux/slab.h>
@@ -2032,12 +2033,46 @@ static __kernel_ulong_t damos_get_node_mem_bp(
numerator = i.freeram;
return numerator * 10000 / i.totalram;
}
+
+static unsigned long damos_get_node_memcg_used_bp(
+ struct damos_quota_goal *goal)
+{
+ struct mem_cgroup *memcg;
+ struct lruvec *lruvec;
+ unsigned long used_pages;
+ struct sysinfo i;
+
+ rcu_read_lock();
+ memcg = mem_cgroup_from_id(goal->memcg_id);
+ rcu_read_unlock();
+ if (!memcg) {
+ if (goal->metric == DAMOS_QUOTA_NODE_MEMCG_USED_BP)
+ return 0;
+ else /* DAMOS_QUOTA_NODE_MEMCG_FREE_BP */
+ return 10000;
+ }
+ mem_cgroup_flush_stats(memcg);
+ lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(goal->nid));
+ used_pages = lruvec_page_state(lruvec, NR_ACTIVE_ANON);
+ used_pages += lruvec_page_state(lruvec, NR_INACTIVE_ANON);
+ used_pages += lruvec_page_state(lruvec, NR_ACTIVE_FILE);
+ used_pages += lruvec_page_state(lruvec, NR_INACTIVE_FILE);
+
+ si_meminfo_node(&i, goal->nid);
+ return used_pages * 10000 / i.totalram;
+}
#else
static __kernel_ulong_t damos_get_node_mem_bp(
struct damos_quota_goal *goal)
{
return 0;
}
+
+static unsigned long damos_get_node_memcg_used_bp(
+ struct damos_quota_goal *goal)
+{
+ return 0;
+}
#endif
@@ -2058,6 +2093,9 @@ static void damos_set_quota_goal_current_value(struct damos_quota_goal *goal)
case DAMOS_QUOTA_NODE_MEM_FREE_BP:
goal->current_value = damos_get_node_mem_bp(goal);
break;
+ case DAMOS_QUOTA_NODE_MEMCG_USED_BP:
+ goal->current_value = damos_get_node_memcg_used_bp(goal);
+ break;
default:
break;
}
--
2.39.5
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [RFC PATCH v2 03/10] mm/damon/core: implement DAMOS_QUOTA_NODE_MEMCG_USED_BP
2025-10-09 21:20 ` [RFC PATCH v2 03/10] mm/damon/core: implement DAMOS_QUOTA_NODE_MEMCG_USED_BP SeongJae Park
@ 2025-10-17 18:20 ` SeongJae Park
0 siblings, 0 replies; 13+ messages in thread
From: SeongJae Park @ 2025-10-17 18:20 UTC (permalink / raw)
To: SeongJae Park; +Cc: Andrew Morton, damon, kernel-team, linux-kernel, linux-mm
On Thu, 9 Oct 2025 14:20:35 -0700 SeongJae Park <sj@kernel.org> wrote:
> Implement the handling of the new DAMOS quota goal metric for per-memcg
> per-node memory usage, namely DAMOS_QUOTA_NODE_MEMCG_USED_BP. The
> metric value is calculated as the sum of active/inactive anon/file pages
> of the given cgroup for a given NUMA node.
>
> Signed-off-by: SeongJae Park <sj@kernel.org>
> ---
> mm/damon/core.c | 38 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 38 insertions(+)
>
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 93848b4c6944..1eacf78aa358 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
[...]
> @@ -2058,6 +2093,9 @@ static void damos_set_quota_goal_current_value(struct damos_quota_goal *goal)
> case DAMOS_QUOTA_NODE_MEM_FREE_BP:
> goal->current_value = damos_get_node_mem_bp(goal);
> break;
> + case DAMOS_QUOTA_NODE_MEMCG_USED_BP:
> + goal->current_value = damos_get_node_memcg_used_bp(goal);
> + break;
> default:
> break;
> }
> --
> 2.39.5
In addition to damos_set_quota_goal_current_value(), this patch should also
update damos_commit_quota_goal_union(), like below. I will add that on the
next spin.
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -825,6 +825,10 @@ static void damos_commit_quota_goal_union(
case DAMOS_QUOTA_NODE_MEM_FREE_BP:
dst->nid = src->nid;
break;
+ case DAMOS_QUOTA_NODE_MEMCG_USED_BP:
+ dst->nid = src->nid;
+ dst->memcg_id = src->memcg_id;
+ break;
default:
break;
}
Thanks,
SJ
^ permalink raw reply [flat|nested] 13+ messages in thread
* [RFC PATCH v2 04/10] mm/damon/sysfs-schemes: implement path file under quota goal directory
2025-10-09 21:20 [RFC PATCH v2 00/10] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (2 preceding siblings ...)
2025-10-09 21:20 ` [RFC PATCH v2 03/10] mm/damon/core: implement DAMOS_QUOTA_NODE_MEMCG_USED_BP SeongJae Park
@ 2025-10-09 21:20 ` SeongJae Park
2025-10-09 21:20 ` [RFC PATCH v2 05/10] mm/damon/sysfs-schemes: support DAMOS_QUOTA_NODE_MEMCG_USED_BP SeongJae Park
` (5 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: SeongJae Park @ 2025-10-09 21:20 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm
Add a DAMOS sysfs file for specifying the cgroup of the interest for
DAMOS_QUOTA_NODE_MEMCG_USED_BP.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/sysfs-schemes.c | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 6536f16006c9..2c440a2b80e6 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -999,6 +999,7 @@ struct damos_sysfs_quota_goal {
unsigned long target_value;
unsigned long current_value;
int nid;
+ char *path;
};
static struct damos_sysfs_quota_goal *damos_sysfs_quota_goal_alloc(void)
@@ -1128,10 +1129,39 @@ static ssize_t nid_store(struct kobject *kobj,
return err ? err : count;
}
+static ssize_t path_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ struct damos_sysfs_quota_goal *goal = container_of(kobj,
+ struct damos_sysfs_quota_goal, kobj);
+
+ return sysfs_emit(buf, "%s\n", goal->path ? goal->path : "");
+}
+
+static ssize_t path_store(struct kobject *kobj,
+ struct kobj_attribute *attr, const char *buf, size_t count)
+{
+ struct damos_sysfs_quota_goal *goal = container_of(kobj,
+ struct damos_sysfs_quota_goal, kobj);
+ char *path = kmalloc_array(size_add(count, 1), sizeof(*path),
+ GFP_KERNEL);
+
+ if (!path)
+ return -ENOMEM;
+
+ strscpy(path, buf, count + 1);
+ kfree(goal->path);
+ goal->path = path;
+ return count;
+}
+
static void damos_sysfs_quota_goal_release(struct kobject *kobj)
{
- /* or, notify this release to the feed callback */
- kfree(container_of(kobj, struct damos_sysfs_quota_goal, kobj));
+ struct damos_sysfs_quota_goal *goal = container_of(kobj,
+ struct damos_sysfs_quota_goal, kobj);
+
+ kfree(goal->path);
+ kfree(goal);
}
static struct kobj_attribute damos_sysfs_quota_goal_target_metric_attr =
@@ -1146,11 +1176,15 @@ static struct kobj_attribute damos_sysfs_quota_goal_current_value_attr =
static struct kobj_attribute damos_sysfs_quota_goal_nid_attr =
__ATTR_RW_MODE(nid, 0600);
+static struct kobj_attribute damos_sysfs_quota_goal_path_attr =
+ __ATTR_RW_MODE(path, 0600);
+
static struct attribute *damos_sysfs_quota_goal_attrs[] = {
&damos_sysfs_quota_goal_target_metric_attr.attr,
&damos_sysfs_quota_goal_target_value_attr.attr,
&damos_sysfs_quota_goal_current_value_attr.attr,
&damos_sysfs_quota_goal_nid_attr.attr,
+ &damos_sysfs_quota_goal_path_attr.attr,
NULL,
};
ATTRIBUTE_GROUPS(damos_sysfs_quota_goal);
--
2.39.5
^ permalink raw reply [flat|nested] 13+ messages in thread* [RFC PATCH v2 05/10] mm/damon/sysfs-schemes: support DAMOS_QUOTA_NODE_MEMCG_USED_BP
2025-10-09 21:20 [RFC PATCH v2 00/10] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (3 preceding siblings ...)
2025-10-09 21:20 ` [RFC PATCH v2 04/10] mm/damon/sysfs-schemes: implement path file under quota goal directory SeongJae Park
@ 2025-10-09 21:20 ` SeongJae Park
2025-10-09 21:20 ` [RFC PATCH v2 06/10] mm/damon/core: add DAMOS quota gaol metric for per-memcg per-numa free memory SeongJae Park
` (4 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: SeongJae Park @ 2025-10-09 21:20 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm
Add support of DAMOS_QUOTA_NODE_MEMCG_USED_BP. For this, extend quota
goal metric inputs for the new metric, and update DAMOS core layer
request construction logic to set the target cgroup, which is specified
by the user, via the 'path' file.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/sysfs-schemes.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 2c440a2b80e6..c679e62fd4b9 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1030,6 +1030,10 @@ struct damos_sysfs_qgoal_metric_name damos_sysfs_qgoal_metric_names[] = {
.metric = DAMOS_QUOTA_NODE_MEM_FREE_BP,
.name = "node_mem_free_bp",
},
+ {
+ .metric = DAMOS_QUOTA_NODE_MEMCG_USED_BP,
+ .name = "node_memcg_used_bp",
+ },
};
static ssize_t target_metric_show(struct kobject *kobj,
@@ -2526,7 +2530,7 @@ static int damos_sysfs_add_quota_score(
struct damos_quota *quota)
{
struct damos_quota_goal *goal;
- int i;
+ int i, err;
for (i = 0; i < sysfs_goals->nr; i++) {
struct damos_sysfs_quota_goal *sysfs_goal =
@@ -2547,6 +2551,15 @@ static int damos_sysfs_add_quota_score(
case DAMOS_QUOTA_NODE_MEM_FREE_BP:
goal->nid = sysfs_goal->nid;
break;
+ case DAMOS_QUOTA_NODE_MEMCG_USED_BP:
+ err = damon_sysfs_memcg_path_to_id(
+ sysfs_goal->path, &goal->memcg_id);
+ if (err) {
+ damos_destroy_quota_goal(goal);
+ return err;
+ }
+ goal->nid = sysfs_goal->nid;
+ break;
default:
break;
}
--
2.39.5
^ permalink raw reply [flat|nested] 13+ messages in thread* [RFC PATCH v2 06/10] mm/damon/core: add DAMOS quota gaol metric for per-memcg per-numa free memory
2025-10-09 21:20 [RFC PATCH v2 00/10] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (4 preceding siblings ...)
2025-10-09 21:20 ` [RFC PATCH v2 05/10] mm/damon/sysfs-schemes: support DAMOS_QUOTA_NODE_MEMCG_USED_BP SeongJae Park
@ 2025-10-09 21:20 ` SeongJae Park
2025-10-17 18:23 ` SeongJae Park
2025-10-09 21:20 ` [RFC PATCH v2 07/10] mm/damon/sysfs-schemes: support DAMOS_QUOTA_NODE_MEMCG_FREE_BP SeongJae Park
` (3 subsequent siblings)
9 siblings, 1 reply; 13+ messages in thread
From: SeongJae Park @ 2025-10-09 21:20 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm
Add a variant of DAMOS_QUOTA_NODE_MEMCG_USED_BP, for the free memory
portion. The value of the metric is implemented as the entire memory of
the given NUMA node subtracted by the given cgroup's usage. So from a
perspective, "unused" could be a better term than "free". But arguably
it is not very clear what is better, so use the term "free".
Signed-off-by: SeongJae Park <sj@kernel.org>
---
include/linux/damon.h | 6 ++++--
mm/damon/core.c | 9 +++++++--
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 0d63ceb7e6ef..0edf41d36ea1 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -148,6 +148,7 @@ enum damos_action {
* @DAMOS_QUOTA_NODE_MEM_USED_BP: MemUsed ratio of a node.
* @DAMOS_QUOTA_NODE_MEM_FREE_BP: MemFree ratio of a node.
* @DAMOS_QUOTA_NODE_MEMCG_USED_BP: MemUsed ratio of a node for a cgroup.
+ * @DAMOS_QUOTA_NODE_MEMCG_FREE_BP: MemFree ratio of a node for a cgroup.
* @NR_DAMOS_QUOTA_GOAL_METRICS: Number of DAMOS quota goal metrics.
*
* Metrics equal to larger than @NR_DAMOS_QUOTA_GOAL_METRICS are unsupported.
@@ -158,6 +159,7 @@ enum damos_quota_goal_metric {
DAMOS_QUOTA_NODE_MEM_USED_BP,
DAMOS_QUOTA_NODE_MEM_FREE_BP,
DAMOS_QUOTA_NODE_MEMCG_USED_BP,
+ DAMOS_QUOTA_NODE_MEMCG_FREE_BP,
NR_DAMOS_QUOTA_GOAL_METRICS,
};
@@ -183,8 +185,8 @@ enum damos_quota_goal_metric {
* If @metric is DAMOS_QUOTA_NODE_MEM_{USED,FREE}_BP, @nid represents the node
* id of the target node to account the used/free memory.
*
- * If @metric is DAMOS_QUOTA_NODE_MEMCG_USED_BP, @nid and @memcg_id represents
- * the node id and the cgroup to account the used memory for.
+ * If @metric is DAMOS_QUOTA_NODE_MEMCG_{USED,FREE}_BP, @nid and @memcg_id
+ * represents the node id and the cgroup to account the used memory for.
*/
struct damos_quota_goal {
enum damos_quota_goal_metric metric;
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 1eacf78aa358..a31ede50906c 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2039,7 +2039,7 @@ static unsigned long damos_get_node_memcg_used_bp(
{
struct mem_cgroup *memcg;
struct lruvec *lruvec;
- unsigned long used_pages;
+ unsigned long used_pages, numerator;
struct sysinfo i;
rcu_read_lock();
@@ -2059,7 +2059,11 @@ static unsigned long damos_get_node_memcg_used_bp(
used_pages += lruvec_page_state(lruvec, NR_INACTIVE_FILE);
si_meminfo_node(&i, goal->nid);
- return used_pages * 10000 / i.totalram;
+ if (goal->metric == DAMOS_QUOTA_NODE_MEMCG_USED_BP)
+ numerator = used_pages;
+ else /* DAMOS_QUOTA_NODE_MEMCG_FREE_BP */
+ numerator = i.totalram - used_pages;
+ return numerator * 10000 / i.totalram;
}
#else
static __kernel_ulong_t damos_get_node_mem_bp(
@@ -2094,6 +2098,7 @@ static void damos_set_quota_goal_current_value(struct damos_quota_goal *goal)
goal->current_value = damos_get_node_mem_bp(goal);
break;
case DAMOS_QUOTA_NODE_MEMCG_USED_BP:
+ case DAMOS_QUOTA_NODE_MEMCG_FREE_BP:
goal->current_value = damos_get_node_memcg_used_bp(goal);
break;
default:
--
2.39.5
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [RFC PATCH v2 06/10] mm/damon/core: add DAMOS quota gaol metric for per-memcg per-numa free memory
2025-10-09 21:20 ` [RFC PATCH v2 06/10] mm/damon/core: add DAMOS quota gaol metric for per-memcg per-numa free memory SeongJae Park
@ 2025-10-17 18:23 ` SeongJae Park
0 siblings, 0 replies; 13+ messages in thread
From: SeongJae Park @ 2025-10-17 18:23 UTC (permalink / raw)
To: SeongJae Park; +Cc: Andrew Morton, damon, kernel-team, linux-kernel, linux-mm
On Thu, 9 Oct 2025 14:20:38 -0700 SeongJae Park <sj@kernel.org> wrote:
> Add a variant of DAMOS_QUOTA_NODE_MEMCG_USED_BP, for the free memory
> portion. The value of the metric is implemented as the entire memory of
> the given NUMA node subtracted by the given cgroup's usage. So from a
> perspective, "unused" could be a better term than "free". But arguably
> it is not very clear what is better, so use the term "free".
>
> Signed-off-by: SeongJae Park <sj@kernel.org>
> ---
> include/linux/damon.h | 6 ++++--
> mm/damon/core.c | 9 +++++++--
> 2 files changed, 11 insertions(+), 4 deletions(-)
[...]
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -2039,7 +2039,7 @@ static unsigned long damos_get_node_memcg_used_bp(
> {
> struct mem_cgroup *memcg;
> struct lruvec *lruvec;
> - unsigned long used_pages;
> + unsigned long used_pages, numerator;
> struct sysinfo i;
>
> rcu_read_lock();
> @@ -2059,7 +2059,11 @@ static unsigned long damos_get_node_memcg_used_bp(
> used_pages += lruvec_page_state(lruvec, NR_INACTIVE_FILE);
>
> si_meminfo_node(&i, goal->nid);
> - return used_pages * 10000 / i.totalram;
> + if (goal->metric == DAMOS_QUOTA_NODE_MEMCG_USED_BP)
> + numerator = used_pages;
> + else /* DAMOS_QUOTA_NODE_MEMCG_FREE_BP */
> + numerator = i.totalram - used_pages;
> + return numerator * 10000 / i.totalram;
> }
> #else
> static __kernel_ulong_t damos_get_node_mem_bp(
> @@ -2094,6 +2098,7 @@ static void damos_set_quota_goal_current_value(struct damos_quota_goal *goal)
> goal->current_value = damos_get_node_mem_bp(goal);
> break;
> case DAMOS_QUOTA_NODE_MEMCG_USED_BP:
> + case DAMOS_QUOTA_NODE_MEMCG_FREE_BP:
> goal->current_value = damos_get_node_memcg_used_bp(goal);
> break;
> default:
> --
> 2.39.5
Like the DAMOS_QUOTA_NODE_MEMCG_USED_BP case, this patch should also update
damos_commit_quota_goal_union(), like below. I will add that on the next spin.
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -826,6 +826,7 @@ static void damos_commit_quota_goal_union(
dst->nid = src->nid;
break;
case DAMOS_QUOTA_NODE_MEMCG_USED_BP:
+ case DAMOS_QUOTA_NODE_MEMCG_FREE_BP:
dst->nid = src->nid;
dst->memcg_id = src->memcg_id;
break;
Thanks,
SJ
^ permalink raw reply [flat|nested] 13+ messages in thread
* [RFC PATCH v2 07/10] mm/damon/sysfs-schemes: support DAMOS_QUOTA_NODE_MEMCG_FREE_BP
2025-10-09 21:20 [RFC PATCH v2 00/10] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (5 preceding siblings ...)
2025-10-09 21:20 ` [RFC PATCH v2 06/10] mm/damon/core: add DAMOS quota gaol metric for per-memcg per-numa free memory SeongJae Park
@ 2025-10-09 21:20 ` SeongJae Park
2025-10-09 21:20 ` [RFC PATCH v2 08/10] Docs/mm/damon/design: document DAMOS_QUOTA_NODE_MEMCG_{USED,FREE}_BP SeongJae Park
` (2 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: SeongJae Park @ 2025-10-09 21:20 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm
Extend DAMON sysfs to support DAMOS_QUOTA_NODE_MEMCG_FREE_BP.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/sysfs-schemes.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index c679e62fd4b9..c98cf4bd2fbb 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1034,6 +1034,10 @@ struct damos_sysfs_qgoal_metric_name damos_sysfs_qgoal_metric_names[] = {
.metric = DAMOS_QUOTA_NODE_MEMCG_USED_BP,
.name = "node_memcg_used_bp",
},
+ {
+ .metric = DAMOS_QUOTA_NODE_MEMCG_FREE_BP,
+ .name = "node_memcg_free_bp",
+ },
};
static ssize_t target_metric_show(struct kobject *kobj,
@@ -2552,6 +2556,7 @@ static int damos_sysfs_add_quota_score(
goal->nid = sysfs_goal->nid;
break;
case DAMOS_QUOTA_NODE_MEMCG_USED_BP:
+ case DAMOS_QUOTA_NODE_MEMCG_FREE_BP:
err = damon_sysfs_memcg_path_to_id(
sysfs_goal->path, &goal->memcg_id);
if (err) {
--
2.39.5
^ permalink raw reply [flat|nested] 13+ messages in thread* [RFC PATCH v2 08/10] Docs/mm/damon/design: document DAMOS_QUOTA_NODE_MEMCG_{USED,FREE}_BP
2025-10-09 21:20 [RFC PATCH v2 00/10] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (6 preceding siblings ...)
2025-10-09 21:20 ` [RFC PATCH v2 07/10] mm/damon/sysfs-schemes: support DAMOS_QUOTA_NODE_MEMCG_FREE_BP SeongJae Park
@ 2025-10-09 21:20 ` SeongJae Park
2025-10-09 21:20 ` [RFC PATCH v2 09/10] Docs/admin-guide/mm/damon/usage: document DAMOS quota goal path file SeongJae Park
2025-10-09 21:20 ` [RFC PATCH v2 10/10] Docs/ABI/damon: " SeongJae Park
9 siblings, 0 replies; 13+ messages in thread
From: SeongJae Park @ 2025-10-09 21:20 UTC (permalink / raw)
Cc: SeongJae Park, Liam R. Howlett, Andrew Morton, David Hildenbrand,
Jonathan Corbet, Lorenzo Stoakes, Michal Hocko, Mike Rapoport,
Suren Baghdasaryan, Vlastimil Babka, damon, kernel-team,
linux-doc, linux-kernel, linux-mm
Update design doc for the newly added two DAMOS quota auto-tuning target
goal metrics, DAMOS_QUOTA_NODE_MEMCG_{USED,FREE}_BP.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/mm/damon/design.rst | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/design.rst
index 80354f4f42ba..b54925ea78e9 100644
--- a/Documentation/mm/damon/design.rst
+++ b/Documentation/mm/damon/design.rst
@@ -564,9 +564,9 @@ aggressiveness (the quota) of the corresponding scheme. For example, if DAMOS
is under achieving the goal, DAMOS automatically increases the quota. If DAMOS
is over achieving the goal, it decreases the quota.
-The goal can be specified with four parameters, namely ``target_metric``,
-``target_value``, ``current_value`` and ``nid``. The auto-tuning mechanism
-tries to make ``current_value`` of ``target_metric`` be same to
+The goal can be specified with five parameters, namely ``target_metric``,
+``target_value``, ``current_value``, ``nid`` and ``path``. The auto-tuning
+mechanism tries to make ``current_value`` of ``target_metric`` be same to
``target_value``.
- ``user_input``: User-provided value. Users could use any metric that they
@@ -581,9 +581,18 @@ tries to make ``current_value`` of ``target_metric`` be same to
set by users at the initial time. In other words, DAMOS does self-feedback.
- ``node_mem_used_bp``: Specific NUMA node's used memory ratio in bp (1/10,000).
- ``node_mem_free_bp``: Specific NUMA node's free memory ratio in bp (1/10,000).
-
-``nid`` is optionally required for only ``node_mem_used_bp`` and
-``node_mem_free_bp`` to point the specific NUMA node.
+- ``node_memcg_used_bp``: Specific cgroup's node used memory ratio for a
+ specific NUMA node, in bp (1/10,000).
+- ``node_memcg_free_bp``: Specific cgroup's node unused memory ratio for a
+ specific NUMA node, in bp (1/10,000).
+
+``nid`` is optionally required for only ``node_mem_used_bp``,
+``node_mem_free_bp``, ``node_memcg_used_bp`` and ``node_memcg_free_bp`` to
+point the specific NUMA node.
+
+``path`` is optionally required for only ``node_memcg_used_bp`` and
+``node_memcg_free_bp`` to point the path to the cgroup. The value should be
+the path of the memory cgroup from the cgroups mount point.
To know how user-space can set the tuning goal metric, the target value, and/or
the current value via :ref:`DAMON sysfs interface <sysfs_interface>`, refer to
--
2.39.5
^ permalink raw reply [flat|nested] 13+ messages in thread* [RFC PATCH v2 09/10] Docs/admin-guide/mm/damon/usage: document DAMOS quota goal path file
2025-10-09 21:20 [RFC PATCH v2 00/10] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (7 preceding siblings ...)
2025-10-09 21:20 ` [RFC PATCH v2 08/10] Docs/mm/damon/design: document DAMOS_QUOTA_NODE_MEMCG_{USED,FREE}_BP SeongJae Park
@ 2025-10-09 21:20 ` SeongJae Park
2025-10-09 21:20 ` [RFC PATCH v2 10/10] Docs/ABI/damon: " SeongJae Park
9 siblings, 0 replies; 13+ messages in thread
From: SeongJae Park @ 2025-10-09 21:20 UTC (permalink / raw)
Cc: SeongJae Park, Liam R. Howlett, Andrew Morton, David Hildenbrand,
Jonathan Corbet, Lorenzo Stoakes, Michal Hocko, Mike Rapoport,
Suren Baghdasaryan, Vlastimil Babka, damon, kernel-team,
linux-doc, linux-kernel, linux-mm
A new DAMON sysfs interface file, namely 'path' has been added under
DAMOS quota goal directory, for specifying the cgroup for
DAMOS_QUOTA_NODE_MEMCG_{USED,FREE}_BP metrics. Document it on the usage
document.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/admin-guide/mm/damon/usage.rst | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst
index eae534bc1bee..98958975604d 100644
--- a/Documentation/admin-guide/mm/damon/usage.rst
+++ b/Documentation/admin-guide/mm/damon/usage.rst
@@ -81,7 +81,7 @@ comma (",").
│ │ │ │ │ │ │ :ref:`quotas <sysfs_quotas>`/ms,bytes,reset_interval_ms,effective_bytes
│ │ │ │ │ │ │ │ weights/sz_permil,nr_accesses_permil,age_permil
│ │ │ │ │ │ │ │ :ref:`goals <sysfs_schemes_quota_goals>`/nr_goals
- │ │ │ │ │ │ │ │ │ 0/target_metric,target_value,current_value,nid
+ │ │ │ │ │ │ │ │ │ 0/target_metric,target_value,current_value,nid,path
│ │ │ │ │ │ │ :ref:`watermarks <sysfs_watermarks>`/metric,interval_us,high,mid,low
│ │ │ │ │ │ │ :ref:`{core_,ops_,}filters <sysfs_filters>`/nr_filters
│ │ │ │ │ │ │ │ 0/type,matching,allow,memcg_path,addr_start,addr_end,target_idx,min,max
@@ -402,9 +402,9 @@ number (``N``) to the file creates the number of child directories named ``0``
to ``N-1``. Each directory represents each goal and current achievement.
Among the multiple feedback, the best one is used.
-Each goal directory contains four files, namely ``target_metric``,
-``target_value``, ``current_value`` and ``nid``. Users can set and get the
-four parameters for the quota auto-tuning goals that specified on the
+Each goal directory contains five files, namely ``target_metric``,
+``target_value``, ``current_value`` ``nid`` and ``path``. Users can set and
+get the five parameters for the quota auto-tuning goals that specified on the
:ref:`design doc <damon_design_damos_quotas_auto_tuning>` by writing to and
reading from each of the files. Note that users should further write
``commit_schemes_quota_goals`` to the ``state`` file of the :ref:`kdamond
--
2.39.5
^ permalink raw reply [flat|nested] 13+ messages in thread* [RFC PATCH v2 10/10] Docs/ABI/damon: document DAMOS quota goal path file
2025-10-09 21:20 [RFC PATCH v2 00/10] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (8 preceding siblings ...)
2025-10-09 21:20 ` [RFC PATCH v2 09/10] Docs/admin-guide/mm/damon/usage: document DAMOS quota goal path file SeongJae Park
@ 2025-10-09 21:20 ` SeongJae Park
9 siblings, 0 replies; 13+ messages in thread
From: SeongJae Park @ 2025-10-09 21:20 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel, linux-mm
A DAMON sysfs interface file for DAMOS quota goal's optional path
argument has been added. Document it on the ABI doc.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/ABI/testing/sysfs-kernel-mm-damon | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentation/ABI/testing/sysfs-kernel-mm-damon
index b6b71db36ca7..dce6c2cda4e8 100644
--- a/Documentation/ABI/testing/sysfs-kernel-mm-damon
+++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon
@@ -303,6 +303,12 @@ Contact: SeongJae Park <sj@kernel.org>
Description: Writing to and reading from this file sets and gets the nid
parameter of the goal.
+What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/quotas/goals/<G>/path
+Date: Oct 2025
+Contact: SeongJae Park <sj@kernel.org>
+Description: Writing to and reading from this file sets and gets the path
+ parameter of the goal.
+
What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/schemes/<S>/quotas/weights/sz_permil
Date: Mar 2022
Contact: SeongJae Park <sj@kernel.org>
--
2.39.5
^ permalink raw reply [flat|nested] 13+ messages in thread