* [RFC PATCH 01/11] mm/damon: document damos_quota_goal->nid use case
2025-06-19 22:00 [RFC PATCH 00/11] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
@ 2025-06-19 22:00 ` SeongJae Park
2025-06-19 22:00 ` [RFC PATCH 02/11] mm/damon: add a new DAMOS quota goal metric for cgroup on node memory usage SeongJae Park
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-06-19 22:00 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel,
linux-mm
damos_quota_goal kerneldoc comment is not explaining @metric use case.
Add it.
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 492be8319a25..39b835dd3c4d 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -206,6 +206,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 related [flat|nested] 12+ messages in thread
* [RFC PATCH 02/11] mm/damon: add a new DAMOS quota goal metric for cgroup on node memory usage
2025-06-19 22:00 [RFC PATCH 00/11] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
2025-06-19 22:00 ` [RFC PATCH 01/11] mm/damon: document damos_quota_goal->nid use case SeongJae Park
@ 2025-06-19 22:00 ` SeongJae Park
2025-06-19 22:00 ` [RFC PATCH 03/11] mm/damon/core: implement DAMOS_QUOTA_NODE_MEMCG_USED_BP SeongJae Park
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-06-19 22:00 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel,
linux-mm
Define a new DAMOS quota auto-tuning target metrics for per-cgroup
per-node memory usage. Also extend damos_quota_goal struct to have a
field for specifying the cgroup of the interest.
Note that this commit is only for DAMON kernel API extension. Real
behavior of the new metric will be implemented by a 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 39b835dd3c4d..43aef959d357 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -175,6 +175,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.
* @DAMOS_QUOTA_ACTIVE_MEM_BP: Active to inactive memory ratio.
* @NR_DAMOS_QUOTA_GOAL_METRICS: Number of DAMOS quota goal metrics.
*
@@ -185,6 +186,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,
DAMOS_QUOTA_ACTIVE_MEM_BP,
NR_DAMOS_QUOTA_GOAL_METRICS,
};
@@ -196,6 +198,7 @@ enum damos_quota_goal_metric {
* @current_value: Current value of @metric.
* @last_psi_total: Last measured total PSI
* @nid: Node id.
+ * @memcg: Memcg id.
* @list: List head for siblings.
*
* Data structure for getting the current score of the quota tuning goal. The
@@ -209,6 +212,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;
@@ -217,7 +223,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 related [flat|nested] 12+ messages in thread
* [RFC PATCH 03/11] mm/damon/core: implement DAMOS_QUOTA_NODE_MEMCG_USED_BP
2025-06-19 22:00 [RFC PATCH 00/11] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
2025-06-19 22:00 ` [RFC PATCH 01/11] mm/damon: document damos_quota_goal->nid use case SeongJae Park
2025-06-19 22:00 ` [RFC PATCH 02/11] mm/damon: add a new DAMOS quota goal metric for cgroup on node memory usage SeongJae Park
@ 2025-06-19 22:00 ` SeongJae Park
2025-06-19 22:00 ` [RFC PATCH 04/11] mm/damon/sysfs-schemes: implement path file under quota goal directory SeongJae Park
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-06-19 22:00 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel,
linux-mm
Implement the behavior of DAMOS_QUOTA_NODE_MEMCG_USED_BP. It uses sum
of active/inactive anon/file pages of a given cgroup on a given NUMA
node as the value of the metric.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/core.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index d675dd932a23..1481b43f2710 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>
@@ -2021,12 +2022,40 @@ 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);
+ 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);
+ rcu_read_unlock();
+
+ si_meminfo_node(&i, goal->nid);
+ return used_pages * PAGE_SIZE * 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
/*
@@ -2062,6 +2091,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;
case DAMOS_QUOTA_ACTIVE_MEM_BP:
goal->current_value = damos_get_active_inactive_mem_bp();
break;
--
2.39.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [RFC PATCH 04/11] mm/damon/sysfs-schemes: implement path file under quota goal directory
2025-06-19 22:00 [RFC PATCH 00/11] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (2 preceding siblings ...)
2025-06-19 22:00 ` [RFC PATCH 03/11] mm/damon/core: implement DAMOS_QUOTA_NODE_MEMCG_USED_BP SeongJae Park
@ 2025-06-19 22:00 ` SeongJae Park
2025-06-19 22:00 ` [RFC PATCH 05/11] mm/damon/sysfs-schemes: connect quota goal path file to DAMON core SeongJae Park
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-06-19 22:00 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 4805761d9127..4a340baa72a4 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)
@@ -1132,10 +1133,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 =
@@ -1150,11 +1180,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 related [flat|nested] 12+ messages in thread
* [RFC PATCH 05/11] mm/damon/sysfs-schemes: connect quota goal path file to DAMON core
2025-06-19 22:00 [RFC PATCH 00/11] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (3 preceding siblings ...)
2025-06-19 22:00 ` [RFC PATCH 04/11] mm/damon/sysfs-schemes: implement path file under quota goal directory SeongJae Park
@ 2025-06-19 22:00 ` SeongJae Park
2025-06-19 22:00 ` [RFC PATCH 06/11] Docs/mm/damon/design: document DAMOS_QUOTA_NODE_MEMCG_USED_BP SeongJae Park
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-06-19 22:00 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel,
linux-mm
Read and commit the user-specified cgroup information for
DAMOS_QUOTA_NODE_MEMCG_USED_BP to DAMON core.
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 4a340baa72a4..89e5e40bdf63 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1030,6 +1030,10 @@ static 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",
+ },
{
.metric = DAMOS_QUOTA_ACTIVE_MEM_BP,
.name = "active_mem_bp",
@@ -2317,7 +2321,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 =
@@ -2338,6 +2342,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 related [flat|nested] 12+ messages in thread
* [RFC PATCH 06/11] Docs/mm/damon/design: document DAMOS_QUOTA_NODE_MEMCG_USED_BP
2025-06-19 22:00 [RFC PATCH 00/11] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (4 preceding siblings ...)
2025-06-19 22:00 ` [RFC PATCH 05/11] mm/damon/sysfs-schemes: connect quota goal path file to DAMON core SeongJae Park
@ 2025-06-19 22:00 ` SeongJae Park
2025-06-19 22:00 ` [RFC PATCH 07/11] Docs/admin-guide/mm/damon/usage: document DAMOS quota goal path file SeongJae Park
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-06-19 22:00 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, Jonathan Corbet, damon, kernel-team,
linux-doc, linux-kernel, linux-mm
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/mm/damon/design.rst | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/design.rst
index 2290ebefc648..eb6d3b7d0643 100644
--- a/Documentation/mm/damon/design.rst
+++ b/Documentation/mm/damon/design.rst
@@ -553,9 +553,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
@@ -570,9 +570,16 @@ 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).
+- ``node_memcg_used_bp``: Specific cgroup's node used memory ratio for a
+ specific NUMA node, 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.
+``nid`` is optionally required for only ``node_mem_used_bp``,
+``node_mem_free_bp`` and ``node_memcg_used_bp`` to point the specific NUMA
+node.
+
+``path`` is optionally required for only ``node_memcg_used_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 related [flat|nested] 12+ messages in thread
* [RFC PATCH 07/11] Docs/admin-guide/mm/damon/usage: document DAMOS quota goal path file
2025-06-19 22:00 [RFC PATCH 00/11] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (5 preceding siblings ...)
2025-06-19 22:00 ` [RFC PATCH 06/11] Docs/mm/damon/design: document DAMOS_QUOTA_NODE_MEMCG_USED_BP SeongJae Park
@ 2025-06-19 22:00 ` SeongJae Park
2025-06-19 22:00 ` [RFC PATCH 08/11] mm/damon: add DAMOS_QUOTA_NODE_MEMCG_FREE_BP quota tuning goal metric SeongJae Park
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-06-19 22:00 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, Jonathan Corbet, damon, kernel-team,
linux-doc, linux-kernel, linux-mm
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 d960aba72b82..2f603977fa88 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
@@ -390,9 +390,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 related [flat|nested] 12+ messages in thread
* [RFC PATCH 08/11] mm/damon: add DAMOS_QUOTA_NODE_MEMCG_FREE_BP quota tuning goal metric
2025-06-19 22:00 [RFC PATCH 00/11] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (6 preceding siblings ...)
2025-06-19 22:00 ` [RFC PATCH 07/11] Docs/admin-guide/mm/damon/usage: document DAMOS quota goal path file SeongJae Park
@ 2025-06-19 22:00 ` SeongJae Park
2025-06-19 22:00 ` [RFC PATCH 09/11] mm/damon/core: implement DAMOS_QUOTA_NODE_MEMCG_FREE_BP SeongJae Park
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-06-19 22:00 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 free memory
portion. Note that this commit only extends the DAMON API. The real
behavior will be implemented by a following commit.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
include/linux/damon.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 43aef959d357..ba02c95e7d85 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -176,6 +176,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.
* @DAMOS_QUOTA_ACTIVE_MEM_BP: Active to inactive memory ratio.
* @NR_DAMOS_QUOTA_GOAL_METRICS: Number of DAMOS quota goal metrics.
*
@@ -187,6 +188,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,
DAMOS_QUOTA_ACTIVE_MEM_BP,
NR_DAMOS_QUOTA_GOAL_METRICS,
};
@@ -213,8 +215,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;
--
2.39.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [RFC PATCH 09/11] mm/damon/core: implement DAMOS_QUOTA_NODE_MEMCG_FREE_BP
2025-06-19 22:00 [RFC PATCH 00/11] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (7 preceding siblings ...)
2025-06-19 22:00 ` [RFC PATCH 08/11] mm/damon: add DAMOS_QUOTA_NODE_MEMCG_FREE_BP quota tuning goal metric SeongJae Park
@ 2025-06-19 22:00 ` SeongJae Park
2025-06-19 22:00 ` [RFC PATCH 10/11] mm/damon/sysfs-schemes: support DAMOS_QUOTA_NODE_MEMCG_FREE_BP SeongJae Park
2025-06-19 22:00 ` [RFC PATCH 11/11] Docs/mm/damon/design: document DAMOS_QUOTA_NODE_MEMCG_FREE_BP SeongJae Park
10 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-06-19 22:00 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel,
linux-mm
Implement the core part of DAMOS_QUOTA_NODE_MEMCG_FREE_BP to get the
real value. The value is implemented as the entire memory of the given
NUMA node, except the given cgroup's portion. So strictly speaking, it
is not free memory but memory that not used by the cgroup.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/core.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 1481b43f2710..ee3d6d4b3c9b 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2028,7 +2028,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();
@@ -2042,7 +2042,11 @@ static unsigned long damos_get_node_memcg_used_bp(
rcu_read_unlock();
si_meminfo_node(&i, goal->nid);
- return used_pages * PAGE_SIZE * 10000 / i.totalram;
+ if (goal->metric == DAMOS_QUOTA_NODE_MEMCG_USED_BP)
+ numerator = used_pages * PAGE_SIZE;
+ else /* DAMOS_QUOTA_NODE_MEMCG_FREE_BP */
+ numerator = i.totalram - used_pages * PAGE_SIZE;
+ return numerator * 10000 / i.totalram;
}
#else
static __kernel_ulong_t damos_get_node_mem_bp(
@@ -2092,6 +2096,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;
case DAMOS_QUOTA_ACTIVE_MEM_BP:
--
2.39.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [RFC PATCH 10/11] mm/damon/sysfs-schemes: support DAMOS_QUOTA_NODE_MEMCG_FREE_BP
2025-06-19 22:00 [RFC PATCH 00/11] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (8 preceding siblings ...)
2025-06-19 22:00 ` [RFC PATCH 09/11] mm/damon/core: implement DAMOS_QUOTA_NODE_MEMCG_FREE_BP SeongJae Park
@ 2025-06-19 22:00 ` SeongJae Park
2025-06-19 22:00 ` [RFC PATCH 11/11] Docs/mm/damon/design: document DAMOS_QUOTA_NODE_MEMCG_FREE_BP SeongJae Park
10 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-06-19 22:00 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, damon, kernel-team, linux-kernel,
linux-mm
Let 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 89e5e40bdf63..819e16151752 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1034,6 +1034,10 @@ static 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",
+ },
{
.metric = DAMOS_QUOTA_ACTIVE_MEM_BP,
.name = "active_mem_bp",
@@ -2343,6 +2347,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 related [flat|nested] 12+ messages in thread
* [RFC PATCH 11/11] Docs/mm/damon/design: document DAMOS_QUOTA_NODE_MEMCG_FREE_BP
2025-06-19 22:00 [RFC PATCH 00/11] mm/damon: allow DAMOS auto-tuned for per-memcg per-node memory usage SeongJae Park
` (9 preceding siblings ...)
2025-06-19 22:00 ` [RFC PATCH 10/11] mm/damon/sysfs-schemes: support DAMOS_QUOTA_NODE_MEMCG_FREE_BP SeongJae Park
@ 2025-06-19 22:00 ` SeongJae Park
10 siblings, 0 replies; 12+ messages in thread
From: SeongJae Park @ 2025-06-19 22:00 UTC (permalink / raw)
Cc: SeongJae Park, Andrew Morton, Jonathan Corbet, damon, kernel-team,
linux-doc, linux-kernel, linux-mm
Signed-off-by: SeongJae Park <sj@kernel.org>
---
Documentation/mm/damon/design.rst | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/design.rst
index eb6d3b7d0643..6e1f772006d9 100644
--- a/Documentation/mm/damon/design.rst
+++ b/Documentation/mm/damon/design.rst
@@ -571,15 +571,16 @@ mechanism tries to make ``current_value`` of ``target_metric`` be same to
- ``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).
- ``node_memcg_used_bp``: Specific cgroup's node used memory ratio for a
+- ``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`` and ``node_memcg_used_bp`` to point the specific NUMA
-node.
+``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`` to point the
-path to the cgroup. The value should be the path of the memory cgroup from the
-cgroups mount point.
+``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 related [flat|nested] 12+ messages in thread