]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/damon/core: introduce failed region quota charge ratio
authorSeongJae Park <sj@kernel.org>
Tue, 28 Apr 2026 01:33:52 +0000 (18:33 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 29 May 2026 04:04:42 +0000 (21:04 -0700)
DAMOS quota is charged to all DAMOS action application attempted memory,
regardless of how much of the memory the action was successful and failed.
This makes understanding quota behavior without DAMOS stat but only with
end level metrics (e.g., increased amount of free memory for DAMOS_PAGEOUT
action) difficult.  Also, charging action-failed memory same as
action-successful memory is somewhat unfair, as successful action
application will induce more overhead in most cases.

Introduce DAMON core API for setting the charge ratio for such
action-failed memory.  It allows API callers to specify the ratio in a
flexible way, by setting the numerator and the denominator.

Link: https://lore.kernel.org/20260428013402.115171-4-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Brendan Higgins <brendan.higgins@linux.dev>
Cc: David Hildenbrand <david@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/damon.h
mm/damon/core.c

index 986b8c90258557d66ae6735e79de308054c606b2..2bb43910e22e7e579866a57d486230c6ad89f02e 100644 (file)
@@ -236,6 +236,8 @@ enum damos_quota_goal_tuner {
  * @goals:             Head of quota tuning goals (&damos_quota_goal) list.
  * @goal_tuner:                Goal-based @esz tuning algorithm to use.
  * @esz:               Effective size quota in bytes.
+ * @fail_charge_num:   Failed regions charge rate numerator.
+ * @fail_charge_denom: Failed regions charge rate denominator.
  *
  * @weight_sz:         Weight of the region's size for prioritization.
  * @weight_nr_accesses:        Weight of the region's nr_accesses for prioritization.
@@ -265,6 +267,10 @@ enum damos_quota_goal_tuner {
  *
  * The resulting effective size quota in bytes is set to @esz.
  *
+ * For DAMOS action applying failed amount of regions, charging those same to
+ * those that the action has successfully applied may be unfair.  For the
+ * reason, 'the size * @fail_charge_num / @fail_charge_denom' is charged.
+ *
  * For selecting regions within the quota, DAMON prioritizes current scheme's
  * target memory regions using the &struct damon_operations->get_scheme_score.
  * You could customize the prioritization logic by setting &weight_sz,
@@ -279,6 +285,9 @@ struct damos_quota {
        enum damos_quota_goal_tuner goal_tuner;
        unsigned long esz;
 
+       unsigned int fail_charge_num;
+       unsigned int fail_charge_denom;
+
        unsigned int weight_sz;
        unsigned int weight_nr_accesses;
        unsigned int weight_age;
index e59f4031d24b3e83caeaf5a6b915bbff2c35d3f7..7aeaf319a18abca14956030cadc24541644eedf0 100644 (file)
@@ -922,6 +922,8 @@ static int damos_commit_quota(struct damos_quota *dst, struct damos_quota *src)
        if (err)
                return err;
        dst->goal_tuner = src->goal_tuner;
+       dst->fail_charge_num = src->fail_charge_num;
+       dst->fail_charge_denom = src->fail_charge_denom;
        dst->weight_sz = src->weight_sz;
        dst->weight_nr_accesses = src->weight_nr_accesses;
        dst->weight_age = src->weight_age;
@@ -2065,6 +2067,23 @@ static void damos_walk_cancel(struct damon_ctx *ctx)
        mutex_unlock(&ctx->walk_control_lock);
 }
 
+static void damos_charge_quota(struct damos_quota *quota,
+               unsigned long sz_region, unsigned long sz_applied)
+{
+       /*
+        * sz_applied could be bigger than sz_region, depending on ops
+        * implementation of the action, e.g., damos_pa_pageout().  Charge only
+        * the region size in the case.
+        */
+       if (!quota->fail_charge_denom || sz_applied > sz_region)
+               quota->charged_sz += sz_region;
+       else
+               quota->charged_sz += sz_applied + mult_frac(
+                               (sz_region - sz_applied),
+                               quota->fail_charge_num,
+                               quota->fail_charge_denom);
+}
+
 static bool damos_quota_is_full(struct damos_quota *quota,
                unsigned long min_region_sz)
 {
@@ -2135,7 +2154,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
                ktime_get_coarse_ts64(&end);
                quota->total_charged_ns += timespec64_to_ns(&end) -
                        timespec64_to_ns(&begin);
-               quota->charged_sz += sz;
+               damos_charge_quota(quota, sz, sz_applied);
                if (damos_quota_is_full(quota, c->min_region_sz)) {
                        quota->charge_target_from = t;
                        quota->charge_addr_from = r->ar.end;